Compare commits

1 Commits
main ... horror

Author SHA1 Message Date
bd1cffdf7d bring stuff 2026-03-12 18:23:18 +03:00
5 changed files with 94 additions and 16 deletions

View File

@@ -9,24 +9,27 @@ local PLAYER_PHYS_RUN_SPEED_MUL = 1.4
local PLAYER_PHYS_MOVE_SPEED_EXP = 1.0
local PLAYER_PHYS_FLY_SPEED_EXP = 4.0
local AIR_CONTROL = 0.2
local PLAYER_OFFSET_Y = 0.5
-- игрок
actor_player = inherit_table(actor_base)
actor_player.m_camera_offset_y = 0.5
actor_player.m_camera_offset_y = PLAYER_OFFSET_Y
function actor_player:on_init()
actor_base.on_init(self)
g_player = self
self.m_bobbing = 0.0
self:create_player_body(PLAYER_PHYS_RADIUS, PLAYER_PHYS_HEIGHT - PLAYER_PHYS_RADIUS * 2.0, 80.0, 0.0, 0.0)
self:activate_camera()
local ent = engine.create_entity("weapon_ump")
engine.add_entity_to_world(ent)
self.m_weapon_entity_id = ent:get_id()
--local ent = engine.create_entity("weapon_ump")
--engine.add_entity_to_world(ent)
--self.m_weapon_entity_id = ent:get_id()
--engine.play_sound_3d("data/sounds/test/test_music_64Kbps.mp3", 0.0, 0.0, 0.0)
end
@@ -48,28 +51,62 @@ function actor_player:on_update(dt)
self:update_player_movement(dt)
local ent = engine.get_entity_from_id(self.m_weapon_entity_id)
ent:set_relative_position_to_camera(self)
--local ent = engine.get_entity_from_id(self.m_weapon_entity_id)
--ent:set_relative_position_to_camera(self)
self:action_update()
end
function actor_player:action_update()
local action = self:get_action()
if action == ACTION_USE then
self:on_use_action()
end
local ent = engine.get_entity_from_id(self.m_weapon_entity_id)
if ent then
if action == ACTION_FIRE then
ent:set_state(WEAPON_FSM_STATE_ATTACK)
elseif action == ACTION_RELOAD then
ent:set_state(WEAPON_FSM_STATE_RELOAD)
--local ent = engine.get_entity_from_id(self.m_weapon_entity_id)
--if ent then
-- if action == ACTION_FIRE then
-- ent:set_state(WEAPON_FSM_STATE_ATTACK)
-- elseif action == ACTION_RELOAD then
-- ent:set_state(WEAPON_FSM_STATE_RELOAD)
-- end
--end
end
function actor_player:on_use_action()
local front_x, front_y, front_z = camera.get_front()
local ray_x, ray_y, ray_z = camera.get_position()
ray_x = ray_x + front_x
ray_y = ray_y + front_y
ray_z = ray_z + front_z
local ray_end_x, ray_end_y, ray_end_z = camera.get_position()
ray_end_x = ray_end_x + front_x * 1000
ray_end_y = ray_end_y + front_y * 1000
ray_end_z = ray_end_z + front_z * 1000
local trace = engine.trace_ray(ray_x, ray_y, ray_z, ray_end_x, ray_end_y, ray_end_z, self)
if trace.hit then
local traced_ent = engine.get_entity_from_id(trace.entity_id)
if traced_ent then
local classname = traced_ent:get_classname()
put_debug_string_to_screen(string.format("actor_player:on_use_action: %s", traced_ent:get_classname()), 1)
end
end
end
function actor_player:update_camera_bobbing(dt)
local vel_x, vel_y, vel_z = self:get_velocity()
self.m_bobbing = self.m_bobbing + dt
end
function actor_player:update_player_movement(dt)
local movement = self:get_movement()
local speed = 4.0
local speed = 2.5
local up_x, up_y, up_z = camera.get_up()
local front_x, front_y, front_z = camera.get_front()

View File

@@ -5,7 +5,8 @@ local BLACK_COLOR = { 0.0, 0.0, 0.0, 1.0 }
local WHITE_COLOR = { 1.0, 1.0, 1.0, 1.0 }
local draw_test_hud = true
local draw_example_test_hud = true
local draw_player_hud = false
local draw_example_test_hud = false
local draw_debug_string = false
local debug_string_text = ""
local debug_string_time = 0.0
@@ -26,7 +27,7 @@ function game_hud_draw( )
ui.draw_text("Hello, world!", 200.0, 200.0, GREEN_COLOR)
end
if g_player then
if g_player and draw_player_hud then
game_player_hud_draw()
end

View File

@@ -14,6 +14,9 @@ load_script("actors/actor_base.lua")
load_script("actors/actor_player.lua")
load_script("triggers/trigger_deleter.lua")
load_script("triggers/trigger_use_area.lua")
load_script("objects/inventory_object.lua")
-- глобальные переменные
g_player = nil
@@ -30,7 +33,8 @@ g_entity_table = {
-- Triggers
{ "trigger_deleter", "TriggerBase", "Example trigger" },
{ "trigger_use_area", "TriggerBase", "Example trigger" },
-- Simple entity
{ "test_object", "Entity", "Test entity" },
}

View File

@@ -0,0 +1,15 @@
-- Inventory object class
inventory_object = inherit_table(game_object)
function inventory_object:on_init()
game_object.on_init(self)
end
function inventory_object:on_shutdown()
game_object.on_shutdown(self)
end
function inventory_object:on_update(dt)
game_object.on_update(self, dt)
end

View File

@@ -0,0 +1,21 @@
trigger_use_area = inherit_table(game_object)
function trigger_use_area:on_init()
game_object.on_init(self)
self:create_box_body(0.4, 0.4, 0.4, 0.0, 0.0, 0.0, true, false)
end
function trigger_use_area:on_shutdown()
game_object.on_shutdown(self)
end
function trigger_use_area:on_update(dt)
game_object.on_shutdown(self, dt)
end
function trigger_use_area:on_collide(other)
end
function trigger_use_area:use()
end