Solarus Forum

Solarus => Development => Topic started by: froggy77 on February 07, 2015, 08:25:24 pm

Title: Help: Enemy throwing a projectile
Post by: froggy77 on February 07, 2015, 08:25:24 pm
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.
Title: Re: Help: Enemy throwing a projectile
Post by: Christopho on February 07, 2015, 09:13:50 pm
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.
Title: Re: Help: Enemy throwing a projectile
Post by: froggy77 on February 08, 2015, 04:53:22 pm
Sorry but examples in ZSDX are too complicated and most seem too different from version 1.3 of Solarus Game Engine.
Title: Re: Help: Enemy throwing a projectile
Post by: Christopho on February 08, 2015, 05:47:38 pm
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.
Title: Re: Help: Enemy throwing a projectile
Post by: froggy77 on March 29, 2015, 03:57:45 pm
"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 ?
Title: Re: Help: Enemy throwing a projectile
Post by: Christopho on March 29, 2015, 07:05:15 pm
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.