mirror of
https://github.com/APercy/automobiles_pck
synced 2025-10-24 09:43:08 +02:00
added compatibility with drift game
This commit is contained in:
parent
910bb3fbca
commit
eac604cb65
@ -445,6 +445,8 @@ minetest.register_entity("automobiles_delorean:delorean", {
|
||||
_max_speed = 30,
|
||||
_min_later_speed = 4.5,
|
||||
|
||||
_wheel_compensation = 0.8,
|
||||
|
||||
get_staticdata = automobiles_lib.get_staticdata,
|
||||
|
||||
on_deactivate = function(self)
|
||||
@ -454,286 +456,6 @@ minetest.register_entity("automobiles_delorean:delorean", {
|
||||
on_activate = automobiles_lib.on_activate,
|
||||
|
||||
on_step = automobiles_lib.on_step,
|
||||
--[[on_step = function(self, dtime)
|
||||
automobiles_lib.stepfunc(self, dtime)
|
||||
--sound play control--
|
||||
self._last_time_collision_snd = self._last_time_collision_snd + dtime
|
||||
if self._last_time_collision_snd > 1 then self._last_time_collision_snd = 1 end
|
||||
self._last_time_drift_snd = self._last_time_drift_snd + dtime
|
||||
if self._last_time_drift_snd > 1 then self._last_time_drift_snd = 1 end
|
||||
--end sound control--
|
||||
|
||||
local rotation = self.object:get_rotation()
|
||||
local yaw = rotation.y
|
||||
local newyaw=yaw
|
||||
local pitch = rotation.x
|
||||
|
||||
local hull_direction = minetest.yaw_to_dir(yaw)
|
||||
local nhdir = {x=hull_direction.z,y=0,z=-hull_direction.x} -- lateral unit vector
|
||||
local velocity = self.object:get_velocity()
|
||||
|
||||
local longit_speed = automobiles_lib.dot(velocity,hull_direction)
|
||||
local fuel_weight_factor = (5 - self._energy)/5000
|
||||
local longit_drag = vector.multiply(hull_direction,(longit_speed*longit_speed) *
|
||||
(delorean.LONGIT_DRAG_FACTOR - fuel_weight_factor) * -1 * automobiles_lib.sign(longit_speed))
|
||||
|
||||
local later_speed = automobiles_lib.dot(velocity,nhdir)
|
||||
local later_drag = vector.multiply(nhdir,later_speed*
|
||||
later_speed*delorean.LATER_DRAG_FACTOR*-1*automobiles_lib.sign(later_speed))
|
||||
|
||||
local accel = vector.add(longit_drag,later_drag)
|
||||
local stop = nil
|
||||
local curr_pos = self.object:get_pos()
|
||||
|
||||
local player = nil
|
||||
local is_attached = false
|
||||
if self.driver_name then
|
||||
player = minetest.get_player_by_name(self.driver_name)
|
||||
|
||||
if player then
|
||||
local player_attach = player:get_attach()
|
||||
if player_attach then
|
||||
if self.driver_seat then
|
||||
if player_attach == self.driver_seat then is_attached = true end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--to fix the load on first time and turn on the lights of time machine
|
||||
delorean.set_mode(self, is_attached, curr_pos, velocity, player, dtime)
|
||||
|
||||
local is_breaking = false
|
||||
if is_attached then
|
||||
local ctrl = player:get_player_control()
|
||||
if ctrl.aux1 then
|
||||
--sets the engine running - but sets a delay also, cause keypress
|
||||
if self._last_time_command > 0.8 then
|
||||
self._last_time_command = 0
|
||||
minetest.sound_play({name = "automobiles_horn"},
|
||||
{object = self.object, gain = 0.6, pitch = 1.0, max_hear_distance = 32, loop = false,})
|
||||
end
|
||||
end
|
||||
if ctrl.down then
|
||||
is_breaking = true
|
||||
self.r_lights:set_properties({textures={"automobiles_rear_lights_full.png"}, glow=15})
|
||||
end
|
||||
if ctrl.sneak then
|
||||
self.reverse_lights:set_properties({textures={"automobiles_white.png"}, glow=15})
|
||||
else
|
||||
self.reverse_lights:set_properties({textures={"automobiles_grey.png"}, glow=0})
|
||||
end
|
||||
end
|
||||
|
||||
self._last_light_move = self._last_light_move + dtime
|
||||
if self._last_light_move > 0.15 then
|
||||
self._last_light_move = 0
|
||||
if self._show_lights == true then
|
||||
--self.lights:set_properties({is_visible=true})
|
||||
self.lights:set_properties({textures={"automobiles_delorean_lights.png", "automobiles_black.png"}, glow=15})
|
||||
if is_breaking == false then
|
||||
self.r_lights:set_properties({textures={"automobiles_rear_lights.png"}, glow=10})
|
||||
end
|
||||
automobiles_lib.put_light(self)
|
||||
else
|
||||
--self.lights:set_properties({is_visible=false})
|
||||
self.lights:set_properties({textures={"automobiles_grey.png", "automobiles_black.png"}, glow=0})
|
||||
if is_breaking == false then
|
||||
self.r_lights:set_properties({textures={"automobiles_rear_lights_off.png"}, glow=0})
|
||||
end
|
||||
automobiles_lib.remove_light(self)
|
||||
end
|
||||
end
|
||||
|
||||
-- impacts and control
|
||||
self.object:move_to(curr_pos)
|
||||
if is_attached then --and self.driver_name == self.owner then
|
||||
local impact = automobiles_lib.get_hipotenuse_value(velocity, self.lastvelocity)
|
||||
if impact > 1 then
|
||||
--self.damage = self.damage + impact --sum the impact value directly to damage meter
|
||||
if self._last_time_collision_snd > 0.3 then
|
||||
self._last_time_collision_snd = 0
|
||||
minetest.sound_play("automobiles_collision", {
|
||||
to_player = self.driver_name,
|
||||
--pos = curr_pos,
|
||||
--max_hear_distance = 5,
|
||||
gain = 1.0,
|
||||
fade = 0.0,
|
||||
pitch = 1.0,
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
--control
|
||||
local steering_angle_max = 30
|
||||
local steering_speed = 40
|
||||
if math.abs(longit_speed) > 3 then
|
||||
local mid_speed = (steering_speed/2)
|
||||
steering_speed = mid_speed + mid_speed / math.abs(longit_speed*0.25)
|
||||
end
|
||||
accel, stop = delorean.control(self, dtime, hull_direction, longit_speed, longit_drag, later_drag, accel, delorean.max_acc_factor, delorean.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
|
||||
end
|
||||
end
|
||||
|
||||
local angle_factor = self._steering_angle / 10
|
||||
|
||||
--check if the tyres is touching the pavement
|
||||
local noded = automobiles_lib.nodeatpos(automobiles_lib.pos_shift(curr_pos,{y=-0.3}))
|
||||
if (noded and noded.drawtype ~= 'airlike') then
|
||||
if noded.drawtype ~= 'liquid' then
|
||||
local min_later_speed = 0.9
|
||||
if (later_speed > min_later_speed or later_speed < -min_later_speed) and
|
||||
self._last_time_drift_snd > 0.6 then
|
||||
self._last_time_drift_snd = 0
|
||||
minetest.sound_play("automobiles_drifting", {
|
||||
pos = curr_pos,
|
||||
max_hear_distance = 20,
|
||||
gain = 3.0,
|
||||
fade = 0.0,
|
||||
pitch = 1.0,
|
||||
ephemeral = true,
|
||||
})
|
||||
end
|
||||
|
||||
self.lf_wheel:set_animation_frame_speed(longit_speed * (12 - angle_factor))
|
||||
self.rf_wheel:set_animation_frame_speed(-longit_speed * (12 + angle_factor))
|
||||
self.lr_wheel:set_animation_frame_speed(longit_speed * (12 - angle_factor))
|
||||
self.rr_wheel:set_animation_frame_speed(-longit_speed * (12 + angle_factor))
|
||||
end
|
||||
else
|
||||
--is flying
|
||||
self.lf_wheel:set_animation_frame_speed(0)
|
||||
self.rf_wheel:set_animation_frame_speed(0)
|
||||
self.lr_wheel:set_animation_frame_speed(0)
|
||||
self.rr_wheel:set_animation_frame_speed(0)
|
||||
end
|
||||
|
||||
--drive wheel turn
|
||||
self.object:set_bone_position("drive_wheel", {x=-0, y=0, z=0}, {x=0, y=0, z=-self._steering_angle*2})
|
||||
delorean.set_wheels_mode(self, angle_factor)
|
||||
|
||||
|
||||
if math.abs(self._steering_angle)>5 then
|
||||
local turn_rate = math.rad(40)
|
||||
newyaw = yaw + dtime*(1 - 1 / (math.abs(longit_speed) + 1)) *
|
||||
self._steering_angle / 30 * turn_rate * automobiles_lib.sign(longit_speed)
|
||||
end
|
||||
|
||||
--turn light
|
||||
self._turn_light_timer = self._turn_light_timer + dtime
|
||||
if math.abs(self._steering_angle) > 15 and self._turn_light_timer >= 1 then
|
||||
self._turn_light_timer = 0
|
||||
--set turn light
|
||||
--minetest.chat_send_all(self._steering_angle)
|
||||
if self._steering_angle < 0 then
|
||||
--minetest.chat_send_all("direita")
|
||||
self.turn_r_light:set_properties({textures={"automobiles_turn_on.png"}, glow=20})
|
||||
end
|
||||
if self._steering_angle > 0 then
|
||||
--minetest.chat_send_all("esquerda")
|
||||
self.turn_l_light:set_properties({textures={"automobiles_turn_on.png"}, glow=20})
|
||||
end
|
||||
end
|
||||
if self._turn_light_timer > 0.5 then
|
||||
self.turn_l_light:set_properties({textures={"automobiles_turn.png"}, glow=0})
|
||||
self.turn_r_light:set_properties({textures={"automobiles_turn.png"}, glow=0})
|
||||
end
|
||||
if self._turn_light_timer > 1 then
|
||||
self._turn_light_timer = 1
|
||||
end
|
||||
|
||||
--accell correction
|
||||
--under some circunstances the acceleration exceeds the max value accepted by set_acceleration and
|
||||
--the game crashes with an overflow, so limiting the max acceleration in each axis prevents the crash
|
||||
local max_factor = 25
|
||||
local acc_adjusted = 10
|
||||
if accel.x > max_factor then accel.x = acc_adjusted end
|
||||
if accel.x < -max_factor then accel.x = -acc_adjusted end
|
||||
if accel.z > max_factor then accel.z = acc_adjusted end
|
||||
if accel.z < -max_factor then accel.z = -acc_adjusted end
|
||||
-- end correction
|
||||
|
||||
-- calculate energy consumption --
|
||||
----------------------------------
|
||||
if self._energy > 0 then
|
||||
local zero_reference = vector.new()
|
||||
local acceleration = automobiles_lib.get_hipotenuse_value(accel, zero_reference)
|
||||
--minetest.chat_send_all(acceleration)
|
||||
local consumed_power = acceleration/40000
|
||||
self._energy = self._energy - consumed_power;
|
||||
end
|
||||
if self._energy <= 0 then
|
||||
self._engine_running = false
|
||||
self._is_flying = 0
|
||||
if self.sound_handle then minetest.sound_stop(self.sound_handle) end
|
||||
--minetest.chat_send_player(self.driver_name, "Out of fuel")
|
||||
else
|
||||
self._last_engine_sound_update = self._last_engine_sound_update + dtime
|
||||
if self._last_engine_sound_update > 0.300 then
|
||||
self._last_engine_sound_update = 0
|
||||
automobiles_lib.engine_set_sound_and_animation(self, longit_speed)
|
||||
end
|
||||
end
|
||||
|
||||
local energy_indicator_angle = automobiles_lib.get_gauge_angle(self._energy)
|
||||
self.fuel_gauge:set_attach(self.object,'',self._fuel_gauge_pos,{x=0,y=0,z=energy_indicator_angle})
|
||||
----------------------------
|
||||
-- end energy consumption --
|
||||
|
||||
--gravity works
|
||||
if not self._is_flying or self._is_flying == 0 then
|
||||
accel.y = -automobiles_lib.gravity
|
||||
else
|
||||
local time_correction = (self.dtime/delorean.ideal_step)
|
||||
local y_accel = self._car_gravity*time_correction
|
||||
accel.y = y_accel --sets the anti gravity
|
||||
end
|
||||
|
||||
if stop ~= true then
|
||||
--self.object:set_velocity(velocity)
|
||||
self.object:add_velocity(vector.multiply(accel,dtime))
|
||||
--self.object:set_acceleration(accel)
|
||||
else
|
||||
if stop == true then
|
||||
self.object:set_acceleration({x=0,y=0,z=0})
|
||||
self.object:set_velocity({x=0,y=0,z=0})
|
||||
end
|
||||
end
|
||||
|
||||
self._last_ground_check = self._last_ground_check + dtime
|
||||
if self._last_ground_check > 0.18 then
|
||||
self._last_ground_check = 0
|
||||
automobiles_lib.ground_get_distances(self, 0.372, 2.6)
|
||||
end
|
||||
local newpitch = self._pitch --velocity.y * math.rad(6)
|
||||
|
||||
local newroll = 0
|
||||
if self._is_flying == 1 then
|
||||
local turn_effect_speed = longit_speed
|
||||
if turn_effect_speed > 10 then turn_effect_speed = 10 end
|
||||
newroll = (-self._steering_angle/100)*(turn_effect_speed/10)
|
||||
if math.abs(self._steering_angle) < 1 then newroll = 0 end
|
||||
|
||||
--pitch
|
||||
local max_pitch = 6
|
||||
local h_vel_compensation = (((longit_speed * 2) * 100)/max_pitch)/100
|
||||
if h_vel_compensation < 0 then h_vel_compensation = 0 end
|
||||
if h_vel_compensation > max_pitch then h_vel_compensation = max_pitch end
|
||||
newpitch = newpitch + (velocity.y * math.rad(max_pitch - h_vel_compensation))
|
||||
end
|
||||
|
||||
self.object:set_rotation({x=newpitch,y=newyaw,z=newroll})
|
||||
|
||||
--saves last velocity for collision detection (abrupt stop)
|
||||
self.lastvelocity = self.object:get_velocity()
|
||||
self._longit_speed = longit_speed
|
||||
|
||||
end,]]--
|
||||
|
||||
on_punch = automobiles_lib.on_punch,
|
||||
on_rightclick = automobiles_lib.on_rightclick,
|
||||
|
||||
@ -387,6 +387,10 @@ function automobiles_lib.on_step(self, dtime)
|
||||
if longit_speed > 2 then dynamic_later_drag = 2.0 end
|
||||
if longit_speed > 8 then dynamic_later_drag = 0.5 end
|
||||
|
||||
if automobiles_lib.extra_drift and longit_speed > 4 then
|
||||
dynamic_later_drag = dynamic_later_drag/(longit_speed*2)
|
||||
end
|
||||
|
||||
local later_drag = vector.multiply(nhdir,later_speed*
|
||||
later_speed*dynamic_later_drag*-1*automobiles_lib.sign(later_speed))
|
||||
|
||||
@ -552,17 +556,22 @@ function automobiles_lib.on_step(self, dtime)
|
||||
if (noded and noded.drawtype ~= 'airlike') then
|
||||
if noded.drawtype ~= 'liquid' then
|
||||
local min_later_speed = self._min_later_speed or 3
|
||||
if (later_speed > min_later_speed or later_speed < -min_later_speed) and
|
||||
self._last_time_drift_snd >= 2.0 then
|
||||
self._last_time_drift_snd = 0
|
||||
minetest.sound_play("automobiles_drifting", {
|
||||
pos = curr_pos,
|
||||
max_hear_distance = 20,
|
||||
gain = 3.0,
|
||||
fade = 0.0,
|
||||
pitch = 1.0,
|
||||
ephemeral = true,
|
||||
})
|
||||
|
||||
if (later_speed > min_later_speed or later_speed < -min_later_speed) then
|
||||
automobiles_lib.add_smoke(curr_pos)
|
||||
if automobiles_lib.extra_drift == false then --disables the sound when playing drift game.. it's annoying
|
||||
if self._last_time_drift_snd >= 2.0 then
|
||||
self._last_time_drift_snd = 0
|
||||
minetest.sound_play("automobiles_drifting", {
|
||||
pos = curr_pos,
|
||||
max_hear_distance = 20,
|
||||
gain = 3.0,
|
||||
fade = 0.0,
|
||||
pitch = 1.0,
|
||||
ephemeral = true,
|
||||
})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local wheel_compensation = longit_speed * (self._wheel_compensation or 1)
|
||||
@ -639,8 +648,12 @@ function automobiles_lib.on_step(self, dtime)
|
||||
local zero_reference = vector.new()
|
||||
local acceleration = automobiles_lib.get_hipotenuse_value(accel, zero_reference)
|
||||
--minetest.chat_send_all(acceleration)
|
||||
local consumed_power = acceleration/40000
|
||||
self._energy = self._energy - consumed_power;
|
||||
if automobiles_lib.is_drift_game == false then
|
||||
local consumed_power = acceleration/40000
|
||||
self._energy = self._energy - consumed_power;
|
||||
else
|
||||
self._energy = 5
|
||||
end
|
||||
end
|
||||
if self._energy <= 0 then
|
||||
self._engine_running = false
|
||||
|
||||
@ -25,6 +25,12 @@ automobiles_lib.gravity = 9.8
|
||||
automobiles_lib.ideal_step = 0.2
|
||||
automobiles_lib.is_creative = minetest.settings:get_bool("creative_mode", false)
|
||||
|
||||
automobiles_lib.is_drift_game = false
|
||||
automobiles_lib.extra_drift = false
|
||||
if minetest.registered_nodes["dg_mapgen:stone"] then
|
||||
automobiles_lib.is_drift_game = true
|
||||
automobiles_lib.extra_drift = true
|
||||
end
|
||||
|
||||
local load_noob_mode = storage:get_int("noob_mode")
|
||||
automobiles_lib.noob_mode = false
|
||||
@ -82,6 +88,20 @@ function automobiles_lib.properties_copy(origin_table)
|
||||
return tablecopy
|
||||
end
|
||||
|
||||
function automobiles_lib.add_smoke(pos)
|
||||
minetest.add_particle({
|
||||
pos = pos,
|
||||
velocity = {x = 0, y = 0, z = 0},
|
||||
acceleration = {x = 0, y = 0, z = 0},
|
||||
expirationtime = 0.25,
|
||||
size = 2.8,
|
||||
collisiondetection = false,
|
||||
collision_removal = false,
|
||||
vertical = false,
|
||||
texture = "automobiles_smoke.png",
|
||||
})
|
||||
end
|
||||
|
||||
--returns 0 for old, 1 for new
|
||||
function automobiles_lib.detect_player_api(player)
|
||||
local player_proterties = player:get_properties()
|
||||
|
||||
@ -1,3 +1,3 @@
|
||||
name = automobiles_lib
|
||||
depends=player_api, biofuel
|
||||
optional_depends=emote
|
||||
depends=player_api
|
||||
optional_depends=emote, biofuel, dg_mapgen
|
||||
|
||||
BIN
automobiles_lib/textures/automobiles_smoke.png
Normal file
BIN
automobiles_lib/textures/automobiles_smoke.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 609 B |
@ -430,8 +430,12 @@ minetest.register_entity("automobiles_motorcycle:motorcycle", {
|
||||
local zero_reference = vector.new()
|
||||
local acceleration = automobiles_lib.get_hipotenuse_value(accel, zero_reference)
|
||||
--minetest.chat_send_all(acceleration)
|
||||
local consumed_power = acceleration/100000
|
||||
self._energy = self._energy - consumed_power;
|
||||
if automobiles_lib.is_drift_game == false then
|
||||
local consumed_power = acceleration/100000
|
||||
self._energy = self._energy - consumed_power;
|
||||
else
|
||||
self._energy = 5
|
||||
end
|
||||
end
|
||||
if self._energy <= 0 then
|
||||
self._engine_running = false
|
||||
|
||||
@ -363,6 +363,8 @@ minetest.register_entity("automobiles_trans_am:trans_am", {
|
||||
_max_speed = 40,
|
||||
_min_later_speed = 4.5,
|
||||
|
||||
_wheel_compensation = 0.8,
|
||||
|
||||
get_staticdata = automobiles_lib.get_staticdata,
|
||||
|
||||
on_deactivate = function(self)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user