add HUD element that indicates time from last push with a colored icon (red -> green)
This commit is contained in:
parent
30d9bfd569
commit
dd1cb38204
71
items.lua
71
items.lua
@ -5,6 +5,7 @@ local allow_swap_distance = sumo.allow_swap_distance -- if an opponent is within
|
||||
local stick_pointing_distance = sumo.stick_pointing_distance
|
||||
local stick_push_timeout = sumo.stick_push_timeout --(float)--in seconds
|
||||
sumo.timeouts={}
|
||||
sumo.push_hud = {}
|
||||
|
||||
|
||||
|
||||
@ -39,14 +40,13 @@ minetest.register_craftitem("sumo:pushstick", {
|
||||
time_factor = 4
|
||||
elseif time_from_last_push >= 0.4 and time_from_last_push < 0.5 then
|
||||
time_factor = 9
|
||||
elseif time_from_last_push >= 0.5 and time_from_last_push < 0.6 then
|
||||
elseif time_from_last_push >= 0.5 and time_from_last_push < 0.7 then
|
||||
time_factor = 14
|
||||
|
||||
elseif time_from_last_push > 0.7 then
|
||||
time_factor = 20
|
||||
elseif time_from_last_push > 2.0 then
|
||||
time_factor = 25
|
||||
elseif time_from_last_push > 4.0 then
|
||||
time_factor = 30
|
||||
end
|
||||
force = stick_knockback + time_factor
|
||||
end
|
||||
@ -62,8 +62,10 @@ minetest.register_craftitem("sumo:pushstick", {
|
||||
|
||||
if pointed_thing == nil then return end
|
||||
if pointed_thing.type == 'node' then return end
|
||||
if not pointed_thing.type == 'object' then return end
|
||||
|
||||
if pointed_thing.type == 'object' then
|
||||
|
||||
--this only works on players
|
||||
if minetest.is_player(pointed_thing.ref) == true then
|
||||
|
||||
@ -80,6 +82,7 @@ minetest.register_craftitem("sumo:pushstick", {
|
||||
if not sumo.invincible[pointed_name] then
|
||||
pointed_thing.ref:move_to(hitter_pos, true)
|
||||
pointed_thing.ref:add_player_velocity(vector.multiply({x = -dir.x, y = dir.y, z= -dir.z}, (force + 1)* 0.6 )) --switch positions, and throw the target with 0.6X normal force
|
||||
sumo.timeouts[p_name] = current_time
|
||||
local sound = 'swish'..math.random(1,4)
|
||||
minetest.sound_play(sound, {
|
||||
to_player = pointed_thing.ref:get_player_name(),
|
||||
@ -93,6 +96,7 @@ minetest.register_craftitem("sumo:pushstick", {
|
||||
local pointed_name = pointed_thing.ref:get_player_name()
|
||||
if not sumo.invincible[pointed_name] then
|
||||
pointed_thing.ref:add_player_velocity(vector.multiply(dir, force))
|
||||
sumo.timeouts[p_name] = current_time
|
||||
|
||||
local sound = 'thwack2' --TODO: get the other 2 thwack souds into the game (where did they go anyways?!)
|
||||
minetest.sound_play(sound, {
|
||||
@ -117,7 +121,7 @@ minetest.register_craftitem("sumo:pushstick", {
|
||||
|
||||
end
|
||||
end
|
||||
sumo.timeouts[p_name] = current_time
|
||||
|
||||
|
||||
|
||||
end,
|
||||
@ -171,3 +175,62 @@ minetest.register_craftitem("sumo:pushstick", {
|
||||
|
||||
|
||||
|
||||
--HUD indicator for sumo pushstick strength (color based)
|
||||
|
||||
minetest.register_globalstep(function(dtime)
|
||||
|
||||
for _,player in ipairs(minetest.get_connected_players()) do
|
||||
local pl_name = player:get_player_name()
|
||||
local inv = player:get_inventory()
|
||||
local stack = ItemStack("sumo:pushstick")
|
||||
if inv:contains_item('main', stack) then
|
||||
local last_push_time = sumo.timeouts[pl_name] or 0.0
|
||||
local current_time = minetest.get_us_time()/1000000.0
|
||||
local time_from_last_push = current_time-last_push_time
|
||||
local push_color = "#ff000088" --bright red
|
||||
if time_from_last_push >= 0.3 and time_from_last_push < 0.4 then
|
||||
push_color = "#ff150088" --orange red
|
||||
elseif time_from_last_push >= 0.4 and time_from_last_push < 0.5 then
|
||||
push_color = "#ff330088" --orange
|
||||
elseif time_from_last_push >= 0.5 and time_from_last_push < 0.7 then
|
||||
push_color = "#f2ff0088" --yellow
|
||||
elseif time_from_last_push >= 0.7 then
|
||||
push_color = "#8cff0088" --yellow green
|
||||
elseif time_from_last_push >= 2.0 then
|
||||
push_color = "#66ff0088" --green
|
||||
|
||||
end
|
||||
--Thank you, ElCeejo, for giving this HUD code that *actually* works :P
|
||||
if not sumo.push_hud[pl_name] then
|
||||
sumo.push_hud[pl_name] =player:hud_add({
|
||||
hud_elem_type = "image",
|
||||
position = {x = 0, y = 1},
|
||||
name = "sumo_hud_push",
|
||||
text = "sumo_hud_push.png^[colorize:"..push_color,
|
||||
scale = {x = 3, y = 3},
|
||||
alignment = {x = 1, y = -1},
|
||||
offset = {x = 0, y = -5}
|
||||
})
|
||||
else
|
||||
player:hud_change(sumo.push_hud[pl_name], "text", "sumo_hud_push.png^[colorize:"..push_color)
|
||||
end
|
||||
else
|
||||
if sumo.push_hud[pl_name] then
|
||||
player:hud_remove(sumo.push_hud[pl_name])
|
||||
sumo.push_hud[pl_name] = nil
|
||||
end
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -38,6 +38,7 @@ arena_lib.on_load("sumo", function(arena)
|
||||
arena_lib.HUD_send_msg_all("title", arena, "Fight!", 1,nil,0x00FF00)
|
||||
|
||||
local item = ItemStack("sumo:pushstick")
|
||||
|
||||
|
||||
for pl_name, stats in pairs(arena.players) do
|
||||
sumo.invincible[pl_name] = false
|
||||
@ -134,6 +135,9 @@ arena_lib.on_time_tick('sumo', function(arena)
|
||||
|
||||
end)
|
||||
|
||||
|
||||
|
||||
|
||||
minetest.register_on_player_hpchange(function(player, hp_change)
|
||||
local pl_name = player:get_player_name()
|
||||
if arena_lib.is_player_in_arena(pl_name, 'sumo') then
|
||||
|
Loading…
x
Reference in New Issue
Block a user