Jump to content
  • Advertisement
Sign in to follow this  
Markgilst

So I'm trying to make a "unique" 2d sidscroller/Pygame

This topic is 2988 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey, I guess I could be considered somewhat of a newbie to game development, but I have a little bit of experience with Actionscript, DOS, and I have already programmed some of my game I'm trying to make with Pygame. Here's what I posted from another forum, but nobody uses it so my post got ignored.

Quote:
Original post by Markgilst
I have a little tiny bit of experience messing around with DOS and HTML and Actionscript, but now I want to make a sidescroller in Pygame. It's going to be very different from the average sidescroller.

Here's what is happening:
I'm programming this according to thenewboston's tutorial on youtube


The levels are actually large, 100X100 images

The sprites are all .gif's or .png's with a different file for each different action (e.g. a file for a walking sprite, and jumping sprite, etc)

Some levels are just one normal shaped image with 1 sprite.

Those levels might be kinda like this :

Share this post


Link to post
Share on other sites
Advertisement
I'll tell more about the video game plan later, but here's the problem. When I use bif="bg.png" the level just ends up like this:
http://i32.tinypic.com/6o3pm9.jpg
Also, another problem is that I don't know how to make the sprites animated in the game. Please help me get this game straight.

[Edited by - Markgilst on July 12, 2010 5:43:06 PM]

Share this post


Link to post
Share on other sites
THE CODE
[source lang="python]
bif="Chapter1bg.JPG"
mif="mudskipperstillunfinished.png"

import pygame, sys
from pygame.locals import *

pygame.init()

screen=pygame.display.set_mode((640,480),0,32)
background=pygame.image.load(bif).convert()
mouse_c=pygame.image.load(mif).convert_alpha()

x,y=130,300
movex, movey=0,0

while True:

for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit
if event.type==KEYDOWN:
if event.key==K_LEFT:
movex=-0.5
elif event.key==K_RIGHT:
movex=+0.5
if event.type == KEYUP:
if event.key==K_LEFT:
movex=0
elif event.key==K_RIGHT:
movex=0

x+=movex
y+=movey

screen.blit(background,(0,0))
screen.blit(mouse_c,(x,y))

pygame.display.update()


That is the first level. What's supposed to happen is that the player presses a certain key and then this SUPER JUMP .gif is loaded.

[Edited by - Markgilst on July 12, 2010 5:55:15 PM]

Share this post


Link to post
Share on other sites
You're not really asking a question, which is why you're getting no response. Requests for assistance should usually cover a standard four points like this:

- What are you hoping to achieve? (Describe the feature you're attempting.)
- Which precise steps are you taking to get there? (Show the code and your reasoning behind it.)
- What are you expecting to see? (What output did you want from it?)
- What are you actually seeing instead? (What appears to be wrong or missing?)

Share this post


Link to post
Share on other sites
He was in #gamedev last night and we gave him some help. Your questions are spot on: he hadn't made any effort to solve the problem, nor had he even read the code he copied - he didn't recognize pygame.image.load(...) as a function that loaded an image from a file and returned a runtime image object, for instance. Having given him a little orientation, he is marginally better positioned to begin to try to solve his problem on his own and return with better questions.

Share this post


Link to post
Share on other sites
Quote:
Original post by Kylotan
You're not really asking a question, which is why you're getting no response. Requests for assistance should usually cover a standard four points like this:

- What are you hoping to achieve? (Describe the feature you're attempting.)
- Which precise steps are you taking to get there? (Show the code and your reasoning behind it.)
- What are you expecting to see? (What output did you want from it?)
- What are you actually seeing instead? (What appears to be wrong or missing?)


Well, let's see.
I'm trying to make a "unique" sidescroller with pygame, and this code that I just posted is the code for level 1. What's supposed to happen is that the sprite is supposed to do this jump thing if I press the space key. (I'm going to change it later.) When it jumps, a new .gif replace the other sprite file, and that is the "superjump.gif." The background image is actually a fishtank and the sprite is a fish. I'll post pictures later.

Since I'm new to pygame I just called up the IRC to help me "fix" this code to what I desired, as explained above. I learned that apparently I had to add

pygame.image.load(SUPERJUMP.gif)


But then I was thinking, "how do I CAUSE it to load the new sprite?" so then I added this code
elif event.key==K_SPACE:
pygame.image.load(SUPERJUMP.gif)



So then, with only that added, and no jumping code, I was expecting to see just the sprite change to "SUPERJUMP.gif" but what happened was, when I pressed the space bar, the whole window just closed.


Now, I'm starting to consider having someone either help with some of the programming online or just do all of the programming only.

Share this post


Link to post
Share on other sites
Quote:
Original post by Markgilst
So then, with only that added, and no jumping code, I was expecting to see just the sprite change to "SUPERJUMP.gif" but what happened was, when I pressed the space bar, the whole window just closed.

Where is the sprite?

pygame.image.load(...) returns an image object, but if you don't save it to a variable it's lost. You didn't assign the return value to anything, so your code addition has no effect. Further, where did you add the code?

I recommend that you learn to program before trying to make a game. You don't know what you're doing yet, which is why you can't see how to do it.

Share this post


Link to post
Share on other sites
Quote:
Original post by Oluseyi
Quote:
Original post by Markgilst
So then, with only that added, and no jumping code, I was expecting to see just the sprite change to "SUPERJUMP.gif" but what happened was, when I pressed the space bar, the whole window just closed.

Where is the sprite?

pygame.image.load(...) returns an image object, but if you don't save it to a variable it's lost. You didn't assign the return value to anything, so your code addition has no effect. Further, where did you add the code?

I recommend that you learn to program before trying to make a game. You don't know what you're doing yet, which is why you can't see how to do it.

Here is the new, slightly changed code:

bif="Chapter1bg.JPG"
mif="mudskipperstill.gif"

import pygame, sys
from pygame.locals import *

pygame.init()

screen=pygame.display.set_mode((640,480),0,32)
background=pygame.image.load(bif).convert()
mouse_c=pygame.image.load(mif).convert_alpha()

x,y=130,300
movex, movey=0,0

while True:

for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit
if event.type==KEYDOWN:
if event.key==K_LEFT:
movex=-0.5
elif event.key==K_RIGHT:
movex=+0.5
elif event.key==K_SPACE:
pygame.image.load(SUPERJUMP.gif)
if event.type == KEYUP:
if event.key==K_LEFT:
movex=0
elif event.key==K_RIGHT:
movex=0

x+=movex
y+=movey

screen.blit(background,(0,0))
screen.blit(mouse_c,(x,y))

pygame.display.update()

Share this post


Link to post
Share on other sites
Another problem with the regular sidescroller levels is that if I do pretty much the same code, it only shows the whole 1000 X 100 picture, zoomed out. I haven't done anything to modify the code yet, but what exactly am I supposed to put to make it so that it zooms in wherever the sprite is and so that when the sprite moves right the image pans left?

Yeah, I'm a total noob to programming, but that's why I joined this forum and called on you experts to help.

Share this post


Link to post
Share on other sites
Dude, look over your code. What causes the background to be displayed? What causes the mudskipper to be displayed?



bif="Chapter1bg.JPG"
mif="mudskipperstill.gif"

background=pygame.image.load(bif).convert()
mouse_c=pygame.image.load(mif).convert_alpha()
.
.
.

screen.blit(background,(0,0))
screen.blit(mouse_c,(x,y))

pygame.display.update()



You see the lines that assign background to an image? And, then later, you blit that image to the screen? You do the same thing with mudskipper, you assign it to an image, then blit it to the screen.

If you want to blit a new image to the screen, you need to assign the image to a variable, then blit that variable. if you just want to change an image, then you need to assign the variable image to a new image, like this:


.
.
.
while True:

for event in pygame.event.get():
.
.
.
elif event.key==K_SPACE:
mouse_c = pygame.image.load("SUPERJUMP.gif")
.
.
.

screen.blit(background,(0,0))
screen.blit(mouse_c,(x,y))

pygame.display.update()



See what i did there? I assigned mouse_c to the new image, and I added quotes around the image name (just like how mif="mudskipperstill.gif" is done earlier).

Learn to program. Don't expect someone else to anwers all your quesitons, go do research yourself.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!