changeset 460:8b9b4706a4d6

Blocking NPC's block
author Neil Muller <drnlmuller@gmail.com>
date Sat, 09 Apr 2011 20:09:58 +0200
parents 6e065efdcec6
children c6d1165bb16f
files data/game.json skaapsteker/physics.py skaapsteker/sprites/base.py skaapsteker/sprites/npcs.py
diffstat 4 files changed, 19 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/data/game.json	Sat Apr 09 20:50:01 2011 +0200
+++ b/data/game.json	Sat Apr 09 20:09:58 2011 +0200
@@ -157,7 +157,7 @@
     },
     "npcs": {
         "monk": { "type": "Monk", "level": "temple", "pos": [15, 16], "dsm": "npcs/monk.json", "state": "start" },
-        "guard": { "type": "Guard", "level": "temple_grounds", "pos": [5, 11], "dsm": "npcs/guard.json", "state": "start" },
+        "guard": { "type": "Guard", "level": "temple_grounds", "pos": [5, 11], "dsm": "npcs/guard.json", "state": "start", "block": true },
         "hattori": { "type": "Hattori", "level": "road", "pos": [36, 8], "dsm": "npcs/hattori.json", "state": "start" },
         "ichiro": { "type": "Ichiro", "level": "road", "pos": [37, 8], "dsm": "npcs/ichiro.json", "state": "start" },
         "sasuke": { "type": "Sasuke", "level": "road", "pos": [56, 8], "dsm": "npcs/sasuke.json", "state": "start" },
--- a/skaapsteker/physics.py	Sat Apr 09 20:50:01 2011 +0200
+++ b/skaapsteker/physics.py	Sat Apr 09 20:09:58 2011 +0200
@@ -313,8 +313,10 @@
         # Action stuff.
         # Happens after updates, because we only want it for the next frame.
         for sprite in self._actors:
+            actor_collide_rect = sprite.collide_rect.inflate((4, 4))
             for other in self._actionables:
-                if sprite.collide_rect.colliderect(other.collide_rect):
+                other_actor_collide_rect = other.collide_rect.inflate((4, 4))
+                if actor_collide_rect.colliderect(other_actor_collide_rect):
                     sprite.add_actionable(other)
 
 
--- a/skaapsteker/sprites/base.py	Sat Apr 09 20:50:01 2011 +0200
+++ b/skaapsteker/sprites/base.py	Sat Apr 09 20:09:58 2011 +0200
@@ -281,6 +281,18 @@
         OpenDialog.post(self)
 
 
+class BlockingNPC(NPC):
+
+    collides_with = set([PC_LAYER])
+    mobile = False
+    block = True
+
+    def setup(self, name, world, dsm, state, block):
+        NPC.setup(self, name, world, dsm, state)
+        self.block = block
+        self._animation = 'standing'
+
+
 class Projectile(AnimatedGameSprite):
 
     collision_layer = PROJECTILE_LAYER
--- a/skaapsteker/sprites/npcs.py	Sat Apr 09 20:50:01 2011 +0200
+++ b/skaapsteker/sprites/npcs.py	Sat Apr 09 20:09:58 2011 +0200
@@ -1,4 +1,4 @@
-from .base import NPC
+from .base import NPC, BlockingNPC
 
 
 class Monk(NPC):
@@ -8,10 +8,11 @@
     ]
 
 
-class Guard(NPC):
+class Guard(BlockingNPC):
     image_dir = 'sprites/guard'
 
 
+
 class Hattori(NPC):
     image_dir = 'sprites/hattori'