Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRodolfo D. Arce S <rodolfo.arce.s@gmail.com>2011-06-10 03:13:46 (GMT)
committer Rodolfo D. Arce S <rodolfo.arce.s@gmail.com>2011-06-10 03:13:46 (GMT)
commit4f442b748daa336ce08fa035caf1dcd15ba93693 (patch)
tree71535c457e718e898735effe1e90cbaf1ec24381
parentb03ee97224310551a4d283dc892d96f069f14168 (diff)
Show alert and time left when cutter starts on a tree, added some animation when ranger plants a tree
-rw-r--r--images/atention.pngbin0 -> 1039 bytes
-rw-r--r--images/sprout.pngbin0 -> 742 bytes
-rw-r--r--main.py27
-rw-r--r--ranger.py11
-rw-r--r--tree.py21
5 files changed, 42 insertions, 17 deletions
diff --git a/images/atention.png b/images/atention.png
new file mode 100644
index 0000000..f4ac0c5
--- /dev/null
+++ b/images/atention.png
Binary files differ
diff --git a/images/sprout.png b/images/sprout.png
new file mode 100644
index 0000000..75f9d6e
--- /dev/null
+++ b/images/sprout.png
Binary files differ
diff --git a/main.py b/main.py
index 79c8ad8..8edc158 100644
--- a/main.py
+++ b/main.py
@@ -27,7 +27,7 @@ window_h, window_w = screen.get_size ()
# Tree
-plant_time = 100
+plant_time = 10
trees = []
start_time = time.time()
@@ -55,6 +55,10 @@ while number_trees != 0:
trees.append(Tree((randint(0,window_h), randint(0,window_w))) )
number_trees -= 1
+for arbol in trees:
+ arbol.sprout_time = 200
+
+
score = 0
while True:
@@ -78,12 +82,14 @@ while True:
if ranger.new_plant == False:
new_plant_position = ranger.position
ranger.new_plant = True
-
+
+
if ranger.new_plant == True:
plant_time += 1
- if plant_time > 300:
- trees.append(Tree( new_plant_position ) )
+ #trees.append(Tree( new_plant_position ) )
+ if plant_time > 50:
+ trees.append(Tree( new_plant_position ) )
plant_time = 0
ranger.new_plant = False
@@ -106,12 +112,20 @@ while True:
if ranger.collides_with(cortador):
cutter.remove(cortador)
+ # Draw trees or grow them
+ for arbol in trees:
+ if arbol.sprout_time < 200:
+ arbol.sprout_time += 1
+ arbol.draw(screen)
+
# Tree cutters kills trees
for arbol in trees:
for cortador in cutter:
if cortador.collides_with(arbol):
cortador.cut_tree = True
+ arbol.draw_alert(screen)
cortador.cut_time += 1
+ arbol.cutting_time -=1
if cortador.cut_tree == True and cortador.cut_time == 100:
trees.remove(arbol)
cortador.cut_time = 0
@@ -122,15 +136,14 @@ while True:
cutter_time = 0
cutter_time += 1
- for arbol in trees:
- arbol.draw(screen)
+
## SCORE IS DRAWN AFTER EVERYTHING ELSE
# Score is equal to amount of trees
for arbol in trees:
score += 1
# Score text
- score_text = "Air: " + str(score) + " Planting in : " + str(plant_time)
+ score_text = "Air: " + str(score)
font = pygame.font.Font(None, 36)
text = font.render( score_text , 1, (0, 0, 0, 0))
screen.blit(text, (0, 0))
diff --git a/ranger.py b/ranger.py
index 765a403..6769c57 100644
--- a/ranger.py
+++ b/ranger.py
@@ -8,7 +8,7 @@ class Ranger:
self.speed = ranger_speed
self.image = pygame.image.load("images/ranger_hat.png")
image_rect = self.image.get_rect()
- size_reduction = 10
+ size_reduction = 5
self.collision_rect = pygame.Rect(image_rect.left + size_reduction, \
image_rect.top + size_reduction, \
image_rect.width - size_reduction, \
@@ -46,14 +46,7 @@ class Ranger:
if event.type == pygame.KEYDOWN:
if self.new_plant == False:
if event.key == pygame.K_p:
- self.plant = True
-
- # Handle Tree cutting key
- #if event.type == pygame.KEYDOWN:
- # if self.cut_tree == False
- # if event.key == pygame.K_c:
- # self.cut_tree == True
-
+ self.plant = True
def update(self):
image_center = self.image.get_width()/2
diff --git a/tree.py b/tree.py
index 34984c0..5e98151 100644
--- a/tree.py
+++ b/tree.py
@@ -3,11 +3,16 @@ 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, \
@@ -16,7 +21,21 @@ class Tree:
image_rect.height - size_reduction)
def draw(self, on_surface):
- on_surface.blit(self.image, self.position)
+ 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())