]> git.lizzy.rs Git - crafter_client.git/blobdiff - fire_handling.lua
Add fire animation when player is on fire
[crafter_client.git] / fire_handling.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