Files
pke/data/scripts/actors/actor_player.lua
2026-03-05 15:20:18 +03:00

67 lines
2.1 KiB
Lua

-- игрок
actor_player = inherit_table(actor_base)
actor_player.m_camera_offset_y = 0.5
function actor_player:on_init()
actor_base.on_init(self)
self:create_body()
self:activate_camera()
local ent = engine.create_entity("test_object")
engine.add_entity_to_world(ent)
self.m_weapon_entity_id = ent:get_id()
self.m_in_reload = false
--local ent2 = engine.get_entity_from_id(self.m_weapon_entity_id)
--console.print(ent2:get_classname())
end
function actor_player:on_shutdown()
actor_base.on_shutdown(self)
end
function actor_player:on_update(dt)
actor_base.on_update(self, dt)
self:update_camera_look()
--self:update_camera_movement(dt)
self:update_body_movement(dt)
local ent = engine.get_entity_from_id(self.m_weapon_entity_id)
ent:set_relative_position_to_camera(self)
if self:get_action() == ACTION_FIRE and self.m_in_reload == false then
ent:play_animation(ent:find_animation("shoot1"), ANIM_PLAYBACK_NONE)
engine.play_sound("data/sounds/weapons/ump45_shoot.wav")
end
if self:get_action() == ACTION_RELOAD and self.m_in_reload == false then
ent:play_animation(ent:find_animation("reload"), ANIM_PLAYBACK_NONE)
engine.play_sound("data/sounds/weapons/ump45_reload.wav")
self.m_in_reload = true
end
if ent:get_current_animation() == ent:find_animation("shoot1") and
ent:get_current_animation_time() >= ent:get_animation_time(ent:find_animation("shoot1")) then
ent:play_animation(ent:find_animation("idle1"), ANIM_PLAYBACK_REPEAT)
end
if self.m_in_reload == true and ent:get_current_animation_time() >= ent:get_animation_time(ent:find_animation("reload")) then
ent:play_animation(ent:find_animation("idle1"), ANIM_PLAYBACK_REPEAT)
self.m_in_reload = false
end
-- if ent:get_current_animation() == ent:find_animation("reload") and
-- ent:get_current_animation_time() >= ent:get_animation_time(ent:find_animation("reload")) then
-- ent:play_animation(ent:find_animation("idle1"), ANIM_PLAYBACK_NONE)
--end
end
function actor_player:on_collide(other)
console.print(string.format("actor_player:on_collide: %s", other:get_classname()))
end