This commit is contained in:
2026-04-24 21:22:11 -05:00
parent 565c530469
commit c9d949f759
19 changed files with 379 additions and 1141 deletions
+21
View File
@@ -0,0 +1,21 @@
local Cube = {}
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()
return self
end
function Cube:dispose()
entityRemove(self.id)
end
return Cube
-20
View File
@@ -1,20 +0,0 @@
module('entity')
module('math')
module('color')
function entityInit()
entityPositionAdd(ENTITY_ID)
local phys = entityPhysicsAdd(ENTITY_ID)
phys.bodyType = PHYSICS_BODY_STATIC
phys:setShapePlane(vec3(0, 1, 0), 0)
local mesh = entityMeshAdd(ENTITY_ID)
mesh:generatePlane(20, 20)
local mat = entityMaterialAdd(ENTITY_ID)
mat.color = colorBlack()
end
function entityDispose()
end
-48
View File
@@ -1,48 +0,0 @@
module('entity')
module('input')
module('color')
module('math')
module('scene')
module('event')
module('entitycamera')
local phys
local updateSub
local SPEED = 4.0
local mat
function entityInit()
local pos = entityPositionAdd(ENTITY_ID)
pos.x = 0
pos.y = 1
pos.z = 0
phys = entityPhysicsAdd(ENTITY_ID)
phys:setShapeCapsule(0.3, 0.9)
local mesh = entityMeshAdd(ENTITY_ID)
mesh:generateCapsule(0.3, 0.9)
mat = entityMaterialAdd(ENTITY_ID)
updateSub = eventSubscribe(SCENE_EVENT_UPDATE, onUpdate)
end
function onUpdate()
local moveX = inputAxis(INPUT_ACTION_LEFT, INPUT_ACTION_RIGHT)
local moveZ = inputAxis(INPUT_ACTION_DOWN, INPUT_ACTION_UP)
mat.color = colorRainbow()
local cam = entityCameraGetCurrent()
local fwd = cam:getForward()
local right = cam:getRight()
local vy = phys.velocityY
phys.velocityX = (moveX * right.x + moveZ * fwd.x) * SPEED
phys.velocityZ = (moveX * right.y + moveZ * fwd.y) * SPEED
end
function entityDispose()
eventUnsubscribe(SCENE_EVENT_UPDATE, updateSub)
end
+1 -3
View File
@@ -72,6 +72,4 @@ else
print("Unknown platform, no default input bindings set.")
end
local test = 'test'
Scene.set('test/scene.lua')
Scene.set('scenes/cube.lua')
+26
View File
@@ -0,0 +1,26 @@
local Cube = include('entities/cube.lua')
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
cube = Cube.new()
end
function Scene:update()
end
function Scene:dispose()
cube:dispose()
entityRemove(cam)
end