Update: CC - Snake FS - Entity Loaded (21g30t1e75.js) 4309 bytes modified
parent
70e7b4a31e
commit
2915662e7d
197
21g30t1e75.js
197
21g30t1e75.js
|
@ -155,7 +155,9 @@ this.state = {
|
|||
flip : 0,
|
||||
eating : false,
|
||||
exploding : false,
|
||||
lives : 2
|
||||
lives : 3,
|
||||
getReady : false,
|
||||
message : null
|
||||
};
|
||||
|
||||
GameLib.CustomCode.prototype.displayHUD = function() {
|
||||
|
@ -166,9 +168,29 @@ GameLib.CustomCode.prototype.displayHUD = function() {
|
|||
|
||||
this.canvasHUD.text('hiscore', 50, 32, '25px sans-serif', '#ffffff');
|
||||
|
||||
this.canvasHUD.image(this.imageHeart.instance, 250, 5, 30, 30);
|
||||
this.canvasHUD.image(this.imageHeart.instance, 285, 5, 30, 30);
|
||||
this.canvasHUD.image(this.imageHeart.instance, 320, 5, 30, 30);
|
||||
var images = [];
|
||||
|
||||
if (this.state.lives === 3) {
|
||||
images.push(this.imageHeart.instance);
|
||||
images.push(this.imageHeart.instance);
|
||||
images.push(this.imageHeart.instance);
|
||||
} else if (this.state.lives === 2) {
|
||||
images.push(this.imageHeart.instance);
|
||||
images.push(this.imageHeart.instance);
|
||||
images.push(this.imageHeartGrey.instance);
|
||||
} else if (this.state.lives === 1) {
|
||||
images.push(this.imageHeart.instance);
|
||||
images.push(this.imageHeartGrey.instance);
|
||||
images.push(this.imageHeartGrey.instance);
|
||||
} else if (this.state.lives === 0) {
|
||||
images.push(this.imageHeartGrey.instance);
|
||||
images.push(this.imageHeartGrey.instance);
|
||||
images.push(this.imageHeartGrey.instance);
|
||||
}
|
||||
|
||||
this.canvasHUD.image(images[0], 250, 5, 30, 30);
|
||||
this.canvasHUD.image(images[1].instance, 285, 5, 30, 30);
|
||||
this.canvasHUD.image(images[2].instance, 320, 5, 30, 30);
|
||||
|
||||
this.canvasHUD.line(50, 456, 462, 456, 2, "#000000");
|
||||
|
||||
|
@ -186,7 +208,8 @@ GameLib.CustomCode.prototype.displayHUD = function() {
|
|||
this.canvasHUD.image(this.imagePowerupSlow.instance, 360, 460, 48, 48);
|
||||
|
||||
this.textureHUD.instance.needsUpdate = true;
|
||||
}
|
||||
|
||||
}.bind(this)
|
||||
|
||||
GameLib.CustomCode.prototype.waitReload = function(delta) {
|
||||
|
||||
|
@ -199,7 +222,52 @@ GameLib.CustomCode.prototype.waitReload = function(delta) {
|
|||
/**
|
||||
* We need to revert to a good state
|
||||
*/
|
||||
console.warn('revert to good state');
|
||||
console.warn('reverting to good state');
|
||||
|
||||
this.displayHUD();
|
||||
|
||||
this.restore();
|
||||
|
||||
this.state.exploding = false;
|
||||
|
||||
this.state.getReady = true;
|
||||
|
||||
window.setTimeout(
|
||||
function(){
|
||||
this.state.message = null;
|
||||
this.displayHUD();
|
||||
this.state.getReady = false;
|
||||
}.bind(this),
|
||||
4000
|
||||
);
|
||||
|
||||
window.setTimeout(
|
||||
function(){
|
||||
this.state.message = "1";
|
||||
this.displayHUD();
|
||||
}.bind(this),
|
||||
3000
|
||||
);
|
||||
|
||||
window.setTimeout(
|
||||
function(){
|
||||
this.state.message = "2";
|
||||
this.displayHUD();
|
||||
}.bind(this),
|
||||
2000
|
||||
);
|
||||
|
||||
|
||||
window.setTimeout(
|
||||
function(){
|
||||
this.state.message = "3";
|
||||
this.displayHUD();
|
||||
}.bind(this),
|
||||
1000
|
||||
);
|
||||
|
||||
this.state.message = "READY?";
|
||||
this.displayHUD();
|
||||
|
||||
}.bind(this)
|
||||
|
||||
|
@ -350,6 +418,16 @@ GameLib.CustomCode.GameObject = function(
|
|||
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
|
||||
*/
|
||||
|
@ -744,6 +822,20 @@ GameLib.CustomCode.SnakeBody = function(
|
|||
GameLib.CustomCode.SnakeBody.prototype = Object.create(GameLib.CustomCode.GameObject.prototype);
|
||||
GameLib.CustomCode.SnakeBody.prototype.constructor = GameLib.CustomCode.GameObject;
|
||||
|
||||
/*
|
||||
GameLib.CustomCode.SnakeBody.prototype.clone = function() {
|
||||
return new GameLib.CustomCode.SnakeBody(
|
||||
this.type,
|
||||
this.mesh,
|
||||
this.position,
|
||||
this.orientation,
|
||||
this.flip,
|
||||
this.backupMesh,
|
||||
this.isTail
|
||||
)
|
||||
};
|
||||
*/
|
||||
|
||||
GameLib.CustomCode.SnakeBody.prototype.applyToMesh = function(updateInstance) {
|
||||
|
||||
GameLib.CustomCode.GameObject.prototype.applyToMesh.call(this, updateInstance);
|
||||
|
@ -810,6 +902,22 @@ GameLib.CustomCode.SnakeBody.prototype.advance = function(orientation, flip) {
|
|||
|
||||
GameLib.CustomCode.prototype.initializeGrid = function() {
|
||||
|
||||
this.grid.map(
|
||||
function(x) {
|
||||
x.map(
|
||||
function(y) {
|
||||
y.dispose();
|
||||
}
|
||||
);
|
||||
}
|
||||
)
|
||||
|
||||
this.food = [];
|
||||
|
||||
this.powerups = [];
|
||||
|
||||
this.snake = [];
|
||||
|
||||
this.grid = [];
|
||||
|
||||
for (var x = 0; x < GameLib.CustomCode.GRID_WIDTH; x++) {
|
||||
|
@ -1015,6 +1123,52 @@ GameLib.CustomCode.prototype.createCorner = function(body, temp) {
|
|||
|
||||
}.bind(this);
|
||||
|
||||
GameLib.CustomCode.prototype.backup = function() {
|
||||
this.backupSnake = this.snake.map(
|
||||
function(body) {
|
||||
return body;
|
||||
}
|
||||
);
|
||||
}.bind(this)
|
||||
|
||||
GameLib.CustomCode.prototype.restore = function() {
|
||||
|
||||
|
||||
this.snake.map(
|
||||
function(body) {
|
||||
|
||||
/**
|
||||
* We remove all snake parts from the grid so they are not destroyed on initializeGrid()
|
||||
* @type {null}
|
||||
*/
|
||||
this.grid[body.position.x][body.position.y] = null;
|
||||
|
||||
/**
|
||||
* If we have snake parts which have not been backed up - dispose of them
|
||||
*/
|
||||
if (this.backupSnake.indexOf(body) === -1) {
|
||||
body.dispose();
|
||||
}
|
||||
|
||||
}.bind(this)
|
||||
)
|
||||
|
||||
/**
|
||||
* Now initialize the grid
|
||||
*/
|
||||
this.initializeGrid();
|
||||
|
||||
/**
|
||||
* Restore our backup snake
|
||||
*/
|
||||
this.snake = this.backupSnake.map(
|
||||
function(body) {
|
||||
return body.clone();
|
||||
}
|
||||
);
|
||||
|
||||
}.bind(this)
|
||||
|
||||
/**
|
||||
* Move the snake forward and do collision detection
|
||||
* @type {function(this:snakeEntityLoaded)}
|
||||
|
@ -1261,7 +1415,7 @@ GameLib.CustomCode.prototype.advanceSnake = function(delta) {
|
|||
/**
|
||||
* make a backup of the snake here
|
||||
*/
|
||||
console.log('snake just ate');
|
||||
this.backupSnake();
|
||||
}
|
||||
|
||||
this.state.eating = false;
|
||||
|
@ -1274,34 +1428,15 @@ GameLib.Event.Subscribe(
|
|||
GameLib.Event.GAME_START,
|
||||
function() {
|
||||
|
||||
/**
|
||||
* Remove all existing snake parts
|
||||
*/
|
||||
this.snake.map(
|
||||
function(body) {
|
||||
body.dispose();
|
||||
}
|
||||
)
|
||||
|
||||
this.food.map(
|
||||
function(food) {
|
||||
food.dispose();
|
||||
}
|
||||
)
|
||||
|
||||
this.powerups.map(
|
||||
function(powerup) {
|
||||
powerup.dispose();
|
||||
}
|
||||
);
|
||||
|
||||
this.state = {
|
||||
orientation : 0,
|
||||
turning : false,
|
||||
flip : 0,
|
||||
eating : false,
|
||||
exploding : false,
|
||||
lives : 2
|
||||
lives : 3,
|
||||
getReady : false,
|
||||
message : null
|
||||
};
|
||||
|
||||
this.initializeGrid();
|
||||
|
@ -1338,6 +1473,8 @@ GameLib.Event.Subscribe(
|
|||
)
|
||||
]
|
||||
|
||||
this.backupSnake();
|
||||
|
||||
/**
|
||||
* Other Settings
|
||||
*/
|
||||
|
@ -1346,14 +1483,12 @@ GameLib.Event.Subscribe(
|
|||
|
||||
this.foodTime = 0;
|
||||
this.foodSpeed = GameLib.CustomCode.FOOD_SPEED_INITIAL;
|
||||
this.food = [];
|
||||
|
||||
this.powerupTime = 0;
|
||||
this.nextPowerupTime = GameLib.Utils.GetRandomIntInclusive(
|
||||
GameLib.CustomCode.POWERUP_WAIT_TIME_MIN,
|
||||
GameLib.CustomCode.POWERUP_WAIT_TIME_MAX
|
||||
);
|
||||
this.powerups = [];
|
||||
|
||||
this.explodeTime = 0;
|
||||
|
||||
|
|
Loading…
Reference in New Issue