Update: CC - Snake FS - Entity Loaded (21g30t1e75.js) 3399 bytes modified
parent
b5f55bc1f5
commit
3359bfdaad
150
21g30t1e75.js
150
21g30t1e75.js
|
@ -134,35 +134,93 @@ this.state = {
|
||||||
flip : 0
|
flip : 0
|
||||||
};
|
};
|
||||||
|
|
||||||
GameLib.CustomCode.prototype.visualizeGrid = function (color) {
|
GameLib.CustomCode.prototype.visualizeGrid = function () {
|
||||||
|
|
||||||
if (this.starsMesh) {
|
if (this.noneMesh) {
|
||||||
this.scene.instance.remove(this.starsMesh);
|
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(
|
this.grid.map(
|
||||||
function(x, xIndex) {
|
function(x, xIndex) {
|
||||||
x.map(
|
x.map(
|
||||||
function(y, yIndex) {
|
function(object, yIndex) {
|
||||||
this.starsGeometry.vertices.push(
|
|
||||||
new THREE.Vector3(
|
if (object.objectType === GameLib.CustomCode.OBJECT_TYPE_NONE) {
|
||||||
(xIndex * GameLib.CustomCode.BODY_SCALE_X) + GameLib.CustomCode.GRID_OFFSET_X,
|
this.noneGeometry.vertices.push(
|
||||||
(yIndex * GameLib.CustomCode.BODY_SCALE_Y) + GameLib.CustomCode.GRID_OFFSET_Y,
|
new THREE.Vector3(
|
||||||
5
|
(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)
|
||||||
)
|
)
|
||||||
}.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)
|
}.bind(this)
|
||||||
|
|
||||||
|
@ -303,17 +361,17 @@ GameLib.CustomCode.prototype.createGameObject = function(
|
||||||
case GameLib.CustomCode.POWERUP_SPEED :
|
case GameLib.CustomCode.POWERUP_SPEED :
|
||||||
mesh = this.createGameMesh(this.materialPowerupSpeed);
|
mesh = this.createGameMesh(this.materialPowerupSpeed);
|
||||||
break;
|
break;
|
||||||
case GameLib.CustomCode.POWERUP_LIFE :
|
case GameLib.CustomCode.POWERUP_LIFE :
|
||||||
mesh = this.createGameMesh(this.materialPowerupLife);
|
mesh = this.createGameMesh(this.materialPowerupLife);
|
||||||
break;
|
break;
|
||||||
case GameLib.CustomCode.POWERUP_SLOW :
|
case GameLib.CustomCode.POWERUP_SLOW :
|
||||||
mesh = this.createGameMesh(this.materialPowerupSlow);
|
mesh = this.createGameMesh(this.materialPowerupSlow);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new Error('unhandled power up type : ' + type)
|
throw new Error('unhandled power up type : ' + type)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* We apply a scale to the powerupss too - since they appear too big when normal
|
* We apply a scale to the powerupss too - since they appear too big when normal
|
||||||
*/
|
*/
|
||||||
mesh.scale.x = 0.8;
|
mesh.scale.x = 0.8;
|
||||||
|
@ -458,7 +516,16 @@ GameLib.CustomCode.prototype.createGameObject = function(
|
||||||
/**
|
/**
|
||||||
* Save a reference to this object to the specific object array
|
* Save a reference to this object to the specific object array
|
||||||
*/
|
*/
|
||||||
array.push(gameObject);
|
|
||||||
|
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)
|
* If we have too many objects - dispose of the first on in the queue (fifo)
|
||||||
|
@ -473,7 +540,7 @@ GameLib.CustomCode.prototype.createGameObject = function(
|
||||||
this.grid[gameObject.position.x][gameObject.position.y].dispose();
|
this.grid[gameObject.position.x][gameObject.position.y].dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
return gameObject;
|
return gameObject;
|
||||||
|
|
||||||
}.bind(this);
|
}.bind(this);
|
||||||
|
|
||||||
|
@ -958,29 +1025,28 @@ GameLib.Event.Subscribe(
|
||||||
};
|
};
|
||||||
|
|
||||||
this.initializeGrid();
|
this.initializeGrid();
|
||||||
|
this.visualizeGrid();
|
||||||
|
|
||||||
this.createGameObject(
|
this.snake = [
|
||||||
GameLib.CustomCode.OBJECT_TYPE_SNAKE_BODY,
|
this.createGameObject(
|
||||||
GameLib.CustomCode.BODY_TYPE_BREAD_HEAD,
|
GameLib.CustomCode.OBJECT_TYPE_SNAKE_BODY,
|
||||||
{
|
GameLib.CustomCode.BODY_TYPE_BREAD_HEAD,
|
||||||
x : 4,
|
{
|
||||||
y : 4
|
x : 4,
|
||||||
},
|
y : 4
|
||||||
GameLib.CustomCode.ORIENTATION_UP
|
},
|
||||||
);
|
GameLib.CustomCode.ORIENTATION_UP
|
||||||
|
),
|
||||||
this.createGameObject(
|
this.createGameObject(
|
||||||
GameLib.CustomCode.OBJECT_TYPE_SNAKE_BODY,
|
GameLib.CustomCode.OBJECT_TYPE_SNAKE_BODY,
|
||||||
GameLib.CustomCode.BODY_TYPE_BREAD_TAIL,
|
GameLib.CustomCode.BODY_TYPE_BREAD_TAIL,
|
||||||
{
|
{
|
||||||
x : 4,
|
x : 4,
|
||||||
y : 3
|
y : 3
|
||||||
},
|
},
|
||||||
GameLib.CustomCode.ORIENTATION_UP
|
GameLib.CustomCode.ORIENTATION_UP
|
||||||
);
|
)
|
||||||
|
]
|
||||||
|
|
||||||
//this.visualizeGrid();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Other Settings
|
* Other Settings
|
||||||
|
|
Loading…
Reference in New Issue