prog
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
var Cube = {
|
||||
create: function() {
|
||||
var e = Entity.create();
|
||||
e.add(COMPONENT_TYPE_POSITION);
|
||||
e.position.x = 0;
|
||||
e.position.y = 0;
|
||||
e.position.z = 0;
|
||||
e.add(COMPONENT_TYPE_MESH);
|
||||
e.add(COMPONENT_TYPE_MATERIAL);
|
||||
e.material.setColor(colorRed());
|
||||
|
||||
return {
|
||||
_e: e,
|
||||
update: Cube.update,
|
||||
dispose: Cube.dispose
|
||||
};
|
||||
},
|
||||
|
||||
update: function() {
|
||||
var speed = 3.0;
|
||||
var dx = inputAxis(INPUT_ACTION_LEFT, INPUT_ACTION_RIGHT);
|
||||
var dz = inputAxis(INPUT_ACTION_UP, INPUT_ACTION_DOWN);
|
||||
this._e.position.x += dx * speed * TIME.delta;
|
||||
this._e.position.z += dz * speed * TIME.delta;
|
||||
},
|
||||
|
||||
dispose: function() {
|
||||
this._e.dispose();
|
||||
}
|
||||
};
|
||||
|
||||
Cube;
|
||||
@@ -1,25 +0,0 @@
|
||||
local Cube = setmetatable({}, { __index = Entity })
|
||||
Cube.__index = Cube
|
||||
|
||||
function Cube.new()
|
||||
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: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
|
||||
Reference in New Issue
Block a user