Hey, I am doing a 'Helicopter'-style game for a project where the player holds the spacebar for the main sprite to go up, releases to go down. Objects come from the right side of the screen at random y-cords moving until they hit 0 on the x-cord. The player must dodge these objects, while making sure to not hit the top or bottom of the screen. If the player collides with the top, bottom or any object, game is over.
So far the game is coming along OK, with the exception of the scoreboard not working right. BUT I want to implement a start menu that runs before the game starts that explains directions, and starts the game after some user-interaction (if user presses spacebar).
Also, I want to implement a 'Play again?' message if the player loses.
I am very new to pygame and livewires, as this is the 2nd or 3rd time really using them. Any ideas would be greatly appreciated.
from livewires import games, color import random import time games.init(screen_width = 900, screen_height = 480, fps = 50) class Pig(games.Sprite): """The Pig, controlled by the player""" image = games.load_image("pig2.bmp") def __init__(self): super(Pig, self).__init__(image = Pig.image, y = games.screen.height/2, x = 75) def update(self): """falls at a greater rate than flies, spacebar to fly""" if games.keyboard.is_pressed(games.K_SPACE): self.y -= 1.7 self.angle = -20 else: self.y += 2 self.angle = 20 if self.y > games.screen.height: self.end_game() if self.y < 1: self.end_game() self.check_hit() def check_hit(self): """checks to see if pig hits a fence""" for fence in self.overlapping_sprites: self.end_game() def end_game(self): end_message = games.Message(value = "GAME OVER", size = 100, color = color.black, 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) class Fence(games.Sprite): """a razor-wire fence""" image = games.load_image("razor.bmp") SCORE = 0 SPEEDS = [-1, -2] def __init__(self, x, y): super(Fence, self).__init__(image = Fence.image, x = x, y = y, dx = random.choice(Fence.SPEEDS)) self.score_display = games.Text(value = 0, size = 50, color = color.red, top = 5, right = games.screen.width - 10) games.screen.add(self.score_display) def update(self): if self.x < 0: self.die() if self.x == games.screen.width/2: y_cord = random.randrange(games.screen.height) new_fence = Fence(games.screen.width - 10, y_cord) games.screen.add(new_fence) def die(self): self.score_display.destroy() Fence.SCORE += 1 self.score_display = games.Text(value = Fence.SCORE, size = 50, color = color.red, top = 5, right = games.screen.width - 10) games.screen.add(self.score_display) self.destroy() def pause(seconds): go = False while go != True: time.sleep(seconds) go = True def main(): """main func""" pig = Pig() games.screen.add(pig) fence = Fence(games.screen.width - 10, games.screen.height/2) games.screen.add(fence) games.mouse.is_visible = False games.screen.event_grab = True wall_image = games.load_image("wall.jpg") games.screen.background = wall_image games.screen.mainloop() main()