89 lines
2.2 KiB
Lua
89 lines
2.2 KiB
Lua
local PROJECTILE_LIFE_TIME = 30
|
|
|
|
local SHADOW_PROJECTILE_TOOL_PROPERTIES = {
|
|
full_punch_interval = 0.0,
|
|
damage_groups = { fleshy = 1 },
|
|
}
|
|
|
|
local impact_particles = function(mob)
|
|
minetest.add_particlespawner({
|
|
amount = 12,
|
|
time = 0.05,
|
|
exptime = {
|
|
min = 0.7,
|
|
max = 1.4,
|
|
},
|
|
size = 1,
|
|
pos = mob.object:get_pos(),
|
|
vel = {
|
|
min = vector.new(-2, -2, -2),
|
|
max = vector.new(2, 2, 2),
|
|
},
|
|
drag = vector.new(5, 5, 5),
|
|
texture = {
|
|
name = "sf_particles_shadow_poof_anim.png",
|
|
},
|
|
animation = {
|
|
type = "vertical_frames",
|
|
aspect_w = 16,
|
|
aspect_h = 16,
|
|
length = -1,
|
|
},
|
|
})
|
|
end
|
|
|
|
minetest.register_entity("sf_projectiles:shadow", {
|
|
initial_properties = {
|
|
visual = "cube",
|
|
physical = true,
|
|
collides_with_objects = true,
|
|
textures = {
|
|
"sf_projectiles_shadow.png",
|
|
"sf_projectiles_shadow.png",
|
|
"sf_projectiles_shadow.png",
|
|
"sf_projectiles_shadow.png",
|
|
"sf_projectiles_shadow.png",
|
|
"sf_projectiles_shadow.png",
|
|
},
|
|
collisionbox = { -0.125, -0.125, -0.125, 0.125, 0.125, 0.125 },
|
|
selectionbox = { -0.125, -0.125, -0.125, 0.125, 0.125, 0.125, rotate = true },
|
|
visual_size = { x = 0.25, y = 0.25, z = 0.25 },
|
|
},
|
|
_life_timer = 0,
|
|
on_activate = function(self, staticdata)
|
|
self.object:set_armor_groups({immortal=1})
|
|
-- DEBUG: default speed
|
|
self.object:set_velocity({x=9,y=0,z=0})
|
|
end,
|
|
on_deactivate = function(self, removal)
|
|
if removal then
|
|
end
|
|
end,
|
|
on_step = function(self, dtime, moveresult)
|
|
local opos = self.object:get_pos()
|
|
if moveresult.collides then
|
|
for c=1, #moveresult.collisions do
|
|
local collision = moveresult.collisions[c]
|
|
if collision.type == "object" then
|
|
if collision.object:is_player() then
|
|
local dir = vector.direction(opos, collision.object:get_pos())
|
|
collision.object:punch(self.object, math.huge, SHADOW_PROJECTILE_TOOL_PROPERTIES, dir)
|
|
end
|
|
impact_particles(self)
|
|
self.object:remove()
|
|
return
|
|
elseif collision.type == "node" then
|
|
impact_particles(self)
|
|
self.object:remove()
|
|
return
|
|
end
|
|
end
|
|
end
|
|
self._life_timer = self._life_timer + dtime
|
|
if self._life_timer > PROJECTILE_LIFE_TIME then
|
|
self.object:remove()
|
|
return
|
|
end
|
|
end,
|
|
})
|