2023-10-13 06:48:11 +00:00
|
|
|
local utils = load_file("util_misc")
|
|
|
|
|
2023-10-12 14:19:11 +00:00
|
|
|
local walk_speed = 1
|
2023-10-16 19:58:52 +00:00
|
|
|
local walk_time = 4
|
2023-10-12 14:19:11 +00:00
|
|
|
local speedup_time = 6
|
2023-10-16 19:58:52 +00:00
|
|
|
local run_factor = 2.5
|
|
|
|
local slowdown_factor = 12
|
2023-10-12 14:19:11 +00:00
|
|
|
local jump_height = 1
|
2023-10-16 19:58:52 +00:00
|
|
|
local jump_factor = 1.4
|
2023-10-12 14:19:11 +00:00
|
|
|
|
|
|
|
local speed_data = {}
|
|
|
|
|
|
|
|
local function handle_speed (player, delta_time)
|
2023-10-13 06:48:11 +00:00
|
|
|
utils.handle_player(player, function (player, p_data)
|
|
|
|
speed_data[player] = speed_data[player] or {}
|
|
|
|
local data = speed_data[player]
|
|
|
|
|
|
|
|
data.duration = (data.duration or 0) + delta_time
|
|
|
|
|
|
|
|
local control = p_data.control
|
|
|
|
local moving = control.up or control.down or control.left or control.right
|
|
|
|
if not moving then
|
|
|
|
data.duration = data.duration - delta_time * (slowdown_factor + 1)
|
|
|
|
end
|
|
|
|
if data.duration < 0 then data.duration = 0 end
|
|
|
|
if data.duration > walk_time + speedup_time then data.duration = walk_time + speedup_time end
|
|
|
|
|
|
|
|
if data.duration < walk_time then
|
|
|
|
p_data.physics.speed = walk_speed
|
|
|
|
p_data.physics.jump = jump_height
|
|
|
|
else
|
|
|
|
local run_time = data.duration - walk_time
|
|
|
|
local t = run_time / speedup_time
|
|
|
|
|
|
|
|
local factor = (run_factor - 1) * t + 1
|
|
|
|
if factor > run_factor then factor = run_factor end
|
|
|
|
|
|
|
|
p_data.physics.speed = walk_speed * factor
|
|
|
|
p_data.physics.jump = jump_height + (jump_height * jump_factor - 1) * t
|
|
|
|
end
|
|
|
|
end)
|
2023-10-12 14:19:11 +00:00
|
|
|
end
|
|
|
|
|
2023-10-13 07:31:55 +00:00
|
|
|
blockgame.register_globalstep(function(delta_time)
|
2023-10-12 14:19:11 +00:00
|
|
|
for _, player in pairs(minetest.get_connected_players()) do
|
|
|
|
handle_speed(player, delta_time)
|
|
|
|
end
|
|
|
|
end)
|