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:
Relative to: scene
Add this rule into it:
If game.heroDead is false
self.Motion.LinearVelocity.X to 50
self.Motion.LinearVelocity.Y to 200
game.heroDead to true
If self.Position.Y < -50
game.lives to game.lives-1
Spawn Actor: hero,
position x=20, y=50
relative to scene
game.heroDead to false
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
Alright we're done! Let's preview our game.
Wait for the next tutorial coming up soon!