Коровы плодятся и едят растения, даже есть какой то баланс.
This commit is contained in:
@@ -3,33 +3,50 @@ from random import randint
|
|||||||
import numpy as np
|
import numpy as np
|
||||||
|
|
||||||
SCREEN_SIZE = (800,600)
|
SCREEN_SIZE = (800,600)
|
||||||
TICK_TIME = 1
|
TICK_TIME = 0.5
|
||||||
|
|
||||||
class Cow(arcade.SpriteCircle):
|
class Cow(arcade.SpriteCircle):
|
||||||
ls = arcade.SpriteList()
|
ls = arcade.SpriteList()
|
||||||
def __init__(self,parent=None):
|
def __init__(self,parent=None):
|
||||||
super().__init__(radius=5, color=arcade.color.BROWN)
|
super().__init__(radius=5, color=arcade.color.BROWN)
|
||||||
if parent:
|
if parent:
|
||||||
pass
|
self.center_x = parent.center_x
|
||||||
|
self.center_y = parent.center_y
|
||||||
else:
|
else:
|
||||||
self.center_x = randint(1,SCREEN_SIZE[0])
|
self.center_x = randint(1,SCREEN_SIZE[0])
|
||||||
self.center_y = randint(1,SCREEN_SIZE[1])
|
self.center_y = randint(1,SCREEN_SIZE[1])
|
||||||
self.age = 0
|
self.age = 0
|
||||||
self.age_to_bride = 3
|
self.age_to_bride = 3
|
||||||
|
self.health = 30
|
||||||
self.speed = 5
|
self.speed = 5
|
||||||
Cow.ls.append(self)
|
Cow.ls.append(self)
|
||||||
@classmethod
|
@classmethod
|
||||||
def update(cls):
|
def update(cls):
|
||||||
for c in cls.ls:
|
for c in cls.ls:
|
||||||
near_plant = Plant.get_near(c.center_x,c.center_y)
|
c.age += 1
|
||||||
if near_plant:
|
if c.age >= 30:
|
||||||
vec = cls.get_vector(c.center_x,near_plant.center_x,
|
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,
|
||||||
c.center_y,near_plant.center_y)
|
c.center_y,near_plant.center_y)
|
||||||
new_x = c.center_x + vec[0]*randint(0,c.speed)
|
new_x = c.center_x + vec[0]*randint(0,c.speed)
|
||||||
new_y = c.center_y + vec[1]*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]:
|
if 0 < new_x < SCREEN_SIZE[0] and 0 < new_y < SCREEN_SIZE[1]:
|
||||||
c.center_x = new_x
|
c.center_x = new_x
|
||||||
c.center_y = new_y
|
c.center_y = new_y
|
||||||
|
c.health -= 1
|
||||||
|
if c.health <= 0:
|
||||||
|
cls.ls.remove(c)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def draw(cls):
|
def draw(cls):
|
||||||
@@ -97,7 +114,6 @@ class MainView(arcade.View):
|
|||||||
super().__init__()
|
super().__init__()
|
||||||
self.background_color = (100,100,200)
|
self.background_color = (100,100,200)
|
||||||
Plant()
|
Plant()
|
||||||
Cow()
|
|
||||||
self.time = 0
|
self.time = 0
|
||||||
self.cur_time = 0
|
self.cur_time = 0
|
||||||
self.text = None
|
self.text = None
|
||||||
@@ -109,6 +125,8 @@ class MainView(arcade.View):
|
|||||||
Cow.update()
|
Cow.update()
|
||||||
self.time += 1
|
self.time += 1
|
||||||
self.cur_time = 0
|
self.cur_time = 0
|
||||||
|
if self.time == 30:
|
||||||
|
Cow()
|
||||||
#self.text = arcade.Text(f'Time: {self.time}',20,100,(255,255,255))
|
#self.text = arcade.Text(f'Time: {self.time}',20,100,(255,255,255))
|
||||||
|
|
||||||
def on_draw(self):
|
def on_draw(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user