More cleanup
This commit is contained in:
+18
-31
@@ -1,35 +1,22 @@
|
||||
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(Color.black());
|
||||
function CubeEntity() {
|
||||
Entity.call(this);
|
||||
this.add(POSITION);
|
||||
this.position.x = 0;
|
||||
this.position.y = 0;
|
||||
this.position.z = 0;
|
||||
this.add(MESH);
|
||||
this.add(MATERIAL);
|
||||
}
|
||||
|
||||
print(Color);
|
||||
print(Color.prototype);
|
||||
Object.assign(CubeEntity.prototype, Entity.prototype);
|
||||
|
||||
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();
|
||||
}
|
||||
CubeEntity.prototype.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.position.x += dx * speed * TIME.delta;
|
||||
this.position.z += dz * speed * TIME.delta;
|
||||
this.material.setColor(Color.rainbow());
|
||||
};
|
||||
|
||||
Cube;
|
||||
module = CubeEntity;
|
||||
+19
-21
@@ -1,28 +1,26 @@
|
||||
var Cube = include('entities/cube.js');
|
||||
|
||||
var cam;
|
||||
var cube;
|
||||
function CubeScene() {
|
||||
this.cam = new Entity();
|
||||
this.cam.add(POSITION);
|
||||
this.cam.position.x = 3;
|
||||
this.cam.position.y = 3;
|
||||
this.cam.position.z = 3;
|
||||
this.cam.position.lookAt(0, 0, 0);
|
||||
this.cam.add(CAMERA);
|
||||
|
||||
var SceneCube = {
|
||||
init: function() {
|
||||
cam = Entity.create();
|
||||
cam.add(COMPONENT_TYPE_POSITION);
|
||||
cam.position.x = 3;
|
||||
cam.position.y = 3;
|
||||
cam.position.z = 3;
|
||||
cam.position.lookAt(0, 0, 0);
|
||||
cam.add(COMPONENT_TYPE_CAMERA);
|
||||
cube = Cube.create();
|
||||
},
|
||||
this.cube = new Cube();
|
||||
}
|
||||
|
||||
update: function() {
|
||||
cube.update();
|
||||
},
|
||||
Object.assign(CubeScene, Scene.prototype);
|
||||
|
||||
dispose: function() {
|
||||
cam.dispose();
|
||||
cube.dispose();
|
||||
}
|
||||
CubeScene.prototype.update = function() {
|
||||
this.cube.update();
|
||||
};
|
||||
|
||||
SceneCube;
|
||||
CubeScene.prototype.dispose = function() {
|
||||
this.cam.dispose();
|
||||
this.cube.dispose();
|
||||
};
|
||||
|
||||
module = CubeScene;
|
||||
|
||||
Reference in New Issue
Block a user