Zaktualizuj 'plant.py'
This commit is contained in:
parent
bc02986bb3
commit
25dccc958b
50
plant.py
50
plant.py
@ -6,24 +6,36 @@ from sprites import *
|
|||||||
class Plant(pygame.sprite.Sprite):
|
class Plant(pygame.sprite.Sprite):
|
||||||
def __init__(self, field, species):
|
def __init__(self, field, species):
|
||||||
super(Plant, self).__init__()
|
super(Plant, self).__init__()
|
||||||
self.surf = plant_img_0
|
self.species = species
|
||||||
|
if self.species == "wheat":
|
||||||
|
self.growth_speed = 1.5
|
||||||
|
self.humidity_needed = 2
|
||||||
|
self.img0 = wheat_img_0
|
||||||
|
self.img1 = wheat_img_1
|
||||||
|
self.img2 = wheat_img_2
|
||||||
|
self.img3 = wheat_img_3
|
||||||
|
elif self.species == "potato":
|
||||||
|
self.growth_speed = 1
|
||||||
|
self.humidity_needed = 1
|
||||||
|
self.img0 = potato_img_0
|
||||||
|
self.img1 = potato_img_1
|
||||||
|
self.img2 = potato_img_2
|
||||||
|
self.img3 = potato_img_3
|
||||||
|
elif self.species == "strawberry":
|
||||||
|
self.growth_speed = 0.8
|
||||||
|
self.humidity_needed = 1
|
||||||
|
self.img0 = strawberry_img_0
|
||||||
|
self.img1 = strawberry_img_1
|
||||||
|
self.img2 = strawberry_img_2
|
||||||
|
self.img3 = strawberry_img_3
|
||||||
|
self.surf = self.img0
|
||||||
self.position = field.position
|
self.position = field.position
|
||||||
self.field = field
|
self.field = field
|
||||||
self.rect = self.surf.get_rect(
|
self.rect = self.surf.get_rect(
|
||||||
topleft=((MARGIN + WIDTH) * self.position[0] + MARGIN, (MARGIN + HEIGHT) * self.position[1] + MARGIN))
|
topleft=((MARGIN + WIDTH) * self.position[0] + MARGIN, (MARGIN + HEIGHT) * self.position[1] + MARGIN))
|
||||||
self.growth = 0
|
self.growth = 0
|
||||||
self.isHealthy = True
|
self.isHealthy = True
|
||||||
self.species = species
|
field.planted = True
|
||||||
if self.species == "beetroot":
|
|
||||||
self.growth_speed = 1.5
|
|
||||||
self.humidity_needed = 2
|
|
||||||
elif self.species == "wheat":
|
|
||||||
self.growth_speed = 1
|
|
||||||
self.humidity_needed = 1
|
|
||||||
elif self.species == "cotton":
|
|
||||||
self.growth_speed = 0.8
|
|
||||||
self.humidity_needed = 1
|
|
||||||
|
|
||||||
|
|
||||||
def grow(self):
|
def grow(self):
|
||||||
if self.field.hydration >= self.humidity_needed:
|
if self.field.hydration >= self.humidity_needed:
|
||||||
@ -35,10 +47,10 @@ class Plant(pygame.sprite.Sprite):
|
|||||||
if self.growth < 0:
|
if self.growth < 0:
|
||||||
self.growth = 0
|
self.growth = 0
|
||||||
if self.growth == 0:
|
if self.growth == 0:
|
||||||
self.surf = plant_img_0
|
self.surf = self.img0
|
||||||
elif self.growth == 1:
|
elif self.growth < 1:
|
||||||
self.surf = plant_img_1
|
self.surf = self.img1
|
||||||
elif self.growth == 2:
|
elif self.growth < 2:
|
||||||
self.surf = plant_img_2
|
self.surf = self.img2
|
||||||
elif self.growth == 3:
|
elif self.growth <= 3:
|
||||||
self.surf = plant_img_3
|
self.surf = self.img3
|
||||||
|
Loading…
Reference in New Issue
Block a user