update base:demo component
This commit is contained in:
parent
6500f9b6f3
commit
4d3cc50edb
@ -6,7 +6,8 @@ inair = true
|
|||||||
target = -1
|
target = -1
|
||||||
timer = 0.3
|
timer = 0.3
|
||||||
|
|
||||||
local dropitem = ARGS
|
local def_index = entity:def_index()
|
||||||
|
dropitem = ARGS
|
||||||
if dropitem then
|
if dropitem then
|
||||||
timer = dropitem.pickup_delay or timer
|
timer = dropitem.pickup_delay or timer
|
||||||
end
|
end
|
||||||
@ -38,7 +39,7 @@ end
|
|||||||
|
|
||||||
function on_grounded(force)
|
function on_grounded(force)
|
||||||
local matrix = mat4.idt()
|
local matrix = mat4.idt()
|
||||||
mat4.rotate(matrix, {0, 1, 0}, math.random()*360, matrix)
|
mat4.rotate(matrix, {0, 1, 0}, math.random() * 360, matrix)
|
||||||
mat4.rotate(matrix, {1, 0, 0}, 90, matrix)
|
mat4.rotate(matrix, {1, 0, 0}, 90, matrix)
|
||||||
mat4.scale(matrix, scale, matrix)
|
mat4.scale(matrix, scale, matrix)
|
||||||
rig:set_matrix(0, matrix)
|
rig:set_matrix(0, matrix)
|
||||||
@ -50,14 +51,34 @@ function on_fall()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function on_sensor_enter(index, oid)
|
function on_sensor_enter(index, oid)
|
||||||
local playerid = hud.get_player()
|
local other = entities.get(oid)
|
||||||
local playerentity = player.get_entity(playerid)
|
if not other then
|
||||||
if timer < 0.0 and oid == playerentity and index == 0 then
|
return
|
||||||
entity:despawn()
|
|
||||||
inventory.add(player.get_inventory(playerid), dropitem.id, dropitem.count)
|
|
||||||
audio.play_sound_2d("events/pickup", 0.5, 0.8+math.random()*0.4, "regular")
|
|
||||||
end
|
end
|
||||||
if index == 1 and oid == playerentity then
|
local pid = other:get_player()
|
||||||
|
if pid == -1 then
|
||||||
|
-- other is base:drop too
|
||||||
|
if index == 0 and other:def_index() == def_index then
|
||||||
|
local odrop = other:get_component("base:drop")
|
||||||
|
if odrop.dropitem.id == dropitem.id then
|
||||||
|
-- // TODO: replace combination logic with item.* function
|
||||||
|
local stack = item.stack_size(dropitem.id)
|
||||||
|
local sum = dropitem.count + odrop.dropitem.count
|
||||||
|
if sum <= stack then
|
||||||
|
dropitem.count = sum
|
||||||
|
other:despawn()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
if timer < 0.0 and index == 0 then
|
||||||
|
entity:despawn()
|
||||||
|
inventory.add(player.get_inventory(pid), dropitem.id, dropitem.count)
|
||||||
|
audio.play_sound_2d("events/pickup", 0.5, 0.8 + math.random() * 0.4, "regular")
|
||||||
|
end
|
||||||
|
if index == 1 then
|
||||||
target = oid
|
target = oid
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -84,15 +105,18 @@ end
|
|||||||
|
|
||||||
function on_update(tps)
|
function on_update(tps)
|
||||||
timer = timer - 1.0/tps
|
timer = timer - 1.0/tps
|
||||||
if target ~= -1 then
|
|
||||||
if timer > 0.0 then
|
if timer > 0.0 or target == -1 then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
local dir = vec3.sub(entities.get(target).transform:get_pos(), tsf:get_pos())
|
local target_entity = entities.get(target)
|
||||||
|
if not target_entity then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
local dir = vec3.sub(target_entity.transform:get_pos(), tsf:get_pos())
|
||||||
vec3.normalize(dir, dir)
|
vec3.normalize(dir, dir)
|
||||||
vec3.mul(dir, 10.0, dir)
|
vec3.mul(dir, 10.0, dir)
|
||||||
body:set_vel(dir)
|
body:set_vel(dir)
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function on_attacked(attacker, pid)
|
function on_attacked(attacker, pid)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user