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/protagonist.py

    r335 r336  
    66    COLLISION_TYPE_PLAYER, ZORDER_MID, WEREWOLF_SOAK_FACTOR,
    77    PROTAGONIST_HEALTH_MIN_LEVEL, PROTAGONIST_HEALTH_MAX_LEVEL,
    8     NON_GAME_OBJECT_COLLIDERS, BULLET_DAMAGE, CLAW_DAMAGE)
     8    NON_GAME_OBJECT_COLLIDERS, BULLET_DAMAGE, CLAW_DAMAGE,
     9    CMD_TOGGLE_FORM, CMD_ATTACK, CMD_ACTION)
    910from nagslang.events import FireEvent, ClawEvent
    1011from nagslang.game_object import GameObject, Physicser, make_body
     
    4546    WOLF_FORM = 'wolf'
    4647
     48    CHANGING_SEQUENCE = {
     49        # The key is the form we're changing *from*.
     50        HUMAN_FORM: (
     51            WOLF_FORM, HUMAN_FORM, HUMAN_FORM,
     52            WOLF_FORM, HUMAN_FORM, WOLF_FORM,
     53            HUMAN_FORM, WOLF_FORM, HUMAN_FORM,
     54            WOLF_FORM, HUMAN_FORM, WOLF_FORM,
     55            HUMAN_FORM, WOLF_FORM, WOLF_FORM,
     56        ),
     57        WOLF_FORM: (
     58            HUMAN_FORM, WOLF_FORM, WOLF_FORM,
     59            HUMAN_FORM, WOLF_FORM, HUMAN_FORM,
     60            WOLF_FORM, HUMAN_FORM, WOLF_FORM,
     61            HUMAN_FORM, WOLF_FORM, HUMAN_FORM,
     62            WOLF_FORM, HUMAN_FORM, HUMAN_FORM,
     63        ),
     64    }
     65
     66    zorder = ZORDER_MID
     67
    4768    def __init__(self, space, world, position):
    48         physicser = self._make_physics(space, position)
    49         renderer = self._make_renderer()
     69        self.form = self.HUMAN_FORM
     70        super(Protagonist, self).__init__(
     71            self._make_physics(space, position), self._make_renderer())
     72        self.world = world
    5073        self.inventory = {}
    51         self.form = self.HUMAN_FORM
     74        self.health_level = 100
     75
    5276        self.angle = 0
    5377        self.is_moving = False
    54         self.world = world
    55 
    56         super(Protagonist, self).__init__(physicser, renderer)
    57         self.zorder = ZORDER_MID
    58 
    59         self.health_level = 100
     78        self.changing_sequence = []
    6079
    6180        self.go_human()
     
    166185        return obj
    167186
     187    def handle_keypress(self, key_command):
     188        if self.changing_sequence:
     189            print "Changing, can't act."
     190            return
     191        if key_command == CMD_TOGGLE_FORM:
     192            self.world.transformations += 1
     193            self.toggle_form()
     194        if key_command == CMD_ATTACK:
     195            self.world.attacks += 1
     196            self.attack()
     197        if key_command == CMD_ACTION:
     198            self.perform_action()
     199
    168200    def get_render_angle(self):
    169201        # No image rotation when rendering, please.
     
    201233
    202234    def set_direction(self, dx, dy):
    203         if (dx, dy) == (0, 0):
     235        if (dx, dy) == (0, 0) or self.changing_sequence:
    204236            self.is_moving = False
    205237            return
     
    221253
    222254    def toggle_form(self):
    223         if self.form == self.WOLF_FORM:
     255        for form in self.CHANGING_SEQUENCE[self.form]:
     256            self.changing_sequence.extend([form] * 3)
     257
     258    def _go_to_next_form(self):
     259        if self.changing_sequence.pop(0) == self.WOLF_FORM:
     260            self.go_werewolf()
     261        else:
    224262            self.go_human()
    225         else:
    226             self.go_werewolf()
    227263
    228264    def get_current_interactible(self):
     
    306342
    307343    def update(self, dt):
     344        if self.changing_sequence:
     345            self._go_to_next_form()
    308346        if int(self.lifetime + dt) > int(self.lifetime):
    309347            if self.form == self.WOLF_FORM:
Note: See TracChangeset for help on using the changeset viewer.