Help: Enemy throwing a projectile

Started by froggy77, February 07, 2015, 08:25:24 PM

Previous topic - Next topic
February 07, 2015, 08:25:24 PM Last Edit: February 07, 2015, 08:27:55 PM by froggy77
Is there an explanation somewhere on the way to create an enemy that throws something like a fireball?
The enemy would throw the projectile only if the hero is quite close and if the enemy  can see him.

There are a lot of bosses that throw projectiles like fireballs in ZSDX. You can look at their code to have examples.
Basically, the idea is to make a repetitive timer that shoot a fireball if the distance the hero is lower than some value. To shoot the fireball, use enemy:create_enemy(). The trick is that the fireball itself is another model of enemy.

Sorry but examples in ZSDX are too complicated and most seem too different from version 1.3 of Solarus Game Engine.

The latest release of ZSDX (1.9) works with Solarus 1.3.
But yes, bosses are really complicated.
First you can try to make a fireball enemy, with either a movement that targets the hero or a straight movement. It would destroy itself when reaching an obstacle.
Then, make your boss create this enemy periodically from a timer.

March 29, 2015, 03:57:45 PM #4 Last Edit: March 29, 2015, 04:01:08 PM by froggy77
"The latest release of ZSDX (1.9) works with Solarus 1.3."sorry I did not know. Indeed there are some examples .
I managed to create an enemy that shoots fireballs when the hero is far enough. Fireballs go straight.
The enemy fled just when the hero is approaching. If the hero is near and its back is turned , the enemy attacks like a coward.

Now what I would like to do is that the enemy only shoot when there is no obstacle in front of him.
If there is a house or a wall between the enemy and the hero , the enemy still shoots and I would like to avoid that.
I try with entity:test_obstacles(dx, dy, [layer]) but I don't really understand it.
Is this method tests the presence of an obstacle every x and y of the "vector" or simply the end point ?
What would be the right approach ?

entity:test_obstacles(dx, dy, [layer]) tests only one point: the point of coordinates entity:get_x() + dx, entity:get_y() + dy. So you can use a loop to test every point of a straight line.