Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/robot.py
diff options
context:
space:
mode:
Diffstat (limited to 'robot.py')
-rw-r--r--robot.py17
1 files changed, 14 insertions, 3 deletions
diff --git a/robot.py b/robot.py
index 15938b1..c47b2a2 100644
--- a/robot.py
+++ b/robot.py
@@ -1,11 +1,16 @@
import pygame
class Robot:
- def __init__(self, screen_w, screen_h, unit, speed):
+ def __init__(self, screen_w, screen_h, unit, robot_speed):
self.unit = unit
- self.speed = speed
+ self.speed = robot_speed
self.image = pygame.image.load("images/robot_1.png")
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.position = [0, 0]
self.screen_w = screen_w
self.screen_h = screen_h
@@ -33,6 +38,12 @@ class Robot:
# Move the character around the screen
self.position = ((self.position[0] + self.direction_x * self.speed * self.unit + image_center)%self.screen_w - image_center), \
((self.position[1] + self.direction_y * self.speed * self.unit + image_center)%self.screen_h - image_center)
-
+
+ def collides_with(self, other):
+ return self.get_absolute_rect().colliderect(other.get_absolute_rect())
+
def draw(self, on_surface):
on_surface.blit(self.image, self.position)
+
+ def get_absolute_rect(self):
+ return self.collision_rect.move(self.position)