Changeset 490:0eade58a71b9


Ignore:
Timestamp:
04/09/11 20:28:03 (12 years ago)
Author:
Simon Cross <hodgestar@…>
Branch:
default
Phase:
public
Rebase:
36346664646663623733373762383966616363323266623236633065326137393036323661323332
Message:

Support item dropping (specifically tails). Have monk drop tail.

Location:
skaapsteker
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • skaapsteker/dialogue.py

    r483 r490  
    22
    33from . import data
    4 from .engine import OpenDialog
     4from .engine import OpenDialog, AddSpriteEvent
    55
    66
     
    4040        OpenDialog.post(npc_name)
    4141
    42     def _drop_item(self, item):
     42    def _drop_item(self, item, shift=(1, 0)):
    4343        """Create a tail of the given type."""
    4444        print "Dropping", item
    45         self.world.get_item(item, to_level=self._me.level)
     45        to_level = self._me.level
     46        to_pos = self._me.pos
     47        to_pos = to_pos[0] + shift[0], to_pos[1] + shift[1]
     48        gamestate = self.world.gamestate()
     49        sprite = gamestate.create_item_sprite(item, to_level=to_level, to_pos=to_pos)
     50        AddSpriteEvent.post(sprite)
    4651
    4752    def event(self, ev):
  • skaapsteker/gamestate.py

    r483 r490  
    88class StateProxy(object):
    99
    10     def __init__(self, data):
     10    def __init__(self, data, gamestate):
    1111        self.__dict__['_data'] = data # should be a dict
     12        self.__dict__['_gamestate'] = gamestate # use sparingly
    1213
    1314    def __getattr__(self, key):
     
    1718            raise AttributeError
    1819        if isinstance(value, dict):
    19             return StateProxy(value)
     20            return StateProxy(value, None) # surprise people
    2021        else:
    2122            return value
     
    3233    def copy(self):
    3334        return self._data.copy()
     35
     36    def gamestate(self):
     37        return self._gamestate
    3438
    3539
     
    4852        raw_data = open(game_file, "rb").read()
    4953        self.data = json.loads(raw_data, encoding='utf-8')
    50         self.world = StateProxy(self.data)
     54        self.world = StateProxy(self.data, self)
    5155
    5256    def new_game(self):
     
    8286        return sprites
    8387
     88    def create_item_sprite(self, item, to_level=None, to_pos=None):
     89        itemdef = self.data['items'].get(item)
    8490
     91        if to_level is not None:
     92            itemdef['level'] = to_level
     93        if to_pos is not None:
     94            itemdef['pos'] = to_pos
     95
     96        sprite_dict = itemdef.copy()
     97        sprite_dict.pop('level')
     98        sprite_dict['name'] = item
     99        sprite_dict['world'] = self.world
     100        return find_sprite(sprite_dict, 'items')
  • skaapsteker/sprites/items.py

    r489 r490  
    238238class Tail(Item):
    239239
     240    image_dir = 'icons/tails/'
    240241    image_file = None
    241242    tail_type = None
     
    249250
    250251class ShapeshiftTail(Tail):
    251     image_file = 'icons/tails/shapeshifted.png'
     252    image_file = 'shapeshift.png'
    252253    tail_type = 'shapeshift'
    253254    help_msg = "Shapeshifting tail. Press C to shape shift." \
     
    256257
    257258class FireballTail(Tail):
    258     image_file = 'icons/tails/fireball.png'
     259    image_file = 'fireball.png'
    259260    tail_type = 'fireball'
    260261    help_msg = "Fireball tail. The X attack key now shoots fireballs."
     
    262263
    263264class SprintTail(Tail):
    264     image_file = 'icons/tails/sprint.png'
     265    image_file = 'sprint.png'
    265266    tail_type = 'sprint'
    266267    help_msg = "Sprint tail. Double-tap the left or right arrow key to" \
     
    269270
    270271class InvisibilityTail(Tail):
    271     image_file = 'icons/tails/invisibility.png'
     272    image_file = 'invisibility.png'
    272273    tail_type = 'invisibility'
    273274    help_msg = "Invisibility tail. Press V to become invisible for a few seconds." \
     
    276277
    277278class FlightTail(Tail):
    278     image_file = 'icons/tails/flight.png'
     279    image_file = 'flight.png'
    279280    tail_type = 'flight'
    280281    help_msg = "Flight tail. Double-tap up to fly. Press down while on the ground to land." \
     
    283284
    284285class ShieldTail(Tail):
    285     image_file = 'icons/tails/shield.png'
     286    image_file = 'shield.png'
    286287    tail_type = 'shield'
    287288    help_msg = "Shield tail. If you get hit, your mystical shield will protect you for" \
     
    290291
    291292class StealTail(Tail):
    292     image_file = 'icons/tails/steal.png'
     293    image_file = 'steal.png'
    293294    tail_type = 'steal'
    294295    help_msg = "Life-stealing tail. If you projectiles hit your enemies, you steal some" \
     
    297298
    298299class LightningTail(Tail):
    299     image_file = 'icons/tails/lightning.png'
     300    image_file = 'lightning.png'
    300301    tail_type = 'lightning'
    301302    help_msg = "Lightning tail. The Z attack now shoots lightning bolts."
  • skaapsteker/sprites/player.py

    r473 r490  
    520520        if my_item is None:
    521521            return None
    522         world_item = getattr(self.the_world.items, my_item)
     522
    523523        if set_level:
    524             world_item.level = self._me.level
    525             world_item.pos = self.get_tile_pos()
    526         sprite_dict = world_item.copy()
    527         sprite_dict.pop('level')
    528         sprite_dict['name'] = my_item
    529         sprite_dict['world'] = self.the_world
    530         return find_sprite(sprite_dict, 'items')
     524            to_level = self._me.level
     525            to_pos = self._me.get_tile_pos()
     526        else:
     527            to_level, to_pos = None, None
     528
     529        return self.the_world.create_item_sprite(
     530            my_item, to_level=to_level, to_pos=to_pos)
    531531
    532532
Note: See TracChangeset for help on using the changeset viewer.