From 1eb52fbcff0e382cee7da5cb1b4efb8f84a6246b Mon Sep 17 00:00:00 2001 From: anna <1711763800@qq.com> Date: Thu, 28 May 2026 11:00:18 +0800 Subject: [PATCH] add images --- main.py | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 55 insertions(+), 6 deletions(-) diff --git a/main.py b/main.py index fa03d93..0720326 100644 --- a/main.py +++ b/main.py @@ -1,22 +1,71 @@ -import pygame +import pgzrun import random #start -pygame.init() +pgzrun.init() #background WIDTH , HEIGHT = 600,200 -screen = pygame.display.set_mode((WIDTH,HEIGHT)) -pygame.display.set_caption("dinosour running") +screen = pgzrun.display.set_mode((WIDTH,HEIGHT)) +pgzrun.display.set_caption("dinosaur running") #colour WHITE = (255,255,255) BLACK = (0,0,0) -clock = pygame.time.Clock() +clock = pgzrun.time.Clock() FPS = 60 gravity = 0.8 jump_vel = -16 is_jump = False -#dinosaur \ No newline at end of file +#dinosaur +dino_x = 50 +dino_y = 140 +dino_y_vel = 0 +is_jump = False + +#bairies +cactus_list = [] +cactus_speed = 6 +spawn_timer = 0 + +#game condition +game_over = False +score = 0 +font = pgzrun.font.SysFont(None,30) + +#main loop +running = True +while running: + clock.tick(FPS) + screen.fill(WHITE) + + for event in pgzrun.event.get(): + if event.type == pgzrun.QUIT: + running = False + if event.type == pgzrun.KEYKNOWN: + if event.key == pgzrun.K_SPACE and not is_jump and not game_over: + dino_y_vel = jump_vel + is_jump = True + #restart the game + if event.key == pgzrun.K_SPACE and game_over: + game_over = False + score = 0 + cactus_list.clear() + dino_y = 140 + dino_y_vel = 0 + + if not game_over: + dino_y_vel += gravity + dino_y += dino_y_vel + + if dino_y >= 140: + dino_y = 140 + dino_y_vel = 0 + is_jump = False + + #produce bairy + spawn_timer += 1 + if spawn_timer > 80: + cactus_x = WIDTH \ No newline at end of file