mirror of
https://github.com/APercy/automobiles_pck
synced 2025-11-06 07:03:03 +01:00
added lights
This commit is contained in:
parent
6e1ac63edd
commit
6017baee2b
@ -56,50 +56,40 @@ function automobiles_lib.ground_get_distances(self, radius, axis_distance)
|
||||
if front_obstacle_level.y ~= nil and rear_obstacle_level.y ~= nil then
|
||||
local deltaX = axis_distance;
|
||||
local deltaY = front_obstacle_level.y - rear_obstacle_level.y;
|
||||
--minetest.chat_send_all("deutaY "..deltaY)
|
||||
local m = (deltaY/deltaX)
|
||||
pitch = math.atan(m) --math.atan2(deltaY, deltaX);
|
||||
--minetest.chat_send_all("m: "..m.." pitch ".. math.deg(pitch))
|
||||
if self.initial_properties.stepheight then
|
||||
--minetest.chat_send_all("deutaY "..deltaY)
|
||||
local m = (deltaY/deltaX)
|
||||
pitch = math.atan(m) --math.atan2(deltaY, deltaX);
|
||||
--minetest.chat_send_all("m: "..m.." pitch ".. math.deg(pitch))
|
||||
|
||||
--[[if mid_car_level then
|
||||
deltaX = axis_distance/2;
|
||||
if mid_car_level.y ~= nil then
|
||||
deltaY = mid_car_level.y - rear_obstacle_level.y;
|
||||
m = (deltaY/deltaX)
|
||||
local midpitch = math.atan(m)
|
||||
if math.abs(math.deg(pitch) - math.deg(midpitch)) < 20 then
|
||||
pitch = pitch + ((pitch - midpitch) / 2)
|
||||
--[[if mid_car_level then
|
||||
deltaX = axis_distance/2;
|
||||
if mid_car_level.y ~= nil then
|
||||
deltaY = mid_car_level.y - rear_obstacle_level.y;
|
||||
m = (deltaY/deltaX)
|
||||
local midpitch = math.atan(m)
|
||||
if math.abs(math.deg(pitch) - math.deg(midpitch)) < 20 then
|
||||
pitch = pitch + ((pitch - midpitch) / 2)
|
||||
end
|
||||
end
|
||||
end
|
||||
end]]--
|
||||
end]]--
|
||||
end
|
||||
else
|
||||
self._pitch = 0
|
||||
pitch = 0
|
||||
end
|
||||
|
||||
if math.abs(math.deg(pitch)) <= 45 and math.abs(math.deg(pitch - self._pitch)) < 20 then
|
||||
self._pitch = pitch
|
||||
else
|
||||
self._pitch = 0
|
||||
end
|
||||
self._pitch = pitch
|
||||
|
||||
end
|
||||
|
||||
function automobiles_lib.get_xz_from_hipotenuse(orig_x, orig_z, yaw, distance)
|
||||
--cara, o minetest é bizarro, ele considera o eixo no sentido ANTI-HORÁRIO... Então pra equação funcionar, subtrair o angulo de 360 antes
|
||||
yaw = math.rad(360) - yaw
|
||||
local z = (math.cos(yaw)*distance) + orig_z
|
||||
local x = (math.sin(yaw)*distance) + orig_x
|
||||
return x, z
|
||||
end
|
||||
|
||||
function automobiles_lib.get_obstacle(ref_pos)
|
||||
--lets clone the table
|
||||
local retval = {x=ref_pos.x, y=ref_pos.y, z=ref_pos.z}
|
||||
--minetest.chat_send_all("aa y: " .. dump(retval.y))
|
||||
local i_pos = {x=ref_pos.x, y=ref_pos.y, z=ref_pos.z}
|
||||
local i_pos = {x=ref_pos.x, y=ref_pos.y + 1, z=ref_pos.z}
|
||||
--minetest.chat_send_all("bb y: " .. dump(i_pos.y))
|
||||
|
||||
local y = automobiles_lib.eval_interception(i_pos, {x=i_pos.x, y=i_pos.y - 2, z=i_pos.z})
|
||||
local y = automobiles_lib.eval_interception(i_pos, {x=i_pos.x, y=i_pos.y - 3, z=i_pos.z})
|
||||
retval.y = y
|
||||
|
||||
--minetest.chat_send_all("y: " .. dump(ref_pos.y) .. " ye: ".. dump(retval.y))
|
||||
|
||||
@ -217,6 +217,112 @@ function automobiles_lib.setText(self, vehicle_name)
|
||||
end
|
||||
end
|
||||
|
||||
function automobiles_lib.get_xz_from_hipotenuse(orig_x, orig_z, yaw, distance)
|
||||
--cara, o minetest é bizarro, ele considera o eixo no sentido ANTI-HORÁRIO... Então pra equação funcionar, subtrair o angulo de 360 antes
|
||||
yaw = math.rad(360) - yaw
|
||||
local z = (math.cos(yaw)*distance) + orig_z
|
||||
local x = (math.sin(yaw)*distance) + orig_x
|
||||
return x, z
|
||||
end
|
||||
|
||||
function automobiles_lib.remove_light(self)
|
||||
if self._light_old_pos then
|
||||
--force the remotion of the last light
|
||||
minetest.add_node(self._light_old_pos, {name="air"})
|
||||
self._light_old_pos = nil
|
||||
end
|
||||
end
|
||||
|
||||
function automobiles_lib.swap_node(self, pos)
|
||||
local target_pos = pos
|
||||
local have_air = false
|
||||
local node = nil
|
||||
local count = 0
|
||||
while have_air == false and count <= 3 do
|
||||
node = minetest.get_node(target_pos)
|
||||
if node.name == "air" then
|
||||
have_air = true
|
||||
break
|
||||
end
|
||||
count = count + 1
|
||||
target_pos.y = target_pos.y + 1
|
||||
end
|
||||
|
||||
if have_air then
|
||||
minetest.set_node(target_pos, {name='automobiles_lib:light'})
|
||||
automobiles_lib.remove_light(self)
|
||||
self._light_old_pos = target_pos
|
||||
--remove after one second
|
||||
--[[minetest.after(1,function(target_pos)
|
||||
local node = minetest.get_node_or_nil(target_pos)
|
||||
if node and node.name == "automobiles_lib:light" then
|
||||
minetest.swap_node(target_pos, {name="air"})
|
||||
end
|
||||
end, target_pos)]]--
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
function automobiles_lib.put_light(self)
|
||||
local pos = self.object:get_pos()
|
||||
pos.y = pos.y + 1
|
||||
local yaw = self.object:get_yaw()
|
||||
local lx, lz = automobiles_lib.get_xz_from_hipotenuse(pos.x, pos.z, yaw, 10)
|
||||
local light_pos = {x=lx, y=pos.y, z=lz}
|
||||
|
||||
local cast = minetest.raycast(pos, light_pos, false, false)
|
||||
local thing = cast:next()
|
||||
local was_set = false
|
||||
while thing do
|
||||
if thing.type == "node" then
|
||||
local ipos = thing.intersection_point
|
||||
if ipos then
|
||||
was_set = automobiles_lib.swap_node(self, ipos)
|
||||
end
|
||||
end
|
||||
thing = cast:next()
|
||||
end
|
||||
if was_set == false then
|
||||
local n = minetest.get_node_or_nil(light_pos)
|
||||
if n and n.name == 'air' then
|
||||
automobiles_lib.swap_node(self, light_pos)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
--[[local n = minetest.get_node_or_nil(light_pos)
|
||||
--minetest.chat_send_player(name, n.name)
|
||||
if n and n.name == 'air' then
|
||||
minetest.set_node(pos, {name='automobiles_lib:light'})
|
||||
--local timer = minetest.get_node_timer(pos)
|
||||
--timer:set(10, 0)
|
||||
minetest.after(0.3,function(pos)
|
||||
local node = minetest.get_node_or_nil(pos)
|
||||
if node and node.name == "automobiles_lib:light" then
|
||||
minetest.swap_node(pos, {name="air"})
|
||||
end
|
||||
end, pos)
|
||||
end]]--
|
||||
|
||||
end
|
||||
|
||||
minetest.register_node("automobiles_lib:light", {
|
||||
drawtype = "glasslike",
|
||||
tile_images = {"automobiles_light.png"},
|
||||
inventory_image = minetest.inventorycube("automobiles_light.png"),
|
||||
paramtype = "light",
|
||||
walkable = false,
|
||||
is_ground_content = true,
|
||||
light_propagates = true,
|
||||
sunlight_propagates = true,
|
||||
light_source = 14,
|
||||
selection_box = {
|
||||
type = "fixed",
|
||||
fixed = {0, 0, 0, 0, 0, 0},
|
||||
},
|
||||
})
|
||||
|
||||
dofile(minetest.get_modpath("automobiles_lib") .. DIR_DELIM .. "custom_physics.lua")
|
||||
dofile(minetest.get_modpath("automobiles_lib") .. DIR_DELIM .. "control.lua")
|
||||
dofile(minetest.get_modpath("automobiles_lib") .. DIR_DELIM .. "fuel_management.lua")
|
||||
|
||||
BIN
automobiles_lib/textures/automobiles_light.png
Normal file
BIN
automobiles_lib/textures/automobiles_light.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 246 B |
BIN
automobiles_roadster/models/automobiles_roadster_lights.b3d
Executable file
BIN
automobiles_roadster/models/automobiles_roadster_lights.b3d
Executable file
Binary file not shown.
@ -47,6 +47,29 @@ initial_properties = {
|
||||
|
||||
})
|
||||
|
||||
minetest.register_entity('automobiles_roadster:lights',{
|
||||
initial_properties = {
|
||||
physical = false,
|
||||
collide_with_objects=false,
|
||||
pointable=false,
|
||||
glow = 15,
|
||||
visual = "mesh",
|
||||
mesh = "automobiles_roadster_lights.b3d",
|
||||
textures = {"automobiles_roadster_lights.png",},
|
||||
},
|
||||
|
||||
on_activate = function(self,std)
|
||||
self.sdata = minetest.deserialize(std) or {}
|
||||
if self.sdata.remove then self.object:remove() end
|
||||
end,
|
||||
|
||||
get_staticdata=function(self)
|
||||
self.sdata.remove=true
|
||||
return minetest.serialize(self.sdata)
|
||||
end,
|
||||
|
||||
})
|
||||
|
||||
minetest.register_entity('automobiles_roadster:wheel',{
|
||||
initial_properties = {
|
||||
physical = false,
|
||||
@ -239,6 +262,8 @@ minetest.register_entity("automobiles_roadster:roadster", {
|
||||
_pitch = 0,
|
||||
_longit_speed = 0,
|
||||
_show_rag = true,
|
||||
_show_lights = false,
|
||||
_light_old_pos = nil,
|
||||
|
||||
get_staticdata = function(self) -- unloaded/unloads ... is now saved
|
||||
return minetest.serialize({
|
||||
@ -253,6 +278,7 @@ minetest.register_entity("automobiles_roadster:roadster", {
|
||||
stored_race_id = self._race_id,
|
||||
stored_rag = self._show_rag,
|
||||
stored_pitch = self._pitch,
|
||||
stored_light_old_pos = self._light_old_pos,
|
||||
})
|
||||
end,
|
||||
|
||||
@ -271,6 +297,7 @@ minetest.register_entity("automobiles_roadster:roadster", {
|
||||
self._race_id = data.stored_race_id
|
||||
self._show_rag = data.stored_rag
|
||||
self._pitch = data.stored_pitch
|
||||
self._light_old_pos = data.stored_light_old_pos
|
||||
automobiles_lib.setText(self, "Roadster")
|
||||
end
|
||||
|
||||
@ -340,6 +367,11 @@ minetest.register_entity("automobiles_roadster:roadster", {
|
||||
fuel_gauge:set_attach(self.object,'',ROADSTER_GAUGE_FUEL_POSITION,{x=0,y=0,z=0})
|
||||
self.fuel_gauge = fuel_gauge
|
||||
|
||||
local lights = minetest.add_entity(pos,'automobiles_roadster:lights')
|
||||
lights:set_attach(self.object,'',{x=0,y=0,z=0},{x=0,y=0,z=0})
|
||||
self.lights = lights
|
||||
self.lights:set_properties({is_visible=false})
|
||||
|
||||
self.object:set_armor_groups({immortal=1})
|
||||
|
||||
mobkit.actfunc(self, staticdata, dtime_s)
|
||||
@ -411,6 +443,14 @@ minetest.register_entity("automobiles_roadster:roadster", {
|
||||
end
|
||||
end
|
||||
|
||||
if self._show_lights == true and is_attached then
|
||||
self.lights:set_properties({is_visible=true})
|
||||
automobiles_lib.put_light(self)
|
||||
else
|
||||
self.lights:set_properties({is_visible=false})
|
||||
automobiles_lib.remove_light(self)
|
||||
end
|
||||
|
||||
local curr_pos = self.object:get_pos()
|
||||
if is_attached then --and self.driver_name == self.owner then
|
||||
local impact = automobiles_lib.get_hipotenuse_value(velocity, self.lastvelocity)
|
||||
@ -456,6 +496,7 @@ minetest.register_entity("automobiles_roadster:roadster", {
|
||||
end
|
||||
accel, stop = automobiles_lib.control(self, dtime, hull_direction, longit_speed, longit_drag, later_drag, accel, roadster.max_acc_factor, roadster.max_speed, steering_angle_max, steering_speed)
|
||||
else
|
||||
self._show_lights = false
|
||||
if self.sound_handle ~= nil then
|
||||
minetest.sound_stop(self.sound_handle)
|
||||
self.sound_handle = nil
|
||||
|
||||
@ -15,11 +15,12 @@ end
|
||||
function roadster.driver_formspec(name)
|
||||
local basic_form = table.concat({
|
||||
"formspec_version[3]",
|
||||
"size[6,4.5]",
|
||||
"size[6,6]",
|
||||
}, "")
|
||||
|
||||
basic_form = basic_form.."button[1,1.0;4,1;go_out;Go Offboard]"
|
||||
basic_form = basic_form.."button[1,2.5;4,1;top;Close/Open Ragtop]"
|
||||
basic_form = basic_form.."button[1,4.0;4,1;lights;Lights]"
|
||||
|
||||
minetest.show_formspec(name, "roadster:driver_main", basic_form)
|
||||
end
|
||||
@ -47,6 +48,13 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||
|
||||
automobiles_lib.dettach_driver(ent, player)
|
||||
end
|
||||
if fields.lights then
|
||||
if ent._show_lights == true then
|
||||
ent._show_lights = false
|
||||
else
|
||||
ent._show_lights = true
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
minetest.close_formspec(name, "roadster:driver_main")
|
||||
|
||||
@ -3,6 +3,7 @@
|
||||
|
||||
-- destroy the roadster
|
||||
function roadster.destroy(self, puncher)
|
||||
automobiles_lib.remove_light(self)
|
||||
if self.sound_handle then
|
||||
minetest.sound_stop(self.sound_handle)
|
||||
self.sound_handle = nil
|
||||
@ -37,6 +38,7 @@ function roadster.destroy(self, puncher)
|
||||
if self.driver_seat then self.driver_seat:remove() end
|
||||
if self.passenger_seat then self.passenger_seat:remove() end
|
||||
if self.fuel_gauge then self.fuel_gauge:remove() end
|
||||
if self.lights then self.lights:remove() end
|
||||
|
||||
self.object:remove()
|
||||
|
||||
|
||||
BIN
automobiles_roadster/textures/automobiles_roadster_lights.png
Executable file
BIN
automobiles_roadster/textures/automobiles_roadster_lights.png
Executable file
Binary file not shown.
|
After Width: | Height: | Size: 5.3 KiB |
Loading…
Reference in New Issue
Block a user