Add fire animation when player is on fire
parent
1ea84788f3
commit
711145f4f6
|
@ -0,0 +1,39 @@
|
|||
local on_fire = 0
|
||||
local fire_id = nil
|
||||
local fire_animation_timer = 0
|
||||
local fire_animation_tile = 0
|
||||
--receive the server states
|
||||
minetest.register_on_modchannel_message(function(channel_name, sender, message)
|
||||
if channel_name == name..":fire_state" then
|
||||
on_fire = tonumber(message)
|
||||
end
|
||||
end)
|
||||
|
||||
minetest.register_globalstep(function(dtime)
|
||||
if on_fire == 0 then
|
||||
if fire_id then
|
||||
minetest.localplayer:hud_remove(fire_id)
|
||||
fire_id = nil
|
||||
end
|
||||
elseif on_fire == 1 then
|
||||
if fire_id == nil then
|
||||
fire_id = minetest.localplayer:hud_add({
|
||||
hud_elem_type = "image", -- see HUD element types, default "text"
|
||||
position = {x=0.5, y=0.5},
|
||||
name = "", -- default ""
|
||||
scale = {x=-100, y=-100}, -- default {x=0,y=0}
|
||||
text = "fire.png^[opacity:180^[verticalframe:8:"..fire_animation_tile,
|
||||
})
|
||||
else
|
||||
fire_animation_timer = fire_animation_timer + dtime
|
||||
if fire_animation_timer >= 0.05 then
|
||||
fire_animation_timer = 0
|
||||
fire_animation_tile = fire_animation_tile + 1
|
||||
if fire_animation_tile > 7 then
|
||||
fire_animation_tile = 0
|
||||
end
|
||||
minetest.localplayer:hud_change(fire_id, "text", "fire.png^[opacity:180^[verticalframe:8:"..fire_animation_tile)
|
||||
end
|
||||
end
|
||||
end
|
||||
end)
|
5
init.lua
5
init.lua
|
@ -7,6 +7,7 @@ nether = nil
|
|||
aether = nil
|
||||
name = nil
|
||||
version_channel = nil
|
||||
fire_handling_channel = nil
|
||||
|
||||
function initialize_all()
|
||||
--declare globals for now
|
||||
|
@ -17,7 +18,8 @@ function initialize_all()
|
|||
nether = minetest.mod_channel_join(name..":nether_teleporters")
|
||||
aether = minetest.mod_channel_join(name..":aether_teleporters")
|
||||
version_channel = minetest.mod_channel_join(name..":client_version_channel")
|
||||
|
||||
fire_handling_channel = minetest.mod_channel_join(name..":fire_state")
|
||||
|
||||
--next we load everything seperately because it's easier to work on individual files than have everything jammed into one file
|
||||
--not into seperate mods because that is unnecessary and cumbersome
|
||||
local path = minetest.get_modpath("crafter_client")
|
||||
|
@ -30,6 +32,7 @@ function initialize_all()
|
|||
dofile(path.."/music_handling.lua")
|
||||
dofile(path.."/version_send.lua")
|
||||
dofile(path.."/colored_names/colored_names.lua")
|
||||
dofile(path.."/fire_handling.lua")
|
||||
end
|
||||
|
||||
--we must delay initialization until the player exists in the world
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
minetest.after(0,function()
|
||||
version_channel:send_all("0.5002")
|
||||
version_channel:send_all("0.5003")
|
||||
end)
|
Loading…
Reference in New Issue