From 737bde8ba43dae322fc5d4d8648add88c402df23 Mon Sep 17 00:00:00 2001 From: oilboi <47129783+oilboi@users.noreply.github.com> Date: Sun, 19 Apr 2020 07:32:00 -0400 Subject: [PATCH] Add slightly better nether teleport animation --- nether.lua | 62 +++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 47 insertions(+), 15 deletions(-) diff --git a/nether.lua b/nether.lua index 7489fe3..43720f5 100644 --- a/nether.lua +++ b/nether.lua @@ -3,6 +3,7 @@ local hud_id = nil --foreground (portal) local hud_bg_id = nil --black background +local nether_id = nil --the nether incoming local cool_off_timer = 0 --use this to stop players teleporting back and forth local init_sound = nil local teleport_sound = nil @@ -39,12 +40,18 @@ minetest.register_globalstep(function(dtime) scale = {x=-1, y=-1}, -- default {x=0,y=0} text = "nether_portal_gui.png", -- default "" }) + nether_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=0, y=0}, -- default {x=0,y=0} + text = "darkness.png", -- default "" + }) init_sound = minetest.sound_play("portal_initialize",{gain=0,pitch=math.random(70,90)/100}) minetest.sound_fade(init_sound, 0.34, 1) else --make the hud zoom in - local scale = minetest.localplayer:hud_get(hud_id).scale.x if scale > -100 then scale = scale - ((scale/-(1/dtime))*2) @@ -62,24 +69,49 @@ minetest.register_globalstep(function(dtime) minetest.sound_fade(teleport_sound, -0.1, 0) teleport_sound = nil end - --make the hud zoom out - local scale = minetest.localplayer:hud_get(hud_id).scale.x - if scale < -1 then - scale = scale + ((scale/-(1/dtime))*2) - elseif scale > -1 then - scale = -1 - end - minetest.localplayer:hud_change(hud_id, "scale", {x=scale,y=scale}) - - if scale == -1 then - minetest.localplayer:hud_remove(hud_bg_id) - minetest.localplayer:hud_remove(hud_id) - hud_bg_id = nil - hud_id = nil + --player left portal before teleporting + if cool_off_timer == 0 then + --make the hud zoom out + local scale = minetest.localplayer:hud_get(hud_id).scale.x + if scale < -1 then + scale = scale + ((scale/-(1/dtime))*2) + elseif scale > -1 then + scale = -1 + end + minetest.localplayer:hud_change(hud_id, "scale", {x=scale,y=scale}) + + if scale == -1 then + minetest.localplayer:hud_remove(hud_bg_id) + minetest.localplayer:hud_remove(hud_id) + minetest.localplayer:hud_remove(nether_id) + nether_id = nil + hud_bg_id = nil + hud_id = nil + end + --teleport complete animation + else + local scale = minetest.localplayer:hud_get(nether_id).scale.x + if scale == 0 then scale = -1 end + if scale > -100 then + scale = scale - ((scale/-(1/dtime))*2) + elseif scale < -100 then + scale = -100 + end + minetest.localplayer:hud_change(nether_id, "scale", {x=scale,y=scale}) + if scale == -100 then + minetest.localplayer:hud_remove(hud_bg_id) + minetest.localplayer:hud_remove(hud_id) + minetest.localplayer:hud_remove(nether_id) + nether_id = nil + hud_bg_id = nil + hud_id = nil + end end elseif hud_bg_id and hud_id then minetest.localplayer:hud_remove(hud_bg_id) minetest.localplayer:hud_remove(hud_id) + minetest.localplayer:hud_remove(nether_id) + nether_id = nil hud_bg_id = nil hud_id = nil end -- 2.44.0