Update: CC - Snake FS - Entity Loaded (21g30t1e75.js) 3399 bytes modified

beta.r3js.org
-=yb4f310 2018-03-22 12:20:14 +01:00
parent b5f55bc1f5
commit 3359bfdaad
1 changed files with 113 additions and 47 deletions

View File

@ -134,35 +134,93 @@ this.state = {
flip : 0
};
GameLib.CustomCode.prototype.visualizeGrid = function (color) {
GameLib.CustomCode.prototype.visualizeGrid = function () {
if (this.starsMesh) {
this.scene.instance.remove(this.starsMesh);
if (this.noneMesh) {
this.scene.instance.remove(this.noneMesh);
}
this.starsGeometry = new THREE.Geometry();
if (this.foodMesh) {
this.scene.instance.remove(this.foodMesh);
}
if (this.powerupMesh) {
this.scene.instance.remove(this.powerupMesh);
}
if (this.snakeMesh) {
this.scene.instance.remove(this.snakeMesh);
}
this.noneGeometry = new THREE.Geometry();
this.foodGeometry = new THREE.Geometry();
this.powerupGeometry = new THREE.Geometry();
this.snakeGeometry = new THREE.Geometry();
this.grid.map(
function(x, xIndex) {
x.map(
function(y, yIndex) {
this.starsGeometry.vertices.push(
function(object, yIndex) {
if (object.objectType === GameLib.CustomCode.OBJECT_TYPE_NONE) {
this.noneGeometry.vertices.push(
new THREE.Vector3(
(xIndex * GameLib.CustomCode.BODY_SCALE_X) + GameLib.CustomCode.GRID_OFFSET_X,
(yIndex * GameLib.CustomCode.BODY_SCALE_Y) + GameLib.CustomCode.GRID_OFFSET_Y,
5
)
);
}
if (object.objectType === GameLib.CustomCode.OBJECT_TYPE_SNAKE_BODY) {
this.snakeGeometry.vertices.push(
new THREE.Vector3(
(xIndex * GameLib.CustomCode.BODY_SCALE_X) + GameLib.CustomCode.GRID_OFFSET_X,
(yIndex * GameLib.CustomCode.BODY_SCALE_Y) + GameLib.CustomCode.GRID_OFFSET_Y,
5
)
);
}
if (object.objectType === GameLib.CustomCode.OBJECT_TYPE_FOOD) {
this.foodGeometry.vertices.push(
new THREE.Vector3(
(xIndex * GameLib.CustomCode.BODY_SCALE_X) + GameLib.CustomCode.GRID_OFFSET_X,
(yIndex * GameLib.CustomCode.BODY_SCALE_Y) + GameLib.CustomCode.GRID_OFFSET_Y,
5
)
);
}
if (object.objectType === GameLib.CustomCode.OBJECT_TYPE_POWERUP) {
this.powerupGeometry.vertices.push(
new THREE.Vector3(
(xIndex * GameLib.CustomCode.BODY_SCALE_X) + GameLib.CustomCode.GRID_OFFSET_X,
(yIndex * GameLib.CustomCode.BODY_SCALE_Y) + GameLib.CustomCode.GRID_OFFSET_Y,
5
)
);
}
}.bind(this)
)
}.bind(this)
);
var starsMaterial = new THREE.PointsMaterial({color: color, size: 0.1});
var noneMaterial = new THREE.PointsMaterial({color: 0xffffff, size: 0.1});
var foodMaterial = new THREE.PointsMaterial({color: 0x00ff00, size: 0.1});
var snakeMaterial = new THREE.PointsMaterial({color: 0x0000ff, size: 0.1});
var powerupMaterial = new THREE.PointsMaterial({color: 0xff0000, size: 0.1});
this.starsMesh = new THREE.Points(this.starsGeometry, starsMaterial);
this.noneMesh = new THREE.Points(this.noneGeometry, noneMaterial);
this.foodMesh = new THREE.Points(this.foodGeometry, foodMaterial);
this.powerupMesh = new THREE.Points(this.powerupGeometry, powerupMaterial);
this.snakeMesh = new THREE.Points(this.snakeGeometry, snakeMaterial);
this.scene.instance.add(this.starsMesh);
this.scene.instance.add(this.noneMesh);
this.scene.instance.add(this.foodMesh);
this.scene.instance.add(this.powerupMesh);
this.scene.instance.add(this.snakeMesh);
}.bind(this)
@ -458,7 +516,16 @@ GameLib.CustomCode.prototype.createGameObject = function(
/**
* Save a reference to this object to the specific object array
*/
if (
currentGameObject.objectType === GameLib.CustomCode.OBJECT_TYPE_POWERUP ||
currentGameObject.objectType === GameLib.CustomCode.OBJECT_TYPE_FOOD
) {
/**
* Food and powerups automatically get added, snake bodys need careful insertion
*/
array.push(gameObject);
}
/**
* If we have too many objects - dispose of the first on in the queue (fifo)
@ -958,7 +1025,9 @@ GameLib.Event.Subscribe(
};
this.initializeGrid();
this.visualizeGrid();
this.snake = [
this.createGameObject(
GameLib.CustomCode.OBJECT_TYPE_SNAKE_BODY,
GameLib.CustomCode.BODY_TYPE_BREAD_HEAD,
@ -967,8 +1036,7 @@ GameLib.Event.Subscribe(
y : 4
},
GameLib.CustomCode.ORIENTATION_UP
);
),
this.createGameObject(
GameLib.CustomCode.OBJECT_TYPE_SNAKE_BODY,
GameLib.CustomCode.BODY_TYPE_BREAD_TAIL,
@ -977,10 +1045,8 @@ GameLib.Event.Subscribe(
y : 3
},
GameLib.CustomCode.ORIENTATION_UP
);
//this.visualizeGrid();
)
]
/**
* Other Settings