Changeset 290:c68f2f3efc7f


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

Item dropping and swapping.

Location:
skaapsteker
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • skaapsteker/engine.py

    r264 r290  
    152152           """
    153153        super(GlobalNpcEvent, cls).post(ev=ev)
     154
     155
     156class ItemRepopulationEvent(UserEvent): # TODO: Needed?
     157
     158    utype = "ITEM_REPOPULATION_EVENT"
     159
     160    @classmethod
     161    def post(cls, item):
     162        """Put a Sprite back in the world.
     163           """
     164        super(ItemRepopulationEvent, cls).post(item=item)
  • skaapsteker/levelscene.py

    r288 r290  
    5353
    5454        # Double tap stuff
    55         self._last_keys_down = []
    5655        self._last_keydown_time = None
    5756        self._last_keyup_time = None
     
    6766            K_RIGHT: action('right'),
    6867            K_UP: action('up'),
    69             K_DOWN: action('down'),
    7068        }
    7169        self._fast_keys_down = set()
    7270
    7371        self._slow_key_map = {
     72            K_DOWN: action('down'),
    7473            K_ESCAPE: self._quit,
    7574            K_p: self._toggle_pause,
     
    8685                (K_LEFT, K_LEFT) : action('double_left'),
    8786                (K_RIGHT, K_RIGHT) : action('double_right'),
    88                 (K_DOWN, K_DOWN) : action('double_down'),
     87                (K_UP, K_UP) : action('double_up'),
    8988                }
    9089
     
    241240        elif engine.CloseDialog.matches(ev):
    242241            self._close_dialogue()
     242        elif engine.ItemRepopulationEvent.matches(ev):
     243            self._world.add(ev.item)
  • skaapsteker/sprites/player.py

    r284 r290  
    44import time
    55
    6 from ..sprites.base import TILE_SIZE, PC_LAYER, MONSTER_LAYER
     6from ..sprites.base import find_sprite, TILE_SIZE, PC_LAYER, MONSTER_LAYER
    77from ..physics import Sprite
    88from ..constants import Layers
    99from ..data import get_files, load_image
    10 from ..engine import PlayerDied
     10from ..engine import PlayerDied, ItemRepopulationEvent
    1111
    1212
     
    201201        self._sprint_start_time = time.time()
    202202
    203     def action_double_down(self):
    204         print 'double down tap'
    205 
    206203    def action_double_right(self):
    207204        if self.sprinting > 0:
     
    209206        self.sprinting =  2
    210207        self._sprint_start_time = time.time()
     208
     209    def action_double_up(self):
     210        pass
    211211
    212212    def action_right(self):
     
    228228    def action_down(self):
    229229        print self._touching_actionables
    230         for actionable in self._touching_actionables[:1]:
    231             actionable.player_action(self)
     230        if self._touching_actionables:
     231            self._touching_actionables[0].player_action(self)
     232        elif self.the_world.fox.item is not None:
     233            self.drop_item()
    232234
    233235
     
    292294
    293295
     296    def drop_item(self):
     297        my_item = self.the_world.fox.item
     298        if my_item is None:
     299            return
     300        self.the_world.fox.item = None
     301        world_item = getattr(self.the_world.items, my_item)
     302        world_item.level = self.the_world.fox.level
     303        world_item.pos = [a/b for a, b in zip(self.rect.center, TILE_SIZE)]
     304        sprite_dict = world_item.copy()
     305        sprite_dict.pop('level')
     306        sprite_dict['name'] = my_item
     307        sprite_dict['world'] = self.the_world
     308        ItemRepopulationEvent.post(find_sprite(sprite_dict, 'items'))
     309
     310
    294311    def take_item(self, item):
    295         my_item = self.the_world.fox.item
    296         if my_item is not None:
    297             print "I already have", my_item
    298             return
     312        self.drop_item()
    299313        getattr(self.the_world.items, item.name).level = "_limbo"
    300314        self.the_world.fox.item = item.name
Note: See TracChangeset for help on using the changeset viewer.