How to draw enemy death animation if its collision is valid

Started by
11 comments, last by Nicholas Kong 10 years, 11 months ago

You definitely need two separates states in your FiniteStateMachine:


enum EnemyState
{
.....
Dying,
Dead,
.......
};

 

The Logic to make sure you handle the switch to Dying status just once (even if the laser will be on screen few more seconds):


if (Is_There_Collision_Of_Laser_With_Enemy ())
  if ((EnemyStatus !=Dying) && (EnemyStatus != Dead))
  {
    EnemyStatus = stDying;
    Start_Dying_Animation (Time_Of_Current_Frame, Length_Of_Dying_Animation)
  }

 

.....

Now you need to switch from Dying to Dead, when Dying animation is over in the place where you handle the states:


if (EnemyStatus == Dying)
{
  if (Time_Of_Current_Frame >= Time_End_Of_Dying_Animation)
  {
    EnemyStatus = Dead;
  }
}

 

VladR My 3rd person action RPG on GreenLight: http://steamcommunity.com/sharedfiles/filedetails/?id=92951596

Advertisement

warnexus, on 11 May 2013 - 06:09, said:
I am having trouble figuring out how to make it a few seconds pass as a condition to trigger the removal of the monster.

You must know when the death animation finishes though? I.e. How many frames (or milliseconds) the animation requires/has-remaining before it finishes.

I think the point is that you need to model the state transitions as a kind of state in its own right, e.g. moving between being "alive" to being "dead" involves a state-transition called "dying". So a monster gets hit by a laser, it enters into a "dying" state; your update logic will respond to that state by playing the death animation. Once the animation completes your update logic removes the monster (or if the monster should just hang around being dead then you set it to a "dead" state).

warnexus, on 11 May 2013 - 06:09, said:
I am having trouble figuring out how to make it a few seconds pass as a condition to trigger the removal of the monster.

You must know when the death animation finishes though? I.e. How many frames (or milliseconds) the animation requires/has-remaining before it finishes.

I think the point is that you need to model the state transitions as a kind of state in its own right, e.g. moving between being "alive" to being "dead" involves a state-transition called "dying". So a monster gets hit by a laser, it enters into a "dying" state; your update logic will respond to that state by playing the death animation. Once the animation completes your update logic removes the monster (or if the monster should just hang around being dead then you set it to a "dead" state).

Thanks for the ideas! I got it to work!

Why is there a -1?

This topic is closed to new replies.

Advertisement