![]() |
A learner game - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Game Development (https://python-forum.io/forum-11.html) +--- Thread: A learner game (/thread-13493.html) |
A learner game - Mentlegenn - Oct-17-2018 I am fairly new to Python and am writing a very basic game. Essentially all we are doing is copying and understanding snippets of code but for some reason, this script for "gravity" won't work as well as the whole movement system despite it being completely accurate: user_input = pygame.key.get_pressed() if user_input[pygame.K_UP]: player.move(0,-2) elif player.rect.y < (height -60): player.move(0,5) if user_input[pygame.K_DOWN]: player.move(0,2) if user_input[pygame.K_LEFT]: player.move(-2,0) if player.rect.x < 0: player.rect.x= width -1 if user_input[pygame.K_RIGHT]: player.move(2,0) if player.rect.x > width: player.rect.x= -59 Any help would be much appreciated! ![]() RE: A learner game - Windspar - Oct-17-2018 Without seeing player class and event loop. All I can do is guess. Maybe you want player.rect.move. RE: A learner game - Mentlegenn - Oct-17-2018 I have just tried that and it still doesn't seem to work :/ the full code for the movement is here: running = True while running: clock.tick(60) for event in pygame.event.get(): if event.type == pygame.QUIT: running = False if (event.type == pygame.KEYDOWN) and (event.key == pygame.K_SPACE): if colour == (0,128,255): colour = (255,100,0) else: colour = (0,128,255) #allow the user to move user_input = pygame.key.get_pressed() if user_input[pygame.K_UP]: player.rect.move(0,-2) elif player.rect.y < (height -60): player.rect.move(0,5) if user_input[pygame.K_DOWN]: player.rect.move(0,2) if user_input[pygame.K_LEFT]: player.rect.move(-2,0) if player.rect.x < 0: player.rect.x= width -1 if user_input[pygame.K_RIGHT]: player.rect.move(2,0) if player.rect.x > width: player.rect.x= -59hope this helps. RE: A learner game - Windspar - Oct-17-2018 Still not enough code. Full event loop and player class. For best result just show full code. Then we can see where the mistake was made. |