aboutsummaryrefslogtreecommitdiff
path: root/trainhud.lua
diff options
context:
space:
mode:
authororwell96 <mono96.mml@gmail.com>2016-05-29 20:27:30 +0200
committerorwell96 <mono96.mml@gmail.com>2016-05-29 20:27:30 +0200
commit2c864564d25eb1b30a359f62a8dcf9508cf7f104 (patch)
treed62d3f99183646b6faa56b0ce6e3a701de2a0626 /trainhud.lua
downloadadvtrains-2c864564d25eb1b30a359f62a8dcf9508cf7f104.tar.gz
advtrains-2c864564d25eb1b30a359f62a8dcf9508cf7f104.tar.bz2
advtrains-2c864564d25eb1b30a359f62a8dcf9508cf7f104.zip
created git repository
Diffstat (limited to 'trainhud.lua')
-rw-r--r--trainhud.lua56
1 files changed, 56 insertions, 0 deletions
diff --git a/trainhud.lua b/trainhud.lua
new file mode 100644
index 0000000..b64c81c
--- /dev/null
+++ b/trainhud.lua
@@ -0,0 +1,56 @@
+
+advtrains.hud = {}
+
+minetest.register_on_leaveplayer(function(player)
+advtrains.hud[player:get_player_name()] = nil
+end)
+
+function advtrains.set_trainhud(name, text)
+ local hud = advtrains.hud[name]
+ local player=minetest.get_player_by_name(name)
+ if not hud then
+ hud = {}
+ advtrains.hud[name] = hud
+ hud.id = player:hud_add({
+ hud_elem_type = "text",
+ name = "ADVTRAINS",
+ number = 0xFFFFFF,
+ position = {x=0.5, y=0.7},
+ offset = {x=0, y=0},
+ text = text,
+ scale = {x=200, y=60},
+ alignment = {x=0, y=0},
+ })
+ hud.oldText=text
+ return
+ elseif hud.oldText ~= text then
+ player:hud_change(hud.id, "text", text)
+ hud.oldText=text
+ end
+end
+function advtrains.hud_train_format(train, flip)
+ local fct=1
+ if flip then fct=-1 end
+ if not train then return "" end
+ local max=advtrains.all_traintypes[train.traintype].max_speed or 10
+ local vel=math.ceil(train.velocity)*fct
+ local tvel=math.ceil(train.tarvelocity)*fct
+ local firstLine, secondLine
+ if vel<0 then
+ firstLine="Speed: <"..string.rep("_", vel+max)..string.rep("+", -vel).."|"..string.rep("_", max)..">"
+ else
+ firstLine="Speed: <"..string.rep("_", max).."|"..string.rep("+", vel)..string.rep("_", max-vel)..">"
+ end
+ if tvel<0 then
+ secondLine="Target: <"..string.rep("_", tvel+max)..string.rep("+", -tvel).."|"..string.rep("_", max)..">"
+ else
+ secondLine="Target: <"..string.rep("_", max).."|"..string.rep("+", tvel)..string.rep("_", max-tvel)..">"
+ end
+ if vel==0 then
+ return firstLine.."\n"..secondLine.."\nup for forward, down for backward, use to get off train. "
+ elseif vel<0 then
+ return firstLine.."\n"..secondLine.."\nPress up to decelerate, down to accelerate, sneak to stop."
+ elseif vel>0 then
+ return firstLine.."\n"..secondLine.."\nPress up to accelerate, down to decelerate, sneak to stop."
+ end
+end \ No newline at end of file