add HUD jump

This commit is contained in:
MisterE123 2021-02-04 22:47:02 +00:00
parent dd1cb38204
commit 4ef5b95b29
2 changed files with 57 additions and 27 deletions

View File

@ -1,11 +1,13 @@
local stick_knockback = sumo.stick_knockback --multiplier for how hard the stick hits
local stick_vault_reach = sumo.stick_vault_reach -- how close to the pointed node must the player be to vault
local stick_vault_timeout = sumo.stick_vault_timeout -- int timer for how long the vault cannot be used after it is used
local stick_vault_timeout = sumo.stick_vault_timeout --(float)--in seconds
local allow_swap_distance = sumo.allow_swap_distance -- if an opponent is within this distance, then if the player uses the pushstick with the shift key pressed, the players switch positions.
local stick_pointing_distance = sumo.stick_pointing_distance
local stick_push_timeout = sumo.stick_push_timeout --(float)--in seconds
sumo.timeouts={}
sumo.jumpouts = {}
sumo.push_hud = {}
sumo.jump_hud = {}
@ -25,10 +27,6 @@ minetest.register_craftitem("sumo:pushstick", {
local last_push_time = sumo.timeouts[p_name] or 0.0
local current_time = minetest.get_us_time()/1000000.0
-- if last_push_time == nil then
-- last_push_time = 0.0
-- end
--minetest.chat_send_all('difference = '..current_time-last_push_time)
local time_from_last_push = current_time-last_push_time
@ -128,30 +126,23 @@ minetest.register_craftitem("sumo:pushstick", {
on_place = function(itemstack, placer, pointed_thing)
local keys = placer:get_player_control()
local user_name = placer:get_player_name()
if pointed_thing == nil then return end
if sumo.invincible[pl_name] then return end
local first_use = false
local imeta = itemstack:get_meta()
local old_time = imeta:get_int('old_time')
local current_time = minetest.get_gametime()
if old_time == 0 or old_time == nil then
first_use = true
end
--lets implement the speed boost in the minigame arena, not here.
local p_name = placer:get_player_name()
local last_jump_time = sumo.jumpouts[p_name] or 0.0
local current_time = minetest.get_us_time()/1000000.0 --microsec converted to sec
local time_from_last_jump = current_time-last_jump_time
if pointed_thing.type == 'node' then
if vector.distance(pointed_thing.under, placer:get_pos()) < stick_vault_reach then
if first_use or current_time > old_time + stick_vault_timeout then
if last_jump_time == 0.0 or time_from_last_jump >= stick_vault_timeout then
local lookvect = placer:get_look_dir()
local pushvect = vector.normalize( {x=lookvect.x, z=lookvect.z, y= math.sqrt(1-(lookvect.y*lookvect.y))})
--gives a unit vector that is 90 deg offset in the vert direction
local force = 10 * vector.length(vector.normalize( {x=lookvect.x, z=lookvect.z, y= 0}))
sumo.jumpouts[p_name] = current_time
placer:add_player_velocity(vector.multiply(pushvect, force))
--update the staff time for next check
local sound = 'jump'..math.random(1,2)
@ -160,9 +151,6 @@ minetest.register_craftitem("sumo:pushstick", {
max_hear_distance = 10,
gain = 10.0,
})
imeta:set_int('old_time', current_time)
return itemstack
end
end
end
@ -184,6 +172,8 @@ minetest.register_globalstep(function(dtime)
local inv = player:get_inventory()
local stack = ItemStack("sumo:pushstick")
if inv:contains_item('main', stack) then
--Push HUD
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
@ -200,6 +190,8 @@ minetest.register_globalstep(function(dtime)
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({
@ -209,16 +201,54 @@ minetest.register_globalstep(function(dtime)
text = "sumo_hud_push.png^[colorize:"..push_color,
scale = {x = 3, y = 3},
alignment = {x = 1, y = -1},
offset = {x = 0, y = -5}
offset = {x = 5, y = -5}
})
else
player:hud_change(sumo.push_hud[pl_name], "text", "sumo_hud_push.png^[colorize:"..push_color)
end
--Jump HUD
local last_jump_time = sumo.jumpouts[pl_name] or 0.0
local current_time = minetest.get_us_time()/1000000.0 --microsec converted to sec
local time_from_last_jump = current_time-last_jump_time
local jump_color = "#ff000088" --red
if last_jump_time == 0.0 or time_from_last_jump >= stick_vault_timeout then --jump *would* work now
jump_color = "#66ff0088" --green
end
if not sumo.jump_hud[pl_name] then
sumo.jump_hud[pl_name] =player:hud_add({
hud_elem_type = "image",
position = {x = 0, y = 1},
name = "sumo_hud_jump",
text = "sumo_hud_jump.png^[colorize:"..jump_color,
scale = {x = 3, y = 3},
alignment = {x = 1, y = -1},
offset = {x = 75, y = -5}
})
else
player:hud_change(sumo.jump_hud[pl_name], "text", "sumo_hud_jump.png^[colorize:"..jump_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
if sumo.jump_hud then
player:hud_remove(sumo.jump_hud[pl_name])
sumo.jump_hud[pl_name] = nil
end
end
end
end)

View File

@ -8,13 +8,13 @@ sumo.player_jump = 1.3
sumo.movement_timeout = 5
--------------------------------------
--the base value of how hard the stick hits, though hit force may be up to 30 more than this
sumo.stick_knockback = 10
sumo.stick_knockback = 25
--------------------------------------
-- how close to the pointed node must the player be to vault
sumo.stick_vault_reach = 3
--------------------------------------
-- int timer for how long the vault cannot be used after it is used
sumo.stick_vault_timeout = 1
-- timer for how long the vault cannot be used after it is used
sumo.stick_vault_timeout = 1.0 --(float)--in seconds
--------------------------------------
-- if an opponent is within this distance, then if the player uses the pushstick with the shift key pressed, the players switch positions.
sumo.allow_swap_distance = 6