Platform game help

Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Aug 2008
Posts: 35
Reputation: Darkangelchick is an unknown quantity at this point 
Solved Threads: 1
Darkangelchick Darkangelchick is offline Offline
Light Poster

Platform game help

 
0
  #1
Jun 10th, 2009
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
H@nn@K*:)
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 489
Reputation: shadwickman will become famous soon enough shadwickman will become famous soon enough 
Solved Threads: 76
shadwickman's Avatar
shadwickman shadwickman is offline Offline
Posting Pro in Training

Re: Platform game help

 
0
  #2
Jun 10th, 2009
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
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 58
Reputation: besktrap is an unknown quantity at this point 
Solved Threads: 1
besktrap's Avatar
besktrap besktrap is offline Offline
Junior Poster in Training

Re: Platform game help

 
0
  #3
Jun 15th, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 2,284
Reputation: sneekula has a spectacular aura about sneekula has a spectacular aura about 
Solved Threads: 176
sneekula's Avatar
sneekula sneekula is offline Offline
Nearly a Posting Maven

Re: Platform game help

 
0
  #4
Jun 15th, 2009
Here is an example using the module pygame:
  1. # experiments with module pygame
  2. # free from: http://www.pygame.org/
  3. # load, display and move an image
  4.  
  5. import pygame as pg
  6.  
  7. # initialize pygame
  8. pg.init()
  9.  
  10. # pick an image you have (.bmp .jpg .png .gif)
  11. # if the image file is not in the working folder,
  12. # use the full pathname like "C:/Images/gifs/Pooh.gif"
  13. image_file = "Pooh.gif"
  14.  
  15. # RGB color tuple used by pygame
  16. white = (255, 255, 255)
  17.  
  18. # create a 300x300 white screen
  19. screen = pg.display.set_mode((300,300))
  20. screen.fill(white)
  21.  
  22. # load the image from a file
  23. # convert() unifies the pixel format for faster blit
  24. image = pg.image.load(image_file).convert()
  25.  
  26. # draw image, position the image ulc at x=50, y=20
  27. screen.blit(image, (50, 20))
  28.  
  29. # get the rectangle the image occupies
  30. # rec(x, y, w, h)
  31. start_rect = image.get_rect()
  32.  
  33. # set up the timed event loop
  34. x = 0
  35. y = 0
  36. clock = pg.time.Clock()
  37. keepGoing = True
  38. while keepGoing:
  39. # set rate of move
  40. clock.tick(30)
  41. for event in pg.event.get():
  42. # quit when user clicks on window x
  43. if event.type == pg.QUIT:
  44. keepGoing = False
  45. # move the image ...
  46. x += 1
  47. y += 1
  48. # stop when x exceeds limit
  49. if x > 270:
  50. keepGoing = False
  51. image_rect = start_rect.move(x, y)
  52. # this erases the old sreen with white
  53. screen.fill(white)
  54. # put the image on the screen at new location
  55. screen.blit(image, image_rect)
  56. # update screen
  57. pg.display.flip()
Last edited by sneekula; Jun 15th, 2009 at 12:47 pm. Reason: add gif
Attached Images
 
No one died when Clinton lied.
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 35
Reputation: Darkangelchick is an unknown quantity at this point 
Solved Threads: 1
Darkangelchick Darkangelchick is offline Offline
Light Poster

Re: Platform game help

 
0
  #5
Jun 15th, 2009
ok thanks alot sneekula. This has helped. I didnt even know where to start. Hopefully I can work it out from here. I thought I might have to try with Tkinter or something but I dont have that much time
Thanks I'll let you know how it goes... or when I need more help
H@nn@K*:)
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 35
Reputation: Darkangelchick is an unknown quantity at this point 
Solved Threads: 1
Darkangelchick Darkangelchick is offline Offline
Light Poster

Re: Platform game help

 
0
  #6
Jun 17th, 2009
Hey guys, I have downloaded Pygame but I cant get it to run. I ran both WingIDE and the normal IDE and neither of them can find the module pygame...any ideas?? Thanks alot
H@nn@K*:)
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 489
Reputation: shadwickman will become famous soon enough shadwickman will become famous soon enough 
Solved Threads: 76
shadwickman's Avatar
shadwickman shadwickman is offline Offline
Posting Pro in Training

Re: Platform game help

 
0
  #7
Jun 17th, 2009
That's weird.... so 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
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 379
Reputation: tomtetlaw is an unknown quantity at this point 
Solved Threads: 4
tomtetlaw's Avatar
tomtetlaw tomtetlaw is offline Offline
Posting Whiz

Re: Platform game help

 
0
  #8
Jun 18th, 2009
You might have to add the PyGame directory, or the python directory to the systems PATH variable, just google "Windows PATH variable" and you should be able to find out how.
You would just add the filepath to it, like:
"c:\python25\" to it, if thats how your drive is mapped.
...
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 35
Reputation: Darkangelchick is an unknown quantity at this point 
Solved Threads: 1
Darkangelchick Darkangelchick is offline Offline
Light Poster

Re: Platform game help

 
0
  #9
Jun 18th, 2009
Hey guys, I have tried both installing on Windows and on my laptop which is Linux. The windows one comes up with "module not found" and yes i double checked I had the right version for python. We use 2.6 at school and thats the version I downloaded.
Other than that I have no idea
H@nn@K*:)
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 35
Reputation: Darkangelchick is an unknown quantity at this point 
Solved Threads: 1
Darkangelchick Darkangelchick is offline Offline
Light Poster

Re: Platform game help

 
0
  #10
Jul 1st, 2009
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...

  1. import pygame
  2. from pygame.locals import *
  3.  
  4. screen = pygame.display.set_mode((1024, 768))
  5. background = pygame.image.load('marioscreendesign.bmp')
  6. man = pygame.image.load('superdudepic.bmp')
  7.  
  8. screen.blit(background, (0,0))
  9. screen.blit(man,(0,0))
  10. pygame.display.flip()
  11. for i in range(100):
  12. screen.fill((0,0,0))
  13. screen.blit(background, (0,0))
  14. screen.blit(man,(i,0))
  15. pygame.display.flip()
  16. pygame.time.delay(50)
  17.  
  18. while 1:
  19. # USER INPUT
  20. clock.tick(30)
  21. for event in pygame.event.get():
  22. if not hasattr(event, 'key'): continue
  23. down = event.type == KEYDOWN # key down or up?
  24. if event.key == K_RIGHT: k_right = down * ­5
  25. elif event.key == K_LEFT: k_left = down * 5
  26. elif event.key == K_UP: k_up = down * 2
  27. elif event.key == K_DOWN: k_down = down * ­2
  28. elif event.key == K_ESCAPE: sys.exit(0) # quit the game
  29. 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*:)
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Python Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC