Upd
This commit is contained in:
40
data/scripts/actors/actor_player.lua
Normal file
40
data/scripts/actors/actor_player.lua
Normal file
@@ -0,0 +1,40 @@
|
||||
-- базовый класс актора
|
||||
actor_base = inherit_table(game_object)
|
||||
|
||||
-- инициализация FSM
|
||||
|
||||
|
||||
function actor_base:on_init()
|
||||
game_object.on_init(self)
|
||||
end
|
||||
|
||||
function actor_base:on_shutdown()
|
||||
game_object.on_shutdown(self)
|
||||
end
|
||||
|
||||
function actor_base:on_update(dt)
|
||||
game_object.on_update(self, dt)
|
||||
end
|
||||
|
||||
-- игрок
|
||||
actor_player = inherit_table(actor_base)
|
||||
|
||||
function actor_player:on_init()
|
||||
actor_base.on_init(self)
|
||||
|
||||
self:create_body()
|
||||
|
||||
self:activate_camera()
|
||||
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)
|
||||
end
|
||||
@@ -1,13 +1,19 @@
|
||||
-- Game initialization script
|
||||
|
||||
-- загружаем скрипты
|
||||
load_script("game_utils.lua")
|
||||
load_script("game_object.lua")
|
||||
load_script("test_object.lua")
|
||||
load_script("actors/actor_player.lua")
|
||||
|
||||
-- глобальная таблица сущностей
|
||||
g_entity_table = {
|
||||
-- Lua class -- CPP class -- Description
|
||||
-- Lua class -- CPP class -- Description
|
||||
|
||||
{ "game_object", "Entity", "Test Lua Entity" }
|
||||
{ "actor_player", "ActorBase", "Player entity" },
|
||||
|
||||
-- Simple entity
|
||||
{ "test_object", "Entity", "Test entity" },
|
||||
|
||||
|
||||
}
|
||||
18
data/scripts/game_utils.lua
Normal file
18
data/scripts/game_utils.lua
Normal file
@@ -0,0 +1,18 @@
|
||||
-- http://lua-users.org/wiki/InheritanceTutorial
|
||||
|
||||
function merge_table( baseClass, newClass )
|
||||
for k, v in pairs( baseClass ) do
|
||||
if type( v ) == "table" then
|
||||
newClass[ k ] = newClass[ k ] or {}
|
||||
merge_table( v, newClass[ k ] )
|
||||
else
|
||||
newClass[ k ] = v
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function inherit_table( baseClass )
|
||||
local newClass = {}
|
||||
merge_table( baseClass, newClass )
|
||||
return newClass
|
||||
end
|
||||
16
data/scripts/test_object.lua
Normal file
16
data/scripts/test_object.lua
Normal file
@@ -0,0 +1,16 @@
|
||||
-- тестовый класс
|
||||
test_object = inherit_table(game_object)
|
||||
|
||||
function test_object:on_init()
|
||||
game_object.on_init(self)
|
||||
|
||||
self:load_model("data/models/scene_walls.obj")
|
||||
|
||||
self.m_test = 0.0
|
||||
end
|
||||
|
||||
function test_object:on_update(dt)
|
||||
game_object.on_update(self, dt)
|
||||
self:set_position(self.m_test, 0.0, 0.0)
|
||||
self.m_test = self.m_test + ( 0.2 * dt )
|
||||
end
|
||||
Reference in New Issue
Block a user