Changeset 273:95e2ef31e714


Ignore:
Timestamp:
04/08/11 17:09:09 (12 years ago)
Author:
Jeremy Thurgood <firxen@…>
Branch:
default
Phase:
public
Message:

Hit "down" to interact with things.

Files:
5 edited

Legend:

Unmodified
Added
Removed
  • data/levels/temple.json

    r264 r273  
    3030    ],
    3131    "doorways": {
    32         "starting": {"type": "StartingDoorway", "pos": [4, 17], "facing": "right"},
     32        "starting": {"type": "StartingDoorway", "pos": [4, 16], "facing": "right"},
    3333        "to_level2": {"type": "Doorway", "pos": [17, 16], "facing": "left", "leadsto": "level2.to_temple"}
    3434    }
  • skaapsteker/levelscene.py

    r270 r273  
    4343
    4444        self._build_action_map()
     45        self._key_sequence = []
    4546
    4647    def setup_player(self):
     
    181182            self._key_sequence = []
    182183            return False
    183 
    184         print ev
    185184
    186185        if ev.type is KEYUP:
  • skaapsteker/physics.py

    r271 r273  
    175175        self._gravitators = pygame.sprite.Group()
    176176        self._updaters = pygame.sprite.Group()
     177        self._actionables = pygame.sprite.Group()
     178        self._actors = pygame.sprite.Group()
    177179        self._collision_groups = { None: pygame.sprite.Group() }
    178180        self._last_time = None
     
    200202            self._updaters.add(sprite)
    201203            sprite.collision_group = self._collision_groups[sprite.collision_layer]
     204        if getattr(sprite, 'player_action', None) is not None:
     205            self._actionables.add(sprite)
     206        if getattr(sprite, 'add_actionable', None) is not None:
     207            self._actors.add(sprite)
    202208
    203209    def _add_collision_group(self, layer):
     
    288294        self._updaters.update()
    289295
     296        # Action stuff.
     297        # Happens after updates, because we only want it for the next frame.
     298        for sprite in self._actors:
     299            for other in self._actionables:
     300                if sprite.collide_rect.colliderect(other.collide_rect):
     301                    sprite.add_actionable(other)
     302
     303
    290304    def draw(self, surface):
    291305        self._all.draw(surface)
  • skaapsteker/sprites/base.py

    r271 r273  
    193193
    194194    collision_layer = NPC_LAYER
    195     collides_with = set([PC_LAYER])
    196195
    197196    debug_color = (240, 240, 240)
     
    199198
    200199    block = False
     200    actionable = True
    201201
    202202    def __init__(self, pos, **opts):
    203203        AnimatedGameSprite.__init__(self, pos, **opts)
    204204        self._layer = Layers.PLAYER
    205         self._ticks_before_interact = 0
    206205
    207206    def setup(self, name, world, dsm, state):
    208207        self.dsm = dialogue.DSM(name, world, dsm, state)
    209208
    210     def collided_player(self, player):
    211         if self._ticks_before_interact == 0:
    212             self._ticks_before_interact = 120
    213             OpenDialog.post(self)
    214 
    215     def update(self):
    216         super(NPC, self).update()
    217         if self._ticks_before_interact > 0:
    218             self._ticks_before_interact -= 1
     209    def player_action(self, player):
     210        OpenDialog.post(self)
    219211
    220212
     
    227219    gravitates = False
    228220
    229     collision_layer = MONSTER_LAYER
    230     collides_with = set([PC_LAYER])
     221    collision_layer = NPC_LAYER
    231222
    232223    portable = True
     224    actionable = True
    233225
    234226    def __init__(self, pos, **opts):
     
    248240
    249241
    250     def collided_player(self, player):
     242    def player_action(self, player):
    251243        print "Player touched %s" % self
    252244        player.take_item(self)
     
    259251    collides_with = set([PC_LAYER, MONSTER_LAYER, NPC_LAYER])
    260252    is_ground = True
     253    actionable = False
    261254    bounce_factor = (0.0, 0.0)
    262255
     
    283276    mobile = False
    284277    gravitates = False
    285     collides_with = set([PC_LAYER])
    286     wants_updates = True
    287278
    288279    blocks = False
     280    actionable = True
    289281
    290282    image_file = 'torii.png'
    291 
    292     debug_color = (120, 240, 120)
    293 
    294     def __init__(self, pos, **opts):
    295         GameSprite.__init__(self, pos, **opts)
    296         self._ticks_before_interact = 120
    297283
    298284
     
    310296
    311297
    312     def update(self):
    313         super(Doorway, self).update()
    314         if self._ticks_before_interact > 0:
    315             self._ticks_before_interact -= 1
    316 
    317 
    318     def collided_player(self, player):
    319         if self._ticks_before_interact != 0:
    320             return
    321         self._ticks_before_interact = 120
     298    def player_action(self, player):
    322299        print "Player touched %s" % self
    323300        from .. import engine, levelscene
     
    327304
    328305class StartingDoorway(Doorway):
    329     collides_with = set()
     306    actionable = False
    330307
    331308    def setup_image_data(self, pos):
     
    337314    def setup(self, facing):
    338315        Doorway.setup(self, facing, None)
    339 
    340 
    341     def collided_player(self, player):
    342         print "Player touched %s" % self
    343         from .. import engine, levelscene
    344         engine.ChangeScene.post((levelscene.LevelScene, self.leadsto))
    345316
    346317
  • skaapsteker/sprites/player.py

    r272 r273  
    7272
    7373    def update(self):
     74        self._touching_actionables = []
    7475        v_x, v_y = self.velocity
    7576        # Never animate slower than !7 fps, never faster than ~15 fps
     
    226227
    227228    def action_down(self):
    228         self.deltav((0.0, 100.0))
     229        print self._touching_actionables
     230        for actionable in self._touching_actionables[:1]:
     231            actionable.player_action(self)
     232
    229233
    230234    def action_fire1(self):
     
    297301        item.kill()
    298302        print "took", item
     303
     304
     305    def add_actionable(self, actionable):
     306        self._touching_actionables.append(actionable)
Note: See TracChangeset for help on using the changeset viewer.