0
votes

OKay, so i wrote a code to develop a game using pygame. this is the aim of the game : there is a player (Mario) which can move only vertically. from the right side of the window, flames appear which the mario has to dodge. the game is very similar to dodger.py ! now, when i run the game, it gets stuck at "Press any key to Enter"

PLEASE HELP !

2
How about you include your code, that would be helpful. - Drewness
Did you try pressing the "any" key? :) Jokes aside, there is nothing set to do in the waitForPlayerToPressKey() function. The if event.type == KEYDOWN: only handles the terminate event, nothing else. - bosnjak
But the dodger game is running perfectly fine even without any addition for a case to check when other keys are pressed ? Whats the difference ? - user3456011

2 Answers

2
votes

You are not doing anything in the waitforkey() function.

if event.type == KEYDOWN:
    # if key exit blah blah
    else:
        runGame() 

You could put your game in a function called runGame and that would probabaly be the easiest way of doing this. Just remember that the variables will then be local to the scope of that function and any changes won't affect the rest of the program.

0
votes

Having checked the code on a PC, I have found 3 errors. Two of which are typing errors. First one is on Line 77:

playerrect.topleft = (50,window_hight/2)

Needs to be:

playerrect.topleft = (50,window_height/2)

and the second is on line 126:

WindowSurface.fill(bgcolour)

You haven't defined bgcolour (as far as I could see) so by adding the following to the variables at the top of the file:

bgcolour(255,255,255) #change to what colour you want

The third error I found was in your waitForKey() function. I don't know whether this is important to the running of the program, but you have your if event.type == "QUIT" in speech marks. Like I said, this may not matter but I thought I'd point it out. You have also done this for the other conditions in this function.

By making these changes, you get running code. However, flames do not appear and I don't have time to figure this one out. By fiddling though, I'm sure you'll figure it out!