Added initial media/code
parent
5dfcfa8eac
commit
8007cecc8b
|
@ -0,0 +1 @@
|
|||
default
|
|
@ -0,0 +1,93 @@
|
|||
turret.spread_ray = function(pos, rot)
|
||||
rot = rot or {x=0, y=0, z=0}
|
||||
local node = minetest.get_node(pos)
|
||||
local u_dir_vec = vector.rotate(minetest.facedir_to_dir(node.param2), {x=0, y=math.rad(180), z=0})
|
||||
|
||||
pos = vector.add(pos, {x=0, y=0.175, z=0})
|
||||
|
||||
--[[local nearby_objs = minetest.get_objects_inside_radius(pos, 20)
|
||||
local hit_objs = {}
|
||||
|
||||
for _, obj in ipairs(nearby_objs) do
|
||||
local self = obj:get_luaentity()
|
||||
|
||||
local view_ang = vector.angle(pos, obj:get_pos())
|
||||
if minetest.registered_entities[self.name].physical and self.name ~= "turret:ray" and view_ang <= math.rad(45) then
|
||||
hit_objs[#hit_objs+1] = obj
|
||||
end
|
||||
end
|
||||
|
||||
local rand_obj = hit_objs[math.random(1, #hit_objs)]]
|
||||
|
||||
local ray_segments_list = {}
|
||||
|
||||
local ray_seg = minetest.add_entity(pos, "turret:ray")
|
||||
ray_seg:set_properties({textures = {"turret_ray_seg.png"}})
|
||||
|
||||
local ang = vector.angle(u_dir_vec, {x=1, y=0, z=0})
|
||||
if vector.length(rot) ~= 0 then
|
||||
ray_seg:set_rotation({x=rot.x, y=rot.y+ang, z=rot.z})
|
||||
else
|
||||
ray_seg:set_yaw(ang)
|
||||
end
|
||||
ray_segments_list[#ray_segments_list+1] = pos
|
||||
|
||||
local next_pos = {x=u_dir_vec.x*math.cos(rot.y) - u_dir_vec.z*math.sin(rot.y),
|
||||
y=u_dir_vec.y,
|
||||
z=u_dir_vec.z*math.cos(rot.y) + u_dir_vec.x*math.sin(rot.y)
|
||||
}
|
||||
|
||||
next_pos.x = next_pos.x*math.cos(rot.z) - u_dir_vec.y*math.sin(rot.z)
|
||||
next_pos.y = next_pos.y*math.cos(rot.z) + u_dir_vec.x*math.sin(rot.z)
|
||||
|
||||
next_pos = vector.add(pos, next_pos)
|
||||
local node = minetest.get_node(next_pos)
|
||||
|
||||
local counter = 1
|
||||
while node.name == "air" do
|
||||
if counter > 100 then
|
||||
return true
|
||||
end
|
||||
|
||||
local obj = minetest.add_entity(next_pos, "turret:ray")
|
||||
|
||||
if vector.length(rot) ~= 0 then
|
||||
obj:set_rotation({x=rot.x, y=rot.y+ang, z=rot.z})
|
||||
else
|
||||
obj:set_yaw(ang)
|
||||
end
|
||||
ray_segments_list[#ray_segments_list+1] = next_pos
|
||||
|
||||
counter = counter + 1
|
||||
next_pos = {x=u_dir_vec.x*counter*math.cos(rot.y) - u_dir_vec.z*counter*math.sin(rot.y),
|
||||
y=u_dir_vec.y*counter,
|
||||
z=u_dir_vec.z*counter*math.cos(rot.y) + u_dir_vec.x*counter*math.sin(rot.y)
|
||||
}
|
||||
|
||||
next_pos.x = next_pos.x*math.cos(rot.z) - u_dir_vec.y*math.sin(rot.z)
|
||||
next_pos.y = next_pos.y*math.cos(rot.z) + u_dir_vec.x*math.sin(rot.z)
|
||||
|
||||
next_pos = vector.add(pos, next_pos)
|
||||
node = minetest.get_node(next_pos)
|
||||
end
|
||||
|
||||
local meta = minetest.get_meta(pos)
|
||||
meta:set_string("ray_segments_list", minetest.serialize(ray_segments_list))
|
||||
return true
|
||||
end
|
||||
|
||||
turret.delete_ray = function(pos)
|
||||
local meta = minetest.get_meta(pos)
|
||||
local ray_seg_l = minetest.deserialize(meta:get_string("ray_segments_list"))
|
||||
|
||||
for _, ray_seg in ipairs(ray_seg_l) do
|
||||
local ray = minetest.get_objects_inside_radius(ray_seg, 0.1)
|
||||
for _, obj in ipairs(ray) do
|
||||
if obj:get_luaentity().name == "turret:ray" then
|
||||
obj:remove()
|
||||
end
|
||||
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,49 @@
|
|||
turret = {}
|
||||
|
||||
local modpath = minetest.get_modpath("turret")
|
||||
|
||||
dofile(modpath .. "/functions.lua")
|
||||
|
||||
minetest.register_entity("turret:ray", {
|
||||
visual = "upright_sprite",
|
||||
visual_size = {x=1, y=0.25, z=1},
|
||||
textures = {"turret_ray.png"},
|
||||
collisionbox = {0, 0, 0, 0, 0, 0},
|
||||
glow = 10
|
||||
})
|
||||
|
||||
|
||||
minetest.register_node("turret:turret", {
|
||||
description = "Turret",
|
||||
drawtype = "mesh",
|
||||
mesh = "turret2.b3d",
|
||||
tiles = {"turret.png"},
|
||||
paramtype = "light",
|
||||
paramtype2 = "facedir",
|
||||
sunlight_propagates = true,
|
||||
collision_box = {
|
||||
type = "fixed",
|
||||
fixed = {-0.4, -0.5, -0.4, 0.4, 0.5, 0.4}
|
||||
},
|
||||
selection_box = {
|
||||
type = "fixed",
|
||||
fixed = {-0.4, -0.5, -0.4, 0.4, 0.5, 0.4}
|
||||
},
|
||||
groups = {cracky=2},
|
||||
sounds = default.node_sound_metal_defaults(),
|
||||
on_construct = function(pos)
|
||||
turret.spread_ray(pos)
|
||||
|
||||
local timer = minetest.get_node_timer(pos)
|
||||
timer:start(0.1)
|
||||
end,
|
||||
on_destruct = function(pos)
|
||||
turret.delete_ray(pos)
|
||||
end,
|
||||
on_timer = function(pos, elapsed)
|
||||
turret.delete_ray(pos)
|
||||
turret.spread_ray(pos)
|
||||
|
||||
return true
|
||||
end
|
||||
})
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
After Width: | Height: | Size: 1.4 KiB |
Binary file not shown.
After Width: | Height: | Size: 5.2 KiB |
Binary file not shown.
After Width: | Height: | Size: 310 B |
Binary file not shown.
After Width: | Height: | Size: 1.3 KiB |
Loading…
Reference in New Issue