Platform Game Tutorial 04 - hero death
In this tutorial we are going to make our hero actor react to the obstacles and enemies. Basically, our hero will die the moment it hits these actors.
Watch this animation below:
You can see that the actor bounced upwards and shows a "dead" image and then falls downwards off screen. What you are seeing there is an actor called deadHero that has been spawned the moment the hero actor hits the spikes. The hero actor will be destroyed.
Alright to do this, create another actor called deadHero.
Add the image called
dead1.png into the actor.
Add this behaviour into it:
Accelerate:
Direction: 270
Acceleration: 200
Relative to: scene
Add this rule into it:
If game.heroDead is false
change attribute:
self.Motion.LinearVelocity.X to 50
self.Motion.LinearVelocity.Y to 200
game.heroDead to true
If self.Position.Y < -50
change attribute:
game.lives to game.lives-1
Spawn Actor: hero,
position x=20, y=50
relative to scene
change attribute:
game.heroDead to false
This rule means that after the deadHero falls off-screen it will spawn the hero actor back to its original position at x=20 and y=50 in the game. It will also reset the game.heroDead to FALSE, so that the heroImage actor can appear and attach back to the hero actor.
Next, go into the hero actor and add this Rule inside it:
When Any conditions are valid:
If actor collides with actor of type : spikes
If actor collides with actor of type : EnemyA
Spawn Actor: deadHero,
position x=0, y=0
relative to actor
Destroy
Alright we're done! Let's preview our game.
Wait for the next tutorial coming up soon!
Watch this animation below:
You can see that the actor bounced upwards and shows a "dead" image and then falls downwards off screen. What you are seeing there is an actor called deadHero that has been spawned the moment the hero actor hits the spikes. The hero actor will be destroyed.
Alright to do this, create another actor called deadHero.
Add the image called
dead1.png into the actor.
Add this behaviour into it:
Accelerate:
Direction: 270
Acceleration: 200
Relative to: scene
Add this rule into it:
If game.heroDead is false
change attribute:
self.Motion.LinearVelocity.X to 50
self.Motion.LinearVelocity.Y to 200
game.heroDead to true
If self.Position.Y < -50
change attribute:
game.lives to game.lives-1
Spawn Actor: hero,
position x=20, y=50
relative to scene
change attribute:
game.heroDead to false
This rule means that after the deadHero falls off-screen it will spawn the hero actor back to its original position at x=20 and y=50 in the game. It will also reset the game.heroDead to FALSE, so that the heroImage actor can appear and attach back to the hero actor.
Next, go into the hero actor and add this Rule inside it:
When Any conditions are valid:
If actor collides with actor of type : spikes
If actor collides with actor of type : EnemyA
Spawn Actor: deadHero,
position x=0, y=0
relative to actor
Destroy
Alright we're done! Let's preview our game.
Wait for the next tutorial coming up soon!
Comments
Post a Comment