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-18 15:12:25 (GMT)
committer Rodolfo D. Arce S <rodolfo.arce.s@gmail.com>2011-05-18 15:12:25 (GMT)
commit6d25c398c9d4f66b32268e63d722dbf0ab6c224e (patch)
tree714ac738e30855b757cc8bb8d2ba507bb6084066
parent1082b11f8724475e79513bd3b041c96669cfcb60 (diff)
Changed speed and TTL of garbage, changed creation position so it doesn't mess up score
-rw-r--r--garbage.py11
-rw-r--r--main.py16
-rw-r--r--person.py10
3 files changed, 24 insertions, 13 deletions
diff --git a/garbage.py b/garbage.py
index 478f3ce..b324511 100644
--- a/garbage.py
+++ b/garbage.py
@@ -24,8 +24,8 @@ class Garbage:
def update(self):
image_center = self.image.get_width()/2
- self.position = [((self.position[0] - randint(0,10) )%self.screen_w), \
- ((self.position[1] - randint(0,10) )%self.screen_h) ]
+ self.position = [(self.position[0] - randint(0, self.speed) ), \
+ (self.position[1] - randint(0, self.speed) ) ]
def collides_with(self, other):
return self.get_absolute_rect().colliderect(other.get_absolute_rect())
@@ -33,8 +33,11 @@ class Garbage:
def draw(self, on_surface):
on_surface.blit(self.image, self.position)
- def died(self):
- return self.position[0] > self.screen_w
+ def died_x(self):
+ return self.position[0] < 0
+
+ def died_y(self):
+ return self.position[1] < 0
def draw_alert(self, on_surface):
on_surface.blit(self.alert_image, self.position)
diff --git a/main.py b/main.py
index 6e4c88b..036150e 100644
--- a/main.py
+++ b/main.py
@@ -22,7 +22,7 @@ unit = 1.0
score = 0
robot_speed = 9
-garbage_speed = 3
+garbage_speed = 1
person_speed = 4
@@ -88,7 +88,9 @@ while not exit:
if last_garbage_tick == 0:
last_garbage_tick = garbage_generation_ticks
for person in people:
- trash.append(Garbage( window_w, window_h, unit, garbage_speed, (person.position[0] - 20, person.position[1] - 20) ))
+ trash.append(Garbage( window_w, window_h, unit, garbage_speed, \
+ (person.position[0] - (person.image_rect.height/2), \
+ person.position[1] - (person.image_rect.width/2)) ))
else:
last_garbage_tick -= 1
@@ -110,15 +112,18 @@ while not exit:
people.remove(person)
for garbage in trash:
- if garbage.died():
+ if garbage.died_x() or garbage.died_y():
trash.remove(garbage)
- # update objects
+ # Persons
for person in people:
person.update()
+
+ # Garbage
for garbage in trash:
garbage.update()
+ # Robot
robot.update()
# draw the background first, because it will cover all the screen
@@ -131,8 +136,11 @@ while not exit:
# Persons
for person in people:
person.draw(screen)
+
+ #Garbage
for garbage in trash:
garbage.draw(screen)
+
#Robot
robot.draw(screen)
diff --git a/person.py b/person.py
index d8ed55e..3edd178 100644
--- a/person.py
+++ b/person.py
@@ -10,12 +10,12 @@ class Person:
self.unit = unit
self.speed = speed
self.image = pygame.image.load(persons[randint(0, person_number - 1)])
- image_rect = self.image.get_rect()
+ self.image_rect = self.image.get_rect()
size_reduction = 20*unit
- 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)
+ self.collision_rect = pygame.Rect( self.image_rect.left + size_reduction, \
+ self.image_rect.top + size_reduction, \
+ self.image_rect.width - size_reduction, \
+ self.image_rect.height - size_reduction)
#self.position = [ 0, randint(0, screen_h -1)]
self.position = [ 0, randint(75, screen_h - 75)]