Mercurial > skaapsteker
diff skaapsteker/sprites/base.py @ 362:02bf05964619
FIREBALLS!
author | Simon Cross <hodgestar@gmail.com> |
---|---|
date | Sat, 09 Apr 2011 14:25:45 +0200 |
parents | 5bdb4677510a |
children | 249ba3bd6904 04b7d8724add |
line wrap: on
line diff
--- a/skaapsteker/sprites/base.py Sat Apr 09 14:22:04 2011 +0200 +++ b/skaapsteker/sprites/base.py Sat Apr 09 14:25:45 2011 +0200 @@ -19,7 +19,7 @@ PC_LAYER = 0 MONSTER_LAYER = 1 NPC_LAYER = 2 - +PROJECTILE_LAYER = 3 class GameSprite(Sprite): @@ -141,7 +141,7 @@ class Monster(AnimatedGameSprite): collision_layer = MONSTER_LAYER - collides_with = set([PC_LAYER]) + collides_with = set([PC_LAYER, PROJECTILE_LAYER]) debug_color = (240, 120, 120) @@ -207,6 +207,7 @@ class NPC(AnimatedGameSprite): collision_layer = NPC_LAYER + collides_with = set([]) debug_color = (240, 240, 240) bounce_factor = (0, 0) # NPC's don't bounce by default @@ -227,8 +228,30 @@ class Projectile(AnimatedGameSprite): + + collision_layer = PROJECTILE_LAYER + collides_with = set() + gravitates = False + DAMAGE = 10 + + def setup(self, hits): + if isinstance(hits, tuple): + self.hits = hits + (Geography,) + else: + self.hits = (hits, Geography) + + def explode(self): + self.kill() + + def collided(self, other): + if not isinstance(other, self.hits): + return + if hasattr(other, 'damage'): + other.damage(self.DAMAGE) + self.explode() + class Item(GameSprite): mobile = False @@ -263,7 +286,7 @@ class Geography(Sprite): mobile = False gravitates = False - collides_with = set([PC_LAYER, MONSTER_LAYER, NPC_LAYER]) + collides_with = set([PC_LAYER, MONSTER_LAYER, NPC_LAYER, PROJECTILE_LAYER]) is_ground = True actionable = False bounce_factor = (0.0, 0.0)