Zaktualizuj 'plant.py'

This commit is contained in:
Cezary Adamczak 2021-05-10 14:37:15 +02:00
parent bc02986bb3
commit 25dccc958b

100
plant.py
View File

@ -1,44 +1,56 @@
import pygame import pygame
from colors import * from colors import *
from dimensions import * from dimensions import *
from sprites import * 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
self.position = field.position if self.species == "wheat":
self.field = field self.growth_speed = 1.5
self.rect = self.surf.get_rect( self.humidity_needed = 2
topleft=((MARGIN + WIDTH) * self.position[0] + MARGIN, (MARGIN + HEIGHT) * self.position[1] + MARGIN)) self.img0 = wheat_img_0
self.growth = 0 self.img1 = wheat_img_1
self.isHealthy = True self.img2 = wheat_img_2
self.species = species self.img3 = wheat_img_3
if self.species == "beetroot": elif self.species == "potato":
self.growth_speed = 1.5 self.growth_speed = 1
self.humidity_needed = 2 self.humidity_needed = 1
elif self.species == "wheat": self.img0 = potato_img_0
self.growth_speed = 1 self.img1 = potato_img_1
self.humidity_needed = 1 self.img2 = potato_img_2
elif self.species == "cotton": self.img3 = potato_img_3
self.growth_speed = 0.8 elif self.species == "strawberry":
self.humidity_needed = 1 self.growth_speed = 0.8
self.humidity_needed = 1
self.img0 = strawberry_img_0
def grow(self): self.img1 = strawberry_img_1
if self.field.hydration >= self.humidity_needed: self.img2 = strawberry_img_2
self.growth += self.growth_speed self.img3 = strawberry_img_3
if self.field.hydration == 0: self.surf = self.img0
self.growth -= self.growth_speed self.position = field.position
if self.growth > 4: self.field = field
self.growth = 4 self.rect = self.surf.get_rect(
if self.growth < 0: topleft=((MARGIN + WIDTH) * self.position[0] + MARGIN, (MARGIN + HEIGHT) * self.position[1] + MARGIN))
self.growth = 0 self.growth = 0
if self.growth == 0: self.isHealthy = True
self.surf = plant_img_0 field.planted = True
elif self.growth == 1:
self.surf = plant_img_1 def grow(self):
elif self.growth == 2: if self.field.hydration >= self.humidity_needed:
self.surf = plant_img_2 self.growth += self.growth_speed
elif self.growth == 3: if self.field.hydration == 0:
self.surf = plant_img_3 self.growth -= self.growth_speed
if self.growth > 4:
self.growth = 4
if self.growth < 0:
self.growth = 0
if self.growth == 0:
self.surf = self.img0
elif self.growth < 1:
self.surf = self.img1
elif self.growth < 2:
self.surf = self.img2
elif self.growth <= 3:
self.surf = self.img3