Making a 3 life health system work. [SOLVED]

Started by Glenjamin, Sat 29/08/2015 22:44:25

Previous topic - Next topic

Glenjamin

I'm currently working on a game where the player takes 3 hits to kill him and end the game.

So logically, I set up a variable for health called "health" and se it's starting value to 3.

Then I set up the code to play the death animations when the player is killed.  This is currently in the Room_load funtion

Code: ags

if (health == 0)
  {
      player.ChangeView(1);
        player.Animate(2, 5, eRepeat, eNoBlock);
        Wait(50);
     aScream.Play(eAudioPriorityHigh, eOnce);
     player.Animate(1, 5, eRepeat, eBlock);
    }


Then, there's three events controlling when the player gets damaged.

This is when a bowling ball lands on his head.
Code: ags


if (player.IsCollidingWithObject(oObject1))
{
player.StopMoving(); 
aRambling_ball.Stop();
oObject1.Visible = false;
 player.ChangeView(8);
 player.Animate(0, 5, eOnce, eBlock);
 health -= 1;
 oinactiveball.Visible = true;
 Wait(100);
   player.ChangeView(4);
  
    ctalk.Walk(2241, 143, eNoBlock, eAnywhere);
 }


This is when he gets a door slammed on him.

Code: ags


if ((atshop == true) && (running == true))
{
  aAccounting2.Stop();
  player.ChangeView(8);
  player.Animate(1, 5, eOnce, eBlock, eForwards);
  player.ChangeView(7);
  player.Animate(3, 5, eOnce, eBlock);
   Wait(100);
   player.ChangeView(4);
   health -= 1;
    ctalk.Walk(3290, 143, eNoBlock, eAnywhere);
  }


And finally, when he gets hit in the head with a flower pot.

Code: ags


if (player.IsCollidingWithObject(oactivepot))
{
player.StopMoving(); 
aAccounting2.Stop();
oactivepot.Visible = false;
 player.ChangeView(8);
 player.Animate(0, 5, eOnce, eBlock);

 obrokepot.Visible = true;
 Wait(100);
   player.ChangeView(4);
   health -= 1;
    ctalk.Walk(3290, 143, eNoBlock, eAnywhere);
 }



Despite executing all 3 of these events perfectly in the game, The death animation doesn't happen. Thanks for all the help you guys! :smiley:

Mandle

#1
I think your problem is that the code to check if Health == 0 is in Room Load. This means that the game only checks every time the player enters the room.

It should be either immediately following the code that subtracts the health OR in Repetedly Execute if you want death to happen the same game-loop that Health hits zero.

Also:

health --;

should be fine for subtracting a single health each time. Not sure if this is tied to the problem though. Probably not.

Glenjamin

Thank you so much! my game is functional again thanks to you!

SMF spam blocked by CleanTalk