943,906 Members | Top Members by Rank

Ad:
  • Python Discussion Thread
  • Marked Solved
  • Views: 1711
  • Python RSS
You are currently viewing page 1 of this multi-page discussion thread
Jun 10th, 2009
0

Platform game help

Expand Post »
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
Similar Threads
Reputation Points: 8
Solved Threads: 1
Light Poster
Darkangelchick is offline Offline
35 posts
since Aug 2008
Jun 10th, 2009
0

Re: Platform game help

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.
Reputation Points: 186
Solved Threads: 77
Posting Pro in Training
shadwickman is offline Offline
495 posts
since Jul 2007
Jun 15th, 2009
0

Re: Platform game help

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.
Reputation Points: 10
Solved Threads: 1
Junior Poster in Training
besktrap is offline Offline
58 posts
since Jul 2008
Jun 15th, 2009
0

Re: Platform game help

Here is an example using the module pygame:
python Syntax (Toggle Plain Text)
  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()
Attached Images
 
Last edited by sneekula; Jun 15th, 2009 at 12:47 pm. Reason: add gif
Reputation Points: 961
Solved Threads: 211
Nearly a Posting Maven
sneekula is offline Offline
2,413 posts
since Oct 2006
Jun 15th, 2009
0

Re: Platform game help

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
Reputation Points: 8
Solved Threads: 1
Light Poster
Darkangelchick is offline Offline
35 posts
since Aug 2008
Jun 17th, 2009
0

Re: Platform game help

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
Reputation Points: 8
Solved Threads: 1
Light Poster
Darkangelchick is offline Offline
35 posts
since Aug 2008
Jun 17th, 2009
0

Re: Platform game help

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?
Reputation Points: 186
Solved Threads: 77
Posting Pro in Training
shadwickman is offline Offline
495 posts
since Jul 2007
Jun 18th, 2009
0

Re: Platform game help

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.
Reputation Points: 9
Solved Threads: 5
Posting Pro
tomtetlaw is offline Offline
591 posts
since Sep 2008
Jun 18th, 2009
0

Re: Platform game help

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
Reputation Points: 8
Solved Threads: 1
Light Poster
Darkangelchick is offline Offline
35 posts
since Aug 2008
Jul 1st, 2009
0

Re: Platform game help

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...

Python Syntax (Toggle Plain Text)
  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
Reputation Points: 8
Solved Threads: 1
Light Poster
Darkangelchick is offline Offline
35 posts
since Aug 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Python Forum Timeline: Simple Database. Linux Path? etc?
Next Thread in Python Forum Timeline: Returning status from compiled PY module





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC