Solarus-Games English Forum

Solarus => Development => Topic started by: YoshiMario2000 on June 13, 2015, 06:02:18 PM

Title: Bubble + boomerang = fairy?
Post by: YoshiMario2000 on June 13, 2015, 06:02:18 PM
Is it possible to trow a boomerang at a bubble and get a fairy?
Title: Re: Bubble + boomerang = fairy?
Post by: Diarandor on June 13, 2015, 06:20:48 PM
Yes. It is possible to make almost anything if you know how to code it (but not easy).

To do what you want, I would use a custom entity for the bubble. You can use a collision test on the bubble script to detect the collision with the boomerang. (I have done something similar to make trees that throw leaves when hit with the sword, and it works.) You can use something like this:

entity:add_collision_test("sprite", function(entity, other_entity, sprite, other_sprite)
  if other_sprite:get_animation() ~= "boomerang" then return end
  -- Here goes your code...
end
Title: Re: Bubble + boomerang = fairy?
Post by: Christopho on June 13, 2015, 11:57:26 PM
It is even possible to keep the bubble as a normal enemy.
Define the enemy:on_hurt(attack) event on bubble, and if attack == "boomerang", call enemy:set_treasure("fairy").
See http://www.solarus-games.org/doc/latest/lua_api_enemy.html#lua_api_enemy_on_hurt
Title: Re: Bubble + boomerang = fairy?
Post by: YoshiMario2000 on June 17, 2015, 04:58:37 PM
Quote from: Christopho on June 13, 2015, 11:57:26 PM
It is even possible to keep the bubble as a normal enemy.
Define the enemy:on_hurt(attack) event on bubble, and if attack == "boomerang", call enemy:set_treasure("fairy").
See http://www.solarus-games.org/doc/latest/lua_api_enemy.html#lua_api_enemy_on_hurt

After that I think we would want to remove the bubble.

If you have played link's awakening, or the oracle games,
Trowing a boomerang at a bubble will cause it to "transform" into a fairy.
That's probably why the are called anti-fairys.
Title: Re: Bubble + boomerang = fairy?
Post by: Christopho on June 17, 2015, 06:03:07 PM
That's right!

function enemy:on_hurt(attack)
  if attack == "boomerang" then
    local layer, x, y = enemy:get_position()
    map:create_pickable({
      layer = layer,
      x = x,
      y = y,
      treasure_name = "fairy"
    })
    enemy:remove()
  end
end
     
     
Title: Re: Bubble + boomerang = fairy?
Post by: YoshiMario2000 on June 18, 2015, 01:11:08 AM
But, This works beater, at least, for me anyways.

function enemy:on_created()
  self:set_life(1)
  self:create_sprite("enemies/bubble")
  self:set_size(8, 8)
  self:set_origin(4, 4)
  self:set_can_hurt_hero_running(true)
  self:set_attack_consequence("sword", "ignored")
  self:set_attack_consequence("hookshot", "ignored")
  self:set_attack_consequence("arrow", "ignored")
  self:set_attack_consequence("fire", "ignored")
  self:set_attack_consequence("explosion", "ignored")
  self:set_attack_consequence("thrown_item", "ignored")
  self:set_attack_consequence("boomerang", 10)
  self:set_treasure("fairy")
end


You're result Gave some useless and humorous results. The bubble could be hit,
It just couldn't be killed. even by boomerang.