]> git.lizzy.rs Git - crafter_client.git/commitdiff
Add fire animation when player is on fire
authoroilboi <47129783+oilboi@users.noreply.github.com>
Sun, 7 Jun 2020 15:35:47 +0000 (11:35 -0400)
committeroilboi <47129783+oilboi@users.noreply.github.com>
Sun, 7 Jun 2020 15:35:47 +0000 (11:35 -0400)
fire_handling.lua [new file with mode: 0644]
init.lua
version_send.lua

diff --git a/fire_handling.lua b/fire_handling.lua
new file mode 100644 (file)
index 0000000..d4a6cd1
--- /dev/null
@@ -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)
\ No newline at end of file
index c61eb85a8ab68833d116bd1529a96f73cd88b4f7..bf07b14318bd3caefadb2a6d0439559ab18c45f5 100644 (file)
--- a/init.lua
+++ b/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
index 06d7e786a5018db4aefd63cc559ea46801d4129a..cffcfebefb3dff43d9644017adc1b93a41bcccf4 100644 (file)
@@ -1,3 +1,3 @@
 minetest.after(0,function()
-    version_channel:send_all("0.5002")
+    version_channel:send_all("0.5003")
 end)
\ No newline at end of file