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-05-20 20:21:21 (GMT)
committer Rodolfo D. Arce S <rodolfo.arce.s@gmail.com>2011-05-20 20:21:21 (GMT)
commited1ccf7802938dbdbc4704a852b462e8b1cd8158 (patch)
tree6a08aaa2659be0b82692d892343dd30a985d709f
parent08e4802f06435915162ab4711811e2caa4e49627 (diff)
Added some (time)logic to growing a tree by the ranger
-rw-r--r--main.py14
-rw-r--r--ranger.py10
2 files changed, 21 insertions, 3 deletions
diff --git a/main.py b/main.py
index 2ce06a7..6f3cb13 100644
--- a/main.py
+++ b/main.py
@@ -12,7 +12,7 @@ from ranger import Ranger
pygame.init()
-global window_h, window_w
+global window_h, window_w, trees
window_h = 640
window_w = 480
@@ -23,6 +23,7 @@ pygame.display.set_caption("Ranger")
# Tree
plant_time = 100
+new_plant = False
trees = []
start_time = time.time()
@@ -59,11 +60,18 @@ while True:
keyboard = pygame.key.get_pressed()
if keyboard[K_ESCAPE]:
exit()
- if keyboard[K_p]:
+
+ if ranger.plant == True:
+ ranger.new_plant = True
+ ranger.plant = False
+ new_plant_position = ranger.position
+
+ if ranger.new_plant == True:
plant_time += 1
if plant_time > 200:
- trees.append(Tree( ranger.position ) )
+ trees.append(Tree( new_plant_position ) )
plant_time = 0
+ new_plant = False
# Update ranger position based on events
ranger.update()
diff --git a/ranger.py b/ranger.py
index 1e67e71..e7ef08d 100644
--- a/ranger.py
+++ b/ranger.py
@@ -2,6 +2,8 @@ import pygame
class Ranger:
def __init__(self, screen_w, screen_h, ranger_speed):
+ self.plant = False
+ self.new_plant = True
self.speed = ranger_speed
self.image = pygame.image.load("images/ranger_hat.png")
image_rect = self.image.get_rect()
@@ -38,6 +40,11 @@ class Ranger:
(event.key == pygame.K_DOWN and self.direction_y == 1 and self.direction_x == 0):
self.direction_x = 0
self.direction_y = 0
+
+ if event.type == pygame.KEYDOWN:
+ if event.key == pygame.K_p:
+ self.plant = True
+
def update(self):
image_center = self.image.get_width()/2
@@ -53,3 +60,6 @@ class Ranger:
def get_absolute_rect(self):
return self.collision_rect.move(self.position)
+
+ def plant(self):
+ trees.append(Tree(self.position))