diff --git a/images/dead.png b/images/dead.png new file mode 100644 index 0000000..b829dff Binary files /dev/null and b/images/dead.png differ diff --git a/images/dino.png b/images/dino.png new file mode 100644 index 0000000..2a6a255 Binary files /dev/null and b/images/dino.png differ diff --git a/main.py b/main.py index 0f1c4d5..41251ca 100644 --- a/main.py +++ b/main.py @@ -19,24 +19,62 @@ min_spawn_interval = 0.2 spawn_timer = 0 game_time = 0 -def draw(): - screen.fill((100,220,100)) - apple.draw() - -def spawn_dinosaur(): - dino = Actor("dino") +def spawn_dinosaurs(): + dino = Actor("dino") + side = random.randint(0,3) - if side == 0: - dino_x = random.randint(0.WIDTH) - dino_y = -50 - elif side == 1: - dino_x = random.randint(0,WIDTH) - dino_y = HEIGHT + 50 - elif side == 2: - dino_x = WIDTH + 50 - dino_y = random.randint(0,HEIGHT) + if side == 0: #up + dino.x = random.randint(2,WIDTH) + dino.y = -50 + elif side == 1: #down + dino.x = random.randint(0,WIDTH) + dino.y = HEIGHT + 50 + elif side == 2: #left + dino.x = -50 + dino.y = random.randint(0,HEIGHT) + else: + dino.x = WIDTH + 50 + dino.y = random.randint(0,HEIGHT) dinosuars.append(dino) +def update(dt): + global spawn_timer , spawn_interval , game_time + game_time += dt + spawn_timer += dt + + spawn_interval = max(min_spawn_interval , spawn_interval - 0.005 * dt) + + if spawn_timer >= spawn_interval: + spawn_dinosaurs() + spawn_timer = 0 + + sword.pos = mouse.pos + + for dino in dinosuars[:]: + dx = apple_x - dino.x + dy = apple_y - dino.y + speed = 80 + dino.x += dx * speed * dt + dino.y += dy * speed * dt + + if dino.colliderect(sword): + dino.image = "dead" + corpses.append({"Actor":dino,"die_time": game_time}) + sounds.hit.play() + dinosuars.remove(dino) + + for corpse in corpses[:]: + if game_time - corpse["die_time"] >= 2: + corpses.remove(corpse) + +def draw(): + screen.fill((100,200,100)) + apple.draw() + sword.draw() + for dino in dinosuars: + dino.draw() + for corpse in corpses: + corpse["Actor"].draw() pgzrun.go() \ No newline at end of file