Ignore:
Timestamp:
09/06/13 10:22:02 (8 years ago)
Author:
Jeremy Thurgood <firxen@…>
Branch:
default
Phase:
public
Message:

Better key handling, form change delay.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • nagslang/screens/area.py

    r333 r336  
    77from nagslang.constants import (
    88    COLLISION_TYPE_WALL, COLLISION_TYPE_PLAYER, CALLBACK_COLLIDERS,
    9     COLLISION_TYPE_FURNITURE, COLLISION_TYPE_WEREWOLF_ATTACK)
     9    COLLISION_TYPE_FURNITURE, COLLISION_TYPE_WEREWOLF_ATTACK,
     10    CMD_TOGGLE_FORM, CMD_ATTACK, CMD_ACTION)
    1011from nagslang.enemies import DeadEnemy
    1112from nagslang.events import (
     
    2526    }
    2627
     28    command_keys = {
     29        pygame.locals.K_c: CMD_TOGGLE_FORM,
     30        pygame.locals.K_z: CMD_ATTACK,
     31        pygame.locals.K_LCTRL: CMD_ATTACK,
     32        pygame.locals.K_SPACE: CMD_ACTION,
     33    }
     34
    2735    def __init__(self):
    2836        self.keys_down = set()
     
    4755                dy += ty
    4856        return (dx, dy)
     57
     58    def get_command_key(self, key):
     59        return self.command_keys.get(key, None)
    4960
    5061
     
    152163            if ev.key == pygame.locals.K_ESCAPE:
    153164                ScreenChange.post('menu')
    154             if ev.key == pygame.locals.K_c:
    155                 self.protagonist.toggle_form()
    156                 self.world.transformations += 1
    157             if ev.key in (pygame.locals.K_z, pygame.locals.K_LCTRL):
    158                 self.world.attacks += 1
    159                 self.protagonist.attack()
    160             if ev.key == pygame.locals.K_SPACE:
    161                 self.protagonist.perform_action()
     165            cmd_key = self.keys.get_command_key(ev.key)
     166            if cmd_key is not None:
     167                self.protagonist.handle_keypress(cmd_key)
    162168        elif DoorEvent.matches(ev):
    163169            self.protagonist.set_position(ev.dest_pos)
Note: See TracChangeset for help on using the changeset viewer.