| | |
Platform game help
Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
•
•
Join Date: Aug 2008
Posts: 35
Reputation:
Solved Threads: 1
Hey guys I'm attempting to make a super mario like platform game and need help with making images move. Like instead of moving the little man, just having the background moving with the corresponding button movement.
Can anyone hint at how to do this?
Or is moving the little man easier than the background?
Thank you
Can anyone hint at how to do this?
Or is moving the little man easier than the background?
Thank you
H@nn@K*:)
Um... you provided absolutely no information. So as of right now, I can't answer your question. What are you using as a 2D engine for Python? etc.
"Two good old boys in a fire-apple red convertible. Stoned. Ripped. Twisted. Good people."
- Hunter S. Thompson
my photography
- Hunter S. Thompson
my photography
If you wanted to start 2d games in python, I begin with pygame (a python port of SDL). There are tons of tuts everywhere, just have a look. Try www.pygame.org for more info.
Here is an example using the module pygame:
python Syntax (Toggle Plain Text)
# experiments with module pygame # free from: http://www.pygame.org/ # load, display and move an image import pygame as pg # initialize pygame pg.init() # pick an image you have (.bmp .jpg .png .gif) # if the image file is not in the working folder, # use the full pathname like "C:/Images/gifs/Pooh.gif" image_file = "Pooh.gif" # RGB color tuple used by pygame white = (255, 255, 255) # create a 300x300 white screen screen = pg.display.set_mode((300,300)) screen.fill(white) # load the image from a file # convert() unifies the pixel format for faster blit image = pg.image.load(image_file).convert() # draw image, position the image ulc at x=50, y=20 screen.blit(image, (50, 20)) # get the rectangle the image occupies # rec(x, y, w, h) start_rect = image.get_rect() # set up the timed event loop x = 0 y = 0 clock = pg.time.Clock() keepGoing = True while keepGoing: # set rate of move clock.tick(30) for event in pg.event.get(): # quit when user clicks on window x if event.type == pg.QUIT: keepGoing = False # move the image ... x += 1 y += 1 # stop when x exceeds limit if x > 270: keepGoing = False image_rect = start_rect.move(x, y) # this erases the old sreen with white screen.fill(white) # put the image on the screen at new location screen.blit(image, image_rect) # update screen pg.display.flip()
Last edited by sneekula; Jun 15th, 2009 at 12:47 pm. Reason: add gif
No one died when Clinton lied.
That's weird.... so
Other than trying to install the wrong version of pygame for your python installation, I don't know what could be wrong.
What OS are you using? A GNU/Linux distro or Windows?
import pygame is causing the "module not found" error?Other than trying to install the wrong version of pygame for your python installation, I don't know what could be wrong.
What OS are you using? A GNU/Linux distro or Windows?
"Two good old boys in a fire-apple red convertible. Stoned. Ripped. Twisted. Good people."
- Hunter S. Thompson
my photography
- Hunter S. Thompson
my photography
•
•
Join Date: Aug 2008
Posts: 35
Reputation:
Solved Threads: 1
Ok guys I'm back.
I got pygame working on my laptop thankfully.
I've been writing some code to create the screen and get both my little hero dude and the background on the screen. I also found some code to help incorporate user input ...like keys and stuff but I can't seem to get it to work...
compile:
invalid syntax (pygame2.py, line 24)
Traceback (most recent call last):
File "/usr/bin/drpython", line 648, in CheckSyntax
compile(ctext, fn, 'exec')
<type 'exceptions.SyntaxError'>: invalid syntax (pygame2.py, line 24)
this is the error I'm getting and I've tried everything to fix it...but it doesn't want to work. Thanks for the help guys. 'Im new to this and my teacher can't help
I got pygame working on my laptop thankfully.
I've been writing some code to create the screen and get both my little hero dude and the background on the screen. I also found some code to help incorporate user input ...like keys and stuff but I can't seem to get it to work...
Python Syntax (Toggle Plain Text)
import pygame from pygame.locals import * screen = pygame.display.set_mode((1024, 768)) background = pygame.image.load('marioscreendesign.bmp') man = pygame.image.load('superdudepic.bmp') screen.blit(background, (0,0)) screen.blit(man,(0,0)) pygame.display.flip() for i in range(100): screen.fill((0,0,0)) screen.blit(background, (0,0)) screen.blit(man,(i,0)) pygame.display.flip() pygame.time.delay(50) while 1: # USER INPUT clock.tick(30) for event in pygame.event.get(): if not hasattr(event, 'key'): continue down = event.type == KEYDOWN # key down or up? if event.key == K_RIGHT: k_right = down * 5 elif event.key == K_LEFT: k_left = down * 5 elif event.key == K_UP: k_up = down * 2 elif event.key == K_DOWN: k_down = down * 2 elif event.key == K_ESCAPE: sys.exit(0) # quit the game screen.fill(BLACK)
compile:
invalid syntax (pygame2.py, line 24)
Traceback (most recent call last):
File "/usr/bin/drpython", line 648, in CheckSyntax
compile(ctext, fn, 'exec')
<type 'exceptions.SyntaxError'>: invalid syntax (pygame2.py, line 24)
this is the error I'm getting and I've tried everything to fix it...but it doesn't want to work. Thanks for the help guys. 'Im new to this and my teacher can't help
H@nn@K*:)
![]() |
Similar Threads
- java platform game (Java)
- Another Java Noob :( (Java)
Other Threads in the Python Forum
- Previous Thread: Simple Database. Linux Path? etc?
- Next Thread: Returning status from compiled PY module
| Thread Tools | Search this Thread |
alarm assignment avogadro beginner bluetooth character cmd code customdialog cx-freeze data decimals dictionary directory dynamic error examples excel exe file float font format function generator gnu graphics gui halp homework http ideas import input itunes java leftmouse line linux list lists logging loop maintain maze module mouse number numbers output parsing path port prime programming projects push py2exe pygame pyglet pyqt python queue random recursion schedule screensaverloopinactive script scrolledtext slicenotation sqlite ssh stdout string strings sudokusolver table terminal text thread threading time tkinter tlapse tuple tutorial ubuntu unicode urllib urllib2 variable ventrilo verify vigenere web webservice wikipedia windows wxpython xlib






