Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/person.py
blob: 3edd1781a6dba5476fe7e64c3b9911cf5bf6cf22 (plain)
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
import pygame
from random import randint


person_number = 4
persons = ["images/person_%02d.png" % person_number for person_number in xrange(1, person_number + 1) ]

class Person:
	def __init__(self, screen_w, screen_h, unit, speed):
		self.unit = unit
		self.speed = speed
		self.image = pygame.image.load(persons[randint(0, person_number - 1)])
		self.image_rect = self.image.get_rect()
		size_reduction = 20*unit
		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)]
		self.screen_h = screen_h
		self.screen_w = screen_w

	def update(self):
		image_center = self.image.get_width()/2
		# Move the person 
		self.position = [ (self.position[0] + self.speed ), self.position[1] ]
  
	def draw(self, on_surface):
		on_surface.blit(self.image, self.position)
		
	def died(self):
		return self.position[0] > self.screen_w

	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)