Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/Gambiarra/objects/wall.py
diff options
context:
space:
mode:
authorLuiz Irber <luiz.irber@gmail.com>2008-04-09 00:48:07 (GMT)
committer Luiz Irber <luiz.irber@gmail.com>2008-04-09 00:48:07 (GMT)
commiteac28ed9766fa39d8be99c46b2c7e285172d4f13 (patch)
treea7ed107a678a114b5e750eea9520cd24e911bac8 /Gambiarra/objects/wall.py
parent6a917f6cbbd8d6ac34320477d5363c8e9f708437 (diff)
Refactoring of check_collision done
- Now the Thing class has a new method, collide(self, obj), and the collision treatment is done there. - Penguin still need to have this method overrided!
Diffstat (limited to 'Gambiarra/objects/wall.py')
-rw-r--r--Gambiarra/objects/wall.py36
1 files changed, 35 insertions, 1 deletions
diff --git a/Gambiarra/objects/wall.py b/Gambiarra/objects/wall.py
index 3ec40cc..4a1b32d 100644
--- a/Gambiarra/objects/wall.py
+++ b/Gambiarra/objects/wall.py
@@ -30,7 +30,16 @@ class LeftWall(Thing):
super(LeftWall, self).__init__(
pygame.image.load(abspath("../data/images/leftwall.png")),
editable, None,
- initialPosition, elasticity = 100, mobility = False, gravity = 10)
+ initialPosition, elasticity = 100, mobility = False,
+ gravity = 10)
+
+ def collide(self, obj):
+ if obj.rect.colliderect(self.rect):
+ if obj.rect.left <= self.rect.right:
+ obj.rect.left = self.rect.right + 5
+ obj.speed[0] *= -0.95*obj.elasticity/100
+ return True
+ return False
class RightWall(Thing):
def __init__(self, initialPosition = [1185,0], editable=False):
@@ -39,6 +48,14 @@ class RightWall(Thing):
editable, None,
initialPosition, elasticity = 100, mobility = False, gravity = 10)
+ def collide(self, obj):
+ if obj.rect.colliderect(self.rect):
+ if obj.rect.right >= self.rect.left:
+ obj.rect.right = self.rect.left - 5
+ obj.speed[0] *= -0.95*obj.elasticity/100
+ return True
+ return False
+
class UpWall(Thing):
def __init__(self, initialPosition = [15,0], editable=False):
super(UpWall, self).__init__(
@@ -47,6 +64,14 @@ class UpWall(Thing):
initialPosition, elasticity = 100, mobility = False,
gravity = 10)
+ def collide(self, obj):
+ if obj.rect.colliderect(self.rect):
+ if obj.rect.top <= self.rect.bottom:
+ obj.rect.top = self.rect.bottom + 5
+ obj.speed[1] *= -0.95*obj.elasticity/100
+ return True
+ return False
+
class DownWall(Thing):
def __init__(self, initialPosition = [15,755], editable=False):
super(DownWall, self).__init__(
@@ -54,3 +79,12 @@ class DownWall(Thing):
editable, None,
initialPosition, elasticity = 100, mobility = False,
gravity = 10)
+
+ def collide(self, obj):
+ if obj.rect.colliderect(self.rect):
+ if obj.rect.bottom > self.rect.top:
+ obj.rect.bottom = self.rect.top - 5
+ obj.speed[1] *= -0.75*obj.elasticity/100
+ return True
+ return False
+