Refactor script logic

This commit is contained in:
2026-04-26 10:10:42 -05:00
parent c9d949f759
commit 07943ec5f8
5 changed files with 101 additions and 31 deletions
+16 -12
View File
@@ -1,21 +1,25 @@
local Cube = {}
local Cube = setmetatable({}, { __index = Entity })
Cube.__index = Cube
function Cube.new()
local self = setmetatable({}, Cube)
self.id = entityAdd()
local pos = entityPositionAdd(self.id)
pos.x = 0
pos.y = 0
pos.z = 0
entityMeshAdd(self.id)
local mat = entityMaterialAdd(self.id)
mat.color = colorWhite()
local self = Entity.new()
setmetatable(self, Cube)
self:add(Entity.POSITION)
self.position.x = 0
self.position.y = 0
self.position.z = 0
self:add(Entity.MESH)
self:add(Entity.MATERIAL)
self.material.color = colorRed()
return self
end
function Cube:dispose()
entityRemove(self.id)
function Cube:update()
local speed = 3.0
local dx = inputAxis(INPUT_ACTION_LEFT, INPUT_ACTION_RIGHT)
local dz = inputAxis(INPUT_ACTION_UP, INPUT_ACTION_DOWN)
self.position.x = self.position.x + dx * speed * TIME.delta
self.position.z = self.position.z + dz * speed * TIME.delta
end
return Cube
+17 -13
View File
@@ -1,26 +1,30 @@
local Cube = include('entities/cube.lua')
local SceneCube = {}
SceneCube.__index = SceneCube
local cam
local cube
function Scene:init()
print("Scene init")
local camId = entityAdd()
local pos = entityPositionAdd(camId)
pos.x = 3
pos.y = 3
pos.z = 3
pos:lookAt(0, 0, 0)
entityCameraAdd(camId)
cam = camId
function SceneCube:init()
cam = Entity.new()
cam:add(Entity.POSITION)
cam.position.x = 3
cam.position.y = 3
cam.position.z = 3
cam.position:lookAt(0, 0, 0)
cam:add(Entity.CAMERA)
cube = Cube.new()
end
function Scene:update()
function SceneCube:update()
cube:update()
end
function Scene:dispose()
function SceneCube:dispose()
cam:dispose()
cube:dispose()
entityRemove(cam)
end
return SceneCube