Simple enemy I made for my project,
Also somewhat of a pain due to my noobness at programming.
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.