[Enemy] Clay Rocket

Started by YoshiMario2000, November 05, 2015, 02:24:27 AM

Previous topic - Next topic
Simple enemy I made for my project,
Also somewhat of a pain due to my noobness at programming.

Code (lua) Select

local enemy = ...
local map = enemy:get_map()
local self = enemy

function enemy:on_created()
  self:set_life(1)
  self:set_damage(6)
  self:create_sprite("enemies/ClayRocket1")
  self:set_size(16, 16)
  self:set_invincible()
  self:set_can_hurt_hero_running(true)
end

-- Objesct is to get the rocket to fire from the cannon
local function Move()
  local angle = self:get_sprite():get_direction()
  local m = sol.movement.create("straight")
  m:set_speed(128)
  m:set_angle(angle)
  m:start(self)
end

function enemy:on_restarted()
  Move()
end

-- The Goal is to get the rocket to expolde on impact of a wall.
function enemy:on_obstacle_reached(movement)
  local x, y, layer = enemy:get_position()
  map:create_explosion{
layer = layer,
x = x,
y = y
}
  sol.audio.play_sound("explosion")
  self:remove()
end


Bit of advice, Use a switch, sensor, and/or auto-spawn to use these rockets.
They start moving as soon as they are active in the map.

Also on line 8,
Put the string where you saved the attachments below.
This signature was way too long before, but now it's short!
Also, I am Still Alive!
On ad Off I go!

Do you ever get the feeling that the fandom of a product(s) ruin the potential that you could have had to enjoy the product?