1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
import pygame
from random import randint
tree_images_number = 3
tree_images = ["images/tree_%02d.png" % tree_images_number for tree_images_number in xrange(1, tree_images_number + 1) ]
cutting_time = 100
class Tree:
def __init__(self, position):
self.cutting_time = cutting_time
self.sprout_time = 0
self.position = position
self.image = pygame.image.load(tree_images[randint(0, tree_images_number - 1)])
self.alert_image = pygame.image.load("images/atention.png")
self.sprout_image = pygame.image.load("images/sprout.png")
image_rect = self.image.get_rect()
size_reduction = 10
self.collision_rect = pygame.Rect(image_rect.left - size_reduction, \
image_rect.top - size_reduction, \
image_rect.width - size_reduction, \
image_rect.height - size_reduction)
def draw(self, on_surface):
if self.sprout_time == 200:
on_surface.blit(self.image, self.position)
else:
sprout_text = str(self.sprout_time)
font = pygame.font.Font(None, 24)
text = font.render( sprout_text , 1, (0, 0, 0, 0))
on_surface.blit(self.sprout_image, self.position)
on_surface.blit( text, self.position)
def draw_alert(self, on_surface):
on_surface.blit(self.alert_image, self.position)
cutting_text = str(self.cutting_time)
font = pygame.font.Font(None, 24)
text = font.render( cutting_text , 1, (0, 0, 0, 0))
on_surface.blit( text, self.position)
def collides_with(self, other):
return self.get_absolute_rect().colliderect(other.get_absolute_rect())
def get_absolute_rect(self):
return self.collision_rect.move(self.position)
|