Коровы плодятся и едят растения, даже есть какой то баланс.

This commit is contained in:
2026-06-11 15:18:54 +03:00
parent cf28a4944f
commit 1127cd9cb1
+21 -3
View File
@@ -3,24 +3,38 @@ from random import randint
import numpy as np
SCREEN_SIZE = (800,600)
TICK_TIME = 1
TICK_TIME = 0.5
class Cow(arcade.SpriteCircle):
ls = arcade.SpriteList()
def __init__(self,parent=None):
super().__init__(radius=5, color=arcade.color.BROWN)
if parent:
pass
self.center_x = parent.center_x
self.center_y = parent.center_y
else:
self.center_x = randint(1,SCREEN_SIZE[0])
self.center_y = randint(1,SCREEN_SIZE[1])
self.age = 0
self.age_to_bride = 3
self.health = 30
self.speed = 5
Cow.ls.append(self)
@classmethod
def update(cls):
for c in cls.ls:
c.age += 1
if c.age >= 30:
cls.ls.remove(c)
continue
hit_plant = arcade.check_for_collision_with_list(c,Plant.ls)
for p in hit_plant:
c.health += p.width
if c.health >= 50 and c.age_to_bride < c.age:
Cow(c)
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,
@@ -30,6 +44,9 @@ class Cow(arcade.SpriteCircle):
if 0 < new_x < SCREEN_SIZE[0] and 0 < new_y < SCREEN_SIZE[1]:
c.center_x = new_x
c.center_y = new_y
c.health -= 1
if c.health <= 0:
cls.ls.remove(c)
@classmethod
def draw(cls):
@@ -97,7 +114,6 @@ class MainView(arcade.View):
super().__init__()
self.background_color = (100,100,200)
Plant()
Cow()
self.time = 0
self.cur_time = 0
self.text = None
@@ -109,6 +125,8 @@ class MainView(arcade.View):
Cow.update()
self.time += 1
self.cur_time = 0
if self.time == 30:
Cow()
#self.text = arcade.Text(f'Time: {self.time}',20,100,(255,255,255))
def on_draw(self):