Compare commits

...

2 Commits

Author SHA1 Message Date
Lizzy Fleckenstein 7e31e4cea6 Add support for fire HUD 2021-09-18 22:30:45 +02:00
Lizzy Fleckenstein ed8cfb2c66 Add sprinting with double-W 2021-03-05 09:25:30 +01:00
3 changed files with 132 additions and 0 deletions

55
fire.lua Normal file
View File

@ -0,0 +1,55 @@
local hud
local channel_name
local frame
local total_frames = 8
local frame_timer
local function set_texture(texture)
if hud then
minetest.localplayer:hud_change(hud, "text", texture)
end
end
minetest.register_on_modchannel_message(function(cname, sender, message)
if sender == "" and cname == channel_name then
if message == "start" then
if not frame_timer then
frame = 0
frame_timer = 0
end
elseif message == "stop" then
frame_timer = nil
set_texture("blank.png")
else
total_frames = tonumber(message) or 8
end
end
end)
minetest.register_globalstep(function(dtime)
local player = minetest.localplayer
if player and not hud then
hud = player:hud_add({
hud_elem_type = "image",
position = {x = 0.5, y = 0.5},
scale = {x = -100, y = -100},
text = "blank.png",
z_index = 1000,
})
channel_name = "mcl_burning:" .. player:get_name()
minetest.mod_channel_join(channel_name)
end
if frame_timer then
frame_timer = frame_timer - dtime
if frame_timer <= 0 then
frame_timer = 1.0 / total_frames
frame = (frame + 1) % total_frames
set_texture("mcl_burning_hud_flame_animated.png^[opacity:180^[verticalframe:" .. total_frames .. ":" .. frame)
end
end
end)

View File

@ -1 +1,6 @@
local modname = minetest.get_current_modname()
local modpath = minetest.get_modpath(modname)
for _, f in ipairs{"sprint", "fire"} do
dofile(modpath .. "/" .. f .. ".lua")
end

72
sprint.lua Normal file
View File

@ -0,0 +1,72 @@
-- set up our initial values
local running = false
local run_discharge_timer = 0
local old_up = false
local channel
local channel_name
-- receive the server states
minetest.register_on_modchannel_message(function(cname, sender, message)
if sender == "" and cname == channel_name then
running = false
run_discharge_timer = 0
end
end)
-- check player's input on the "up" key
minetest.register_globalstep(function(dtime)
local player = minetest.localplayer
if not player then
return
elseif not channel then
channel_name = "mcl_sprint:" .. player:get_name()
channel = minetest.mod_channel_join(channel_name)
end
local old_running = running
local control = player:get_control()
local velocity = player:get_velocity()
local last_velocity = player:get_last_velocity()
-- cancel running if the player bumps into something
if running and (velocity.x == 0 and last_velocity.x ~= 0 or velocity.z == 0 and last_velocity.z ~= 0) then
running = false
run_discharge_timer = 0
end
-- reset the run flag
if running and (not control.up or control.sneak or control.down) then
running = false
end
-- half second window to double tap running
if run_discharge_timer > 0 then
run_discharge_timer = run_discharge_timer - dtime
-- initialize double tap run
if not old_up and control.up == true and velocity.x ~= 0 and velocity.z ~= 0 then
run_discharge_timer = 0
running = true
end
end
-- check if new input of walking forwards
if control.up and not control.down and not control.sneak and not old_up and not running and run_discharge_timer <= 0 then
run_discharge_timer = 0.2
end
-- add this here so the player can sneak
if control.sneak then
running = false
run_discharge_timer = 0
end
-- only send if state has changed
if running ~= old_running then
channel:send_all(running and "true" or "false")
end
old_up = control.up
end)