Exemple #1
0
    def do_update(self):
        player = entity_system.find_one("PlayerComponent")

        # setup the widgets
        do_button = Button()
        do_progress_bar = ProgressBar()
        do_label = Label()
        
        # Hit Points
        do_label(self, (10, 10), 'HP')
        cur_hp = player.get('UnitComponent', 'cur_hp') * 1.0 
        max_hp = player.get('UnitComponent', 'max_hp')
        do_progress_bar(self, (10, 30), (230, 22), cur_hp / max_hp)
        
        # Action Cards
        do_label(self, (10, 70), 'Action Cards')
        ctr = 0
        deck = player.get('UnitComponent', 'deck')
        for card in deck.hand:
            top = 90 + (30 * ctr)
            id = "card_button_%s" % ctr
            
            if do_button(self, id, (10, top), (230, 22), card.name):
                inject_user_event('action_card', card_num=ctr)
            
            ctr += 1
Exemple #2
0
    def on_move_player(self, data):
        delta = data.get("delta", None)

        if delta is None:
            return

        # get the requested position
        player = entity_system.find_one("PlayerComponent")
        x, y = player.get("RenderComponent", "pos")
        dx, dy = delta
        pos = (x + dx, y + dy)

        # if the new spot isn't passible, ignore the command
        if not self.map.get(pos).passible:
            return

        # if the new spot is occupied, ignore the command
        blocker = entity_system.find_one("NpcComponent", {"RenderComponent#pos": pos})
        if blocker is not None:
            return

        player.set("RenderComponent", "pos", pos)
        fov_radius = player.get("UnitComponent", "fov_radius")
        self.map.get_fov_tiles(pos, fov_radius).seen = True
        inject_user_event("end_turn")
Exemple #3
0
    def on_select_target(self, data):
        if self.target is not None:
            self.target.remove_component("TargetComponent")

        self.target = data.get("target", None)

        if self.target is not None:
            self.target.add_component(TargetComponent())

        inject_user_event("map_changed")
Exemple #4
0
    def on_select_target(self, data):
        if self.target is not None:
            self.target.remove_component('TargetComponent')

        self.target = data.get('target', None)

        if self.target is not None:
            self.target.add_component(TargetComponent())

        inject_user_event('map_changed')
Exemple #5
0
 def on_mouse_up(self, data):
     sprite = data.get('sprite', None)
     if sprite is not self:
         return
     
     pos = data.get('pos', None)
     array_pos = self.camera.to_array(pos)
     
     # if there is an entity under the cursor, it needs to be targeted
     entity = entity_system.find_one('RenderComponent', conditions={'RenderComponent#pos': array_pos})
     if entity:
         inject_user_event('select_target', target=entity)
Exemple #6
0
    def on_action_card(self, data):
        index = data.get('card_num', None)
        if index is None:
            return

        # get the card from the player's hand
        player = entity_system.find_one('PlayerComponent')
        deck = player.get('UnitComponent', 'deck')
        card = deck.hand[index]

        # general data passed into all commands
        data = {
            'controller': self,
            'map': self.map,
            'source': player,
            'target': self.target,
        }

        # generate the card commands
        commands = []
        for name, kwargs in card.commands.items():
            # add any properties from the card definition to the general data
            card_data = data.copy()
            if kwargs is not None:
                card_data.update(kwargs)

            command = command_mapping[name](**card_data)
            commands.append(command)

        # make sure all the card commands are valid
        valid = True
        for command in commands:
            # if the command is not valid, notify the user of it and stop processing the card
            if not command.is_valid():
                valid = False
                inject_user_event('show_notification', text=command.msg)
                return

        # execute the card
        for command in commands:
            print "Command: %s" % command
            command.execute()

        # discard the card
        deck.discard(card)

        # note that we finished an action
        self.actions -= 1

        # if we have no more actions, or no more cards in our hand, end the turn
        if self.actions <= 0 or len(deck.hand) == 0:
            inject_user_event('end_turn')
Exemple #7
0
    def fill_hand(self):
        while len(self.hand) < self.hand_size:
            # if there are no cards in the good, reset
            if len(self.cards) == 0:
                self.reset_deck() 

            # add the next card to the hand
            if len(self.cards) > 0:
                self.hand.append(self.cards.pop())
            else:
                break

        inject_user_event('deck_changed')
Exemple #8
0
    def on_keyup(self, data):
        key = data.get('key', 0)

        if key in [K_UP, K_w]:
            inject_user_event('move_player', delta=(0, -1))

        if key in [K_DOWN, K_s]:
            inject_user_event('move_player', delta=(0, 1))

        if key in [K_LEFT, K_a]:
            inject_user_event('move_player', delta=(-1, 0))

        if key in [K_RIGHT, K_d]:
            inject_user_event('move_player', delta=(1, 0))
Exemple #9
0
    def on_end_turn(self, data):
        # reset the action count
        self.actions = 1

        # clear the target component, if necessary
        if self.target is not None:
            self.target.remove_component("TargetComponent")
            self.target = None

        # check for killed npcs
        for npc in entity_system.find("NpcComponent"):
            if npc.get("UnitComponent", "cur_hp") > 0:
                continue

            inject_user_event("npc_killed", npc=npc)
            entity_system.remove(npc)

        # recharge any npc hitpoints
        for npc in entity_system.find("NpcComponent"):
            npc.get_component("UnitComponent").do_hp_recharge()

        # send an event on player death
        player = entity_system.find_one("PlayerComponent")
        if player.get("UnitComponent", "cur_hp") < 0:
            inject_user_event("player_killed")

        # recharge the player's heath
        player = entity_system.find_one("PlayerComponent")
        player.get_component("UnitComponent").do_hp_recharge()

        # refill the player's hand
        player.get("UnitComponent", "deck").fill_hand()

        inject_user_event("map_changed")
Exemple #10
0
 def reset_deck(self):
     self.cards.extend(self.pile)
     self.pile = []
     self.shuffle()
     inject_user_event('deck_changed')
Exemple #11
0
 def add_card(self, card):
     inject_user_event('add_card', card=card)
     self.cards.append(card)