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

beta.r3js.org
-=yb4f310 2018-03-24 14:41:44 +01:00
parent 483ddfdc0b
commit c8c9a3b8d0
1 changed files with 160 additions and 115 deletions

View File

@ -205,7 +205,13 @@ GameLib.CustomCode.prototype.displayHUD = function() {
this.canvasHUD.text('slow', 420, 500, '12px Pixeled', '#ffffff'); this.canvasHUD.text('slow', 420, 500, '12px Pixeled', '#ffffff');
if (this.state.message) { if (this.state.message) {
this.canvasHUD.text(this.state.message, 220, 250, '30px Pixeled', '#ffffff'); this.canvasHUD.text(
this.state.message.text,
this.state.message.x,
this.state.message.y,
'30px Pixeled',
'#ffffff'
);
} }
this.canvasHUD.image(this.imagePowerupSpeed.instance, 50, 460, 48, 48); this.canvasHUD.image(this.imagePowerupSpeed.instance, 50, 460, 48, 48);
@ -232,9 +238,7 @@ GameLib.CustomCode.prototype.waitReload = function(delta) {
this.state.exploding = false; this.state.exploding = false;
if (this.state.lives <= 0) { if (this.state.lives <= 0) {
this.state.gameOver = true; this.gameOver(false);
this.state.message = "GAME OVER";
this.displayHUD();
return; return;
} }
@ -254,7 +258,11 @@ GameLib.CustomCode.prototype.waitReload = function(delta) {
window.setTimeout( window.setTimeout(
function(){ function(){
this.state.message = "GO!"; this.state.message = {
text : "GO!",
x : 150,
y : 256
};
this.displayHUD(); this.displayHUD();
this.state.getReady = false; this.state.getReady = false;
}.bind(this), }.bind(this),
@ -263,7 +271,11 @@ GameLib.CustomCode.prototype.waitReload = function(delta) {
window.setTimeout( window.setTimeout(
function(){ function(){
this.state.message = "1"; this.state.message = {
text: "1",
x: 160,
y: 256
};
this.displayHUD(); this.displayHUD();
}.bind(this), }.bind(this),
3000 3000
@ -271,7 +283,11 @@ GameLib.CustomCode.prototype.waitReload = function(delta) {
window.setTimeout( window.setTimeout(
function(){ function(){
this.state.message = "2"; this.state.message = {
text: "2",
x: 160,
y: 256
};
this.displayHUD(); this.displayHUD();
}.bind(this), }.bind(this),
2000 2000
@ -280,13 +296,21 @@ GameLib.CustomCode.prototype.waitReload = function(delta) {
window.setTimeout( window.setTimeout(
function(){ function(){
this.state.message = "3"; this.state.message = {
text: "3",
x: 160,
y: 256
};
this.displayHUD(); this.displayHUD();
}.bind(this), }.bind(this),
1000 1000
); );
this.state.message = "READY?"; this.state.message = {
text: "GET READY",
x: 100,
y: 256
};
this.displayHUD(); this.displayHUD();
}.bind(this) }.bind(this)
@ -438,16 +462,6 @@ GameLib.CustomCode.GameObject = function(
this.position = position; this.position = position;
} }
/* GameLib.CustomCode.GameObject.prototype.clone = function() {
return new GameLib.CustomCode.GameObject(
this.objectType,
this.type,
this.mesh,
this.position
)
};
*/
/** /**
* Disposes of the mesh object and resets this object to its defaults * Disposes of the mesh object and resets this object to its defaults
*/ */
@ -513,6 +527,10 @@ GameLib.CustomCode.prototype.getFreeGridPosition = function() {
} }
); );
if (positions.length === 0) {
return null;
}
var index = GameLib.Utils.GetRandomInt(0, positions.length); var index = GameLib.Utils.GetRandomInt(0, positions.length);
return positions[index]; return positions[index];
@ -755,12 +773,20 @@ GameLib.CustomCode.prototype.createPowerup = function(delta) {
return; return;
} }
var position = this.getFreeGridPosition();
if (position === null) {
this.gameOver(true);
} else {
this.createGameObject( this.createGameObject(
GameLib.CustomCode.OBJECT_TYPE_POWERUP, GameLib.CustomCode.OBJECT_TYPE_POWERUP,
null, null,
this.getFreeGridPosition() position
); );
}
}.bind(this); }.bind(this);
GameLib.CustomCode.prototype.createFood = function(delta) { GameLib.CustomCode.prototype.createFood = function(delta) {
@ -777,14 +803,29 @@ GameLib.CustomCode.prototype.createFood = function(delta) {
return; return;
} }
var position = this.getFreeGridPosition();
if (position === null) {
this.gameOver(true);
} else {
this.createGameObject( this.createGameObject(
GameLib.CustomCode.OBJECT_TYPE_FOOD, GameLib.CustomCode.OBJECT_TYPE_FOOD,
null, null,
this.getFreeGridPosition() position
); );
}
}.bind(this); }.bind(this);
GameLib.CustomCode.prototype.gameOver = function(won) {
this.state.gameOver = true;
this.state.message = {
text : "GAME OVER",
x : 100,
y : 256
};
this.displayHUD();
}.bind(this)
/** /**
* GameLib.CustomCode.SnakeBody * GameLib.CustomCode.SnakeBody
@ -1102,6 +1143,10 @@ GameLib.CustomCode.prototype.extend = function(gameObject, position, orientation
this.grid[body.position.x][body.position.y] = body; this.grid[body.position.x][body.position.y] = body;
if (this.snake.length === GameLib.CustomCode.GRID_WIDTH * GameLib.CustomCode.GRID_HEIGHT) {
this.gameOver(true);
}
}.bind(this); }.bind(this);
/** /**