Улучшил баланс. Корова идет к одному из ближайщих 3х растений. Учитывается так же размер растения. Если последняя корова умирает, то новая случайным образом спавнится.

This commit is contained in:
2026-06-17 17:46:47 +03:00
parent 1127cd9cb1
commit dc9a8d52ff
+15 -11
View File
@@ -19,6 +19,8 @@ class Cow(arcade.SpriteCircle):
self.age_to_bride = 3
self.health = 30
self.speed = 5
self.move_target = 0
self.target_timer = 0
Cow.ls.append(self)
@classmethod
def update(cls):
@@ -26,6 +28,8 @@ class Cow(arcade.SpriteCircle):
c.age += 1
if c.age >= 30:
cls.ls.remove(c)
if len(cls.ls) == 0:
Cow()
continue
hit_plant = arcade.check_for_collision_with_list(c,Plant.ls)
for p in hit_plant:
@@ -35,10 +39,12 @@ class Cow(arcade.SpriteCircle):
c.health -= 30
Plant.ls.remove(p)
else:
near_plant = Plant.get_near(c.center_x,c.center_y)
if near_plant:
vec = cls.get_vector(c.center_x,near_plant.center_x,
c.center_y,near_plant.center_y)
if c.target_timer <= 0:
c.move_target = Plant.get_near(c.center_x,c.center_y)
c.target_timer = 5
if c.move_target:
vec = cls.get_vector(c.center_x,c.move_target.center_x,
c.center_y,c.move_target.center_y)
new_x = c.center_x + vec[0]*randint(0,c.speed)
new_y = c.center_y + vec[1]*randint(0,c.speed)
if 0 < new_x < SCREEN_SIZE[0] and 0 < new_y < SCREEN_SIZE[1]:
@@ -79,14 +85,11 @@ class Plant(arcade.SpriteCircle):
Plant.ls.append(self)
@classmethod
def get_near(cls,x,y):
min_dist = SCREEN_SIZE[0]
near_plant = None
dist_list = list()
for p in cls.ls:
dist = ((p.center_x - x)**2 + (p.center_y - y)**2)**0.5
if dist < min_dist:
near_plant = p
min_dist = dist
return near_plant
dist_list.append((p,((p.center_x - x)**2 + (p.center_y - y)**2)**0.5 - p.width ))
dist_list.sort(key=lambda x: x[1])
return dist_list[randint(0,3)][0]
@classmethod
def update(cls):
for p in cls.ls:
@@ -121,6 +124,7 @@ class MainView(arcade.View):
def on_update(self, delta_time):
self.cur_time += delta_time
if self.cur_time >= TICK_TIME:
print(f'Total plants: {len(Plant.ls)}, total cows: {len(Cow.ls)}')
Plant.update()
Cow.update()
self.time += 1