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-14 22:39:21 (GMT)
committer Rodolfo D. Arce S <rodolfo.arce.s@gmail.com>2011-05-14 22:39:21 (GMT)
commit29db09662bcd25623596b880d7d72b546ae2b322 (patch)
tree69433935ec59bbb2f468d07b9c98414a33441db4
parent1f60e9b2e7245f9fc7bc59d39bc6237a2e916aa1 (diff)
Added alert image when touching person
-rw-r--r--README3
-rw-r--r--garbage.py15
-rw-r--r--images/atention.pngbin0 -> 1039 bytes
-rw-r--r--images/person_01.pngbin5391 -> 5362 bytes
-rw-r--r--images/person_04.pngbin6272 -> 6395 bytes
-rw-r--r--main.py55
-rw-r--r--person.py3
-rw-r--r--robot.py6
8 files changed, 67 insertions, 15 deletions
diff --git a/README b/README
index 7165eb2..a7d9757 100644
--- a/README
+++ b/README
@@ -7,6 +7,9 @@ Images:
Background:
http://www.openclipart.org/detail/62479
+Alert:
+http://www.openclipart.org/detail/48349
+
Robot:
http://www.openclipart.org/detail/161
diff --git a/garbage.py b/garbage.py
index 8cf5bb3..060b79c 100644
--- a/garbage.py
+++ b/garbage.py
@@ -5,12 +5,17 @@ fallers_size = 3
fallers = ["images/garbage_%02d.png" % faller_number for faller_number in xrange(1, fallers_size + 1) ]
class Garbage:
- def __init__(self, screen_w, screen_h, unit, garbage_speed):
+ def __init__(self, screen_w, screen_h, unit, garbage_speed, position):
self.unit = unit
self.speed = garbage_speed
self.image = pygame.image.load(fallers[randint(0, fallers_size - 1)])
image_rect = self.image.get_rect()
- self.position = [0, 0]
+ size_reduction = 5*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.position = position
self.screen_w = screen_w
self.screen_h = screen_h
self.direction_x = 0
@@ -23,3 +28,9 @@ 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 get_absolute_rect(self):
+ return self.collision_rect.move(self.position)
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/person_01.png b/images/person_01.png
index 5aa47a9..de65d9a 100644
--- a/images/person_01.png
+++ b/images/person_01.png
Binary files differ
diff --git a/images/person_04.png b/images/person_04.png
index cc221a1..fcb3c56 100644
--- a/images/person_04.png
+++ b/images/person_04.png
Binary files differ
diff --git a/main.py b/main.py
index 8639311..ed1ea30 100644
--- a/main.py
+++ b/main.py
@@ -20,16 +20,21 @@ window_h = 600
window_w = 800
unit = 1.0
+score = 0
robot_speed = 9
garbage_speed = 3
person_speed = 4
# Person generation interval
-person_generation_ticks = 100
+person_generation_ticks = 150
last_person_tick = 0
+# Garbage generation interval
+garbage_generation_ticks = 500
+last_garbage_tick = 0
-#garbages = []
+
+trash = []
people = []
screen = pygame.display.set_mode((window_w, window_h))
@@ -50,9 +55,10 @@ frame_time = 1.0/fps
# Main loop
exit = False
lost_game = False
+alert = 30
while not exit:
-
+
# Process pygame events
for event in pygame.event.get():
# Escape key to quit the game
@@ -76,43 +82,70 @@ while not exit:
people.append(Person( window_w, window_h, unit, person_speed))
else:
last_person_tick -= 1
+
+ if lost_game == False:
+ # If enough time passed generate a new object
+ 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 ))
+ else:
+ last_garbage_tick -= 1
# Score text
- score = 10
- score_text = "Score: " + str(score) + " Next in : " + str(last_person_tick)
+ score_text = "Score: " + str(score)
font = pygame.font.Font(None, 36)
text = font.render( score_text , 1, (0, 0, 0, 0))
# check collisions
- for person in people:
- if robot.collides_with(person):
+ for garbage in trash:
+ if robot.collides_with(garbage):
#lost_game = True
- people.remove(person)
-
-
+ trash.remove(garbage)
+ score += 5
+
# Remove objects that "died"
for person in people:
if person.died():
people.remove(person)
+
+ for garbage in trash:
+ if garbage.died():
+ trash.remove(garbage)
# update objects
for person in people:
person.update()
-
+ for garbage in trash:
+ garbage.update()
+
robot.update()
# draw the background first, because it will cover all the screen
screen.blit(object_background, (0,0))
# draw everything else over the background
+
# Score
screen.blit(text, (0, 0))
# Persons
for person in people:
person.draw(screen)
+ for garbage in trash:
+ garbage.draw(screen)
#Robot
robot.draw(screen)
+ # Alert when touching person
+ for person in people:
+ if robot.collides_with(person):
+ robot.draw(screen)
+ robot.draw_alert(screen)
+ #score -= 1
+
+
+
+
# Add score if you pick garbage
#if position_garbage == position_robot:
# score = score + 1
diff --git a/person.py b/person.py
index 4243677..693176a 100644
--- a/person.py
+++ b/person.py
@@ -17,7 +17,8 @@ class Person:
image_rect.width - size_reduction, \
image_rect.height - size_reduction)
- self.position = [ 0, randint(0, screen_h -1)]
+ #self.position = [ 0, randint(0, screen_h -1)]
+ self.position = [ 0, randint(75, screen_h - 75)]
self.screen_h = screen_h
self.screen_w = screen_w
diff --git a/robot.py b/robot.py
index c47b2a2..b0ede03 100644
--- a/robot.py
+++ b/robot.py
@@ -5,8 +5,9 @@ class Robot:
self.unit = unit
self.speed = robot_speed
self.image = pygame.image.load("images/robot_1.png")
+ self.alert_image = pygame.image.load("images/atention.png")
image_rect = self.image.get_rect()
- size_reduction = 20*unit
+ size_reduction = 15*unit
self.collision_rect = pygame.Rect(image_rect.left + size_reduction, \
image_rect.top + size_reduction, \
image_rect.width - size_reduction, \
@@ -45,5 +46,8 @@ class Robot:
def draw(self, on_surface):
on_surface.blit(self.image, self.position)
+ def draw_alert(self, on_surface):
+ on_surface.blit(self.alert_image, self.position)
+
def get_absolute_rect(self):
return self.collision_rect.move(self.position)