From 6cbf2690d03e1a0f324a965861164081a8d07592 Mon Sep 17 00:00:00 2001 From: Emil Shanaty <65846814+emil28092005@users.noreply.github.com> Date: Thu, 10 Apr 2025 14:14:31 +0300 Subject: [PATCH] spawner update --- gameobjects.py | 7 ++++--- main.py | 6 +++--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/gameobjects.py b/gameobjects.py index 4eaab23..2c5abe4 100644 --- a/gameobjects.py +++ b/gameobjects.py @@ -167,16 +167,17 @@ class UI: class Spawner: active = True # Whether the spawner is active - frequency = 500 # Number of ticks between spawns + delay = 500 # Number of ticks between spawns tick_counter = 0 # Counter for ticks - def __init__(self, barrier_image_path): + def __init__(self, barrier_image_path, delay): self.barrier_image_path = barrier_image_path # Path to the barrier image + self.delay = delay def handle(self): if self.active: self.tick_counter += 1 # Increment tick counter - if self.tick_counter >= self.frequency: # Check if it's time to spawn + if self.tick_counter >= self.delay: # Check if it's time to spawn self.spawn() self.tick_counter = 0 # Reset tick counter diff --git a/main.py b/main.py index 61e0bb8..a1ae345 100644 --- a/main.py +++ b/main.py @@ -3,7 +3,7 @@ import sys from gameobjects import * from genetic_alg import GeneticAlgorithm -POPULATION_SIZE = 50 +POPULATION_SIZE = 20 MUTATION_RATE = 0.5 POPULATION_BEST = 0.2 FRAME_RATE = 160 #TODO: FIX THE INCORRECT FRAME RATE CORRELATION @@ -32,7 +32,7 @@ def init_game(): grass = Background("images/Grass.jpg", 0, 0) grass.set_size(WIDTH, HEIGHT) - BARRIER_SPEED = 1 + BARRIER_SPEED = 15 gameobjects = [] @@ -46,7 +46,7 @@ def init_game(): horse.set_vspeed(0) horse.frame_counter = 0 horse.fitness = 0 - spawner = Spawner("images/Barrier.png") + spawner = Spawner("images/Barrier.png", 125) new_barrier = spawner.spawn() barriers.append(new_barrier) gameobjects.extend(horses)