Dodger game
I am trying to write a game using livewires and pygame where I have a chef (only an image I had, haha), avoid rocks that are falling from the sky. The rocks should be dropped in random places. I want 1 stone to drop from the beginning, and then every time you successfully dodge a rock, 2 more stones fall until you lose. So far I have had a chef and 1 stone. However, for some reason, if the sprites collide, or if a rock touches the bottom of the screen, the game ends without giving the game over the message as I said. I am very confused and cannot see what I have done. I know I didn't code it correctly for the rocks part 2, but I can't even get it to run slightly. Help! Here's what I have now:
from livewires import games, color
import random
games.init(screen_width = 640, screen_height = 480, fps = 50)
class Chef(games.Sprite):
image = games.load_image("chef.bmp")
def __init__(self):
super(Chef, self).__init__(image = Chef.image,
x = games.mouse.x,
bottom = games.screen.height)
def update(self):
self.x = games.mouse.x
if self.left < 0:
self.left = 0
if self.right > games.screen.width:
self.right = games.screen.width
self.check_catch()
def check_catch(self):
for pizza in self.overlapping_sprites:
if not self.bottom>games.screen.height:
self.end_game()
class Rock(games.Sprite):
def update(self):
if self.bottom > games.screen.height:
new_rock=Rock(x=random.randrange(games.screen.width),
y=10,
dy=1)
games.screen.add(new_rock)
def end_game(self):
end_message = games.Message(value = "Game Over",
size = 90,
color = color.red,
x = games.screen.width/2,
y = games.screen.height/2,
lifetime = 5 * games.screen.fps,
after_death = games.screen.quit)
games.screen.add(end_message)
def main():
wall_image = games.load_image("wall.jpg", transparent = False)
games.screen.background = wall_image
the_chef = Chef()
games.screen.add(the_chef)
rock_image=games.load_image("rock.bmp")
the_rock=Rock(image=rock_image,
x=random.randrange(games.screen.width),
y=10,
dy=1)
games.screen.add(the_rock)
games.mouse.is_visible = False
games.screen.event_grab = True
games.screen.mainloop()
main()
+2
a source to share