Add chests, doors, and levers, and improve progressive interaction.
This commit is contained in:
parent
6439f11c2f
commit
8f98a7fa2d
18 changed files with 692 additions and 107 deletions
|
|
@ -67,9 +67,13 @@ Player = setmetatable({
|
|||
local yaw = p:get_look_horizontal()
|
||||
local pitch = p:get_look_vertical()
|
||||
local dir = p:get_look_dir()
|
||||
local vel = p:get_velocity()
|
||||
local speed = vel:length()
|
||||
m.pos = pos
|
||||
m.pos.y = m.pos.y +m.eye_height
|
||||
|
||||
-- MARK: Pointing callbacks
|
||||
|
||||
local pointed_found = nil
|
||||
m.pointed_node = nil
|
||||
for x in minetest.raycast(m.pos, m.pos +(dir *5)) do
|
||||
|
|
@ -83,22 +87,26 @@ Player = setmetatable({
|
|||
m.pointed_obj:on_unhover(m)
|
||||
end
|
||||
if m.pointed_obj.on_interact and m.interaction_marker then
|
||||
m.interaction_marker:remove()
|
||||
m.object:hud_remove(m.interaction_marker)
|
||||
m.interaction_marker = nil
|
||||
m.interaction_start = nil
|
||||
end
|
||||
end
|
||||
if e.on_interact and not e._no_interact and (not names_match or names_match and not m.interaction_marker) then
|
||||
if m.interaction_marker then m.object:hud_remove(m.interaction_marker) end
|
||||
local dst = e.object:get_pos()
|
||||
if e._interact_marker_offset then dst = dst +e:_interact_marker_offset() end
|
||||
m.interaction_marker = m.object:hud_add {
|
||||
type = "image_waypoint",
|
||||
world_pos = dst,
|
||||
scale = {x=3, y=3},
|
||||
text = "artifact_rmb.png"
|
||||
}
|
||||
end
|
||||
if (m.pointed_obj and not names_match and e.on_hover) or not m.pointed_obj then
|
||||
if e.on_hover then
|
||||
e:on_hover(m)
|
||||
end
|
||||
if e.on_interact then
|
||||
if m.interaction_marker then m.interaction_marker:remove() end
|
||||
m.interaction_marker = minetest.add_entity(e.object:get_pos(), "display")
|
||||
m.interaction_marker:set_properties {
|
||||
visual = "sprite",
|
||||
textures = {"artifact_rmb.png"}
|
||||
}
|
||||
end
|
||||
pointed_found = true
|
||||
m.pointed_obj = e
|
||||
break
|
||||
|
|
@ -109,6 +117,18 @@ Player = setmetatable({
|
|||
end
|
||||
elseif x and x.type == "node" then
|
||||
m.pointed_node = x
|
||||
if m.pointed_obj then
|
||||
if m.pointed_obj.on_unhover then
|
||||
m.pointed_obj:on_unhover(m)
|
||||
end
|
||||
if m.pointed_obj.on_interact and m.interaction_marker then
|
||||
m.object:hud_remove(m.interaction_marker)
|
||||
m.interaction_marker = nil
|
||||
m.interaction_start = nil
|
||||
end
|
||||
m.pointed_obj = nil
|
||||
end
|
||||
break
|
||||
end
|
||||
end
|
||||
if not pointed_found and m.pointed_obj then
|
||||
|
|
@ -116,52 +136,89 @@ Player = setmetatable({
|
|||
m.pointed_obj:on_unhover(m)
|
||||
end
|
||||
if m.pointed_obj.on_interact and m.interaction_marker then
|
||||
m.interaction_marker:remove()
|
||||
m.object:hud_remove(m.interaction_marker)
|
||||
m.interaction_marker = nil
|
||||
m.interaction_start = nil
|
||||
end
|
||||
m.pointed_obj = nil
|
||||
end
|
||||
local ctl = m.object:get_player_control()
|
||||
|
||||
if ctl.place and not m.ctl.place and m.pointed_obj and m.pointed_obj.on_interact then
|
||||
-- MARK: Animations
|
||||
|
||||
local moving = (ctl.up or ctl.down or ctl.left or ctl.right) and speed > 0.1
|
||||
if moving then
|
||||
m.moving = true
|
||||
if ctl.aux1 and ctl.up then
|
||||
if p:get_animation().y ~= 2 then p:set_animation({x=1, y=2}, 1.5, 0.2, true) end
|
||||
p:set_physics_override{
|
||||
speed = 1.5
|
||||
}
|
||||
else
|
||||
if p:get_animation().y ~= 1 then p:set_animation({x=0, y=1}, 1.5, 0.2, true) end
|
||||
p:set_physics_override{
|
||||
speed = 1
|
||||
}
|
||||
end
|
||||
else
|
||||
m.moving = false
|
||||
if p:get_animation().y ~= 0 then p:set_animation({x=0, y=0}) end
|
||||
end
|
||||
|
||||
if not m.rot then m.rot = 0 end
|
||||
if moving then
|
||||
local fac = 0
|
||||
if ctl.left then fac = 30 elseif ctl.right then fac = -30 end
|
||||
m.rot = yaw +math.rad(fac)
|
||||
elseif math.abs(yaw -m.rot) > math.rad(40) then
|
||||
m.rot = m.rot +(yaw -(m.yaw or 0))
|
||||
end
|
||||
m.rot = m.rot %(math.pi *2)
|
||||
|
||||
p:set_bone_override("Head", {
|
||||
rotation = {vec = vector.new(math.min(math.max(pitch, math.rad(-60)), math.rad(60)),-(yaw -m.rot),0), interpolation = 0.1, absolute = true}
|
||||
})
|
||||
|
||||
p:set_bone_override("root", {
|
||||
rotation = {vec = vector.new(0,yaw -m.rot,0), interpolation = 0.1, absolute = true}
|
||||
})
|
||||
|
||||
-- MARK: Progressive interaction
|
||||
|
||||
if ctl.place and m.ctl.place and m.pointed_obj and m.pointed_obj.on_interact and not m.pointed_obj._no_interact then
|
||||
if not m.interaction_start then
|
||||
m.interaction_start = time
|
||||
-- m.interaction_marker = minetest.add_entity(m.pointed_obj, "display")
|
||||
-- m.interaction_marker:set_properties {
|
||||
-- visual = "sprite",
|
||||
-- textures = {"rgt_interact_progress_0.png"}
|
||||
-- }
|
||||
else
|
||||
if time -m.interaction_start > 1100000 then
|
||||
m.interaction_marker:remove()
|
||||
local duration = (m.pointed_obj._interact_time or 1) *1000000
|
||||
local progress = (time -m.interaction_start) /duration
|
||||
if progress > 1.1 then
|
||||
m.pointed_obj:on_interact(m)
|
||||
elseif time -m.interaction_start > 1000000 then
|
||||
m.interaction_marker:set_properties {
|
||||
textures = {"artifact_rmb_100.png"}
|
||||
}
|
||||
elseif time -m.interaction_start > 750000 then
|
||||
m.interaction_marker:set_properties {
|
||||
textures = {"artifact_rmb_75.png"}
|
||||
}
|
||||
elseif time -m.interaction_start > 500000 then
|
||||
m.interaction_marker:set_properties {
|
||||
textures = {"artifact_rmb_50.png"}
|
||||
}
|
||||
elseif time -m.interaction_start > 250000 then
|
||||
m.interaction_marker:set_properties {
|
||||
textures = {"artifact_rmb_25.png"}
|
||||
}
|
||||
m.interaction_start = nil
|
||||
m.object:hud_remove(m.interaction_marker)
|
||||
m.interaction_marker = nil
|
||||
elseif progress > 1 then
|
||||
m.object:hud_change(m.interaction_marker, "text", "artifact_rmb_100.png")
|
||||
elseif progress > 0.75 then
|
||||
m.object:hud_change(m.interaction_marker, "text", "artifact_rmb_75.png")
|
||||
elseif progress > 0.5 then
|
||||
m.object:hud_change(m.interaction_marker, "text", "artifact_rmb_50.png")
|
||||
elseif progress > 0.25 then
|
||||
m.object:hud_change(m.interaction_marker, "text", "artifact_rmb_25.png")
|
||||
end
|
||||
end
|
||||
elseif not ctl.place and m.ctl.place and m.interaction_start then
|
||||
m.interacting_with = nil
|
||||
elseif not ctl.place and m.interaction_start and (not m.pointed_obj or not m.pointed_obj._no_interact) then
|
||||
m.interaction_start = nil
|
||||
if m.interaction_marker then
|
||||
m.object:hud_change(m.interaction_marker, "text", "artifact_rmb.png")
|
||||
end
|
||||
end
|
||||
|
||||
local wi = p:get_wielded_item()
|
||||
|
||||
m.wielded_item = wi
|
||||
|
||||
-- MARK: Radial menu handling
|
||||
|
||||
if ctl.place and not m.ctl.place and wi:get_name() == "artifact:input" then
|
||||
artifact.show_radial_menu(m, {
|
||||
name = "construct",
|
||||
|
|
@ -239,37 +296,17 @@ Player = setmetatable({
|
|||
end,
|
||||
-- Initialize the player's primary HUD display based on saved state.
|
||||
create_hud = function(m)
|
||||
-- If called post-init, make sure we delete the previous HUD.
|
||||
-- This is useful when we want to recreate the HUD in response
|
||||
-- to an event, like freeing Vix.
|
||||
-- if m.hud then
|
||||
-- for _, x in pairs(m.hud) do
|
||||
-- if type(x) == "table" then
|
||||
-- for _, y in pairs(x) do
|
||||
-- m.object:hud_remove(y)
|
||||
-- end
|
||||
-- else
|
||||
-- m.object:hud_remove(x)
|
||||
-- end
|
||||
-- end
|
||||
-- end
|
||||
-- m.hud = {
|
||||
-- key_health = m.object:hud_add {
|
||||
-- type = "statbar",
|
||||
-- position = {x=0.5,y=1},
|
||||
-- offset = {x=-27 *5,y=artifact.debug and -96 or -30},
|
||||
-- scale = {x=4,y=4},
|
||||
-- alignment = {x=-1, y=-1},
|
||||
-- size = {x=27,y=27},
|
||||
-- text = "artifact_heart_vix.png",
|
||||
-- text2 = "artifact_heart_bg.png",
|
||||
-- number = 20
|
||||
-- }
|
||||
-- }
|
||||
--
|
||||
-- if artifact.debug or artifact.story.states[artifact.story.get_state()] >= artifact.story.states.main then
|
||||
--
|
||||
-- end
|
||||
m.healthbar = m.object:hud_add {
|
||||
type = "statbar",
|
||||
position = {x=0.5,y=1},
|
||||
offset = {x=-27 *5,y=artifact.debug and -96 or -30},
|
||||
scale = {x=4,y=4},
|
||||
alignment = {x=-1, y=-1},
|
||||
size = {x=27,y=27},
|
||||
text = "artifact_heart_vix.png",
|
||||
text2 = "artifact_heart_bg.png",
|
||||
number = 20
|
||||
}
|
||||
end,
|
||||
set_hotbar_size = function(m, slots)
|
||||
local p = m.object
|
||||
|
|
@ -289,6 +326,7 @@ Player = setmetatable({
|
|||
|
||||
artifact.register_craftitem("input", {
|
||||
inventory_image = "artifact_rmb_100.png",
|
||||
range = 0,
|
||||
on_drop = function(s, p, pos)
|
||||
local m = artifact.players[p:get_player_name()]
|
||||
if artifact.debug or artifat.story.state > artifact.story.states.pre_vix then
|
||||
|
|
@ -313,3 +351,7 @@ minetest.register_on_joinplayer(function(p)
|
|||
minetest.registered_chatcommands.grantme.func(p:get_player_name(), "all")
|
||||
end
|
||||
end)
|
||||
|
||||
minetest.register_on_leaveplayer(function(p)
|
||||
artifact.players[p:get_player_name()] = nil
|
||||
end)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue