enemy's death condition/animation
-
so at the moment my enemies die if i jump on them (detects velocity) but i want them to die from a button press say X which is my attack button .?
then could i trigger the enemy's death animation with
if player 1 c.x enemy = death ...... -
The way I've been handling things like this, is that I give each sprite a state. Rather than control everything directly, certain "actions" cause the state to change ~ then the last (or first) thing to happen is for that state to be actioned. It's kind of like;
IDLE = 0 UP = 1 DOWN = 2 LEFT = 4 RIGHT = 8 JUMP = 16 FALLING = 32 DEAD = 64
I use bitwise comparisons to set multiple states for a sprite, e.g. Willy is JUMPing LEFT, or JUMPing RIGHT but also can simply be JUMPing. Anyways, for example the directions cause the state to change to LEFT or RIGHT and then the result of that state change happens later not right at the time of the action. This allows me to also set a state of say, FALLING when applying gravity which isn't untriggered until Willy is either DEAD or he lands (IDLE).
-
So then jumping left would return 20?
-
Oh I get it same as you would set states for your character you do the same for the enemy and code the actions in
-
@waldron said in enemy's death condition/animation:
Oh I get it same as you would set states for your character you do the same for the enemy and code the actions in
Yeah absolutely! There's no reason why not right?! ;)
@lawyerlounge said in enemy's death condition/animation:
So then jumping left would return 20?
Yeah, that's it! And you test the condition with e.g.
if game.willy.state == LEFT | JUMP then // Willy is jumping left. endif