Add: stop watch
This commit is contained in:
@@ -5,7 +5,7 @@ var Game = {
|
||||
|
||||
this.game.stage.backgroundColor = "#000000"; // '#4d4d4d';
|
||||
|
||||
this.scoreManager = new ScoreManager();
|
||||
// this.scoreManager = new ScoreManager();
|
||||
|
||||
sessionStorageManager.setIsNewAppHighestRecord(false);
|
||||
|
||||
@@ -39,7 +39,16 @@ var Game = {
|
||||
|
||||
this.aliens = [];
|
||||
for(var i = 0; i < 100; i++) {
|
||||
var alien = new Alien(this.spaceship);
|
||||
var alien = new Alien(this.spaceship,
|
||||
(function() {
|
||||
this.spaceship.alpha = 0;
|
||||
this.spaceship.body.enable = false;
|
||||
|
||||
this.showExplosionParticle();
|
||||
|
||||
this.gameOver();
|
||||
}).bind(this) // onCollisionHandler
|
||||
);
|
||||
this.aliens.push(alien);
|
||||
}
|
||||
|
||||
@@ -49,6 +58,7 @@ var Game = {
|
||||
screenTopUI.makeBackButton( (function() { this.back(); }).bind(this) );
|
||||
screenTopUI.makeFullScreenButton();
|
||||
|
||||
/*
|
||||
var scoreBoard = new ScoreBoard();
|
||||
this.scoreManager.addOnChangeScoreListener( function(score) {
|
||||
sessionStorageManager.setRecord(score);
|
||||
@@ -60,6 +70,16 @@ var Game = {
|
||||
sessionStorageManager.setIsNewBestRecrd(true);
|
||||
// screenBottomUI.printLeftTextWithAppHighestRecord(sessionStorageManager.getAppHighestRecord());
|
||||
});
|
||||
*/
|
||||
|
||||
this.stopWatch = new StopWatch(
|
||||
60, // sec
|
||||
(function() {
|
||||
this.setClickEnable(false);
|
||||
|
||||
this.gameOver();
|
||||
}).bind(this)
|
||||
);
|
||||
|
||||
|
||||
// bottom ui
|
||||
@@ -69,8 +89,10 @@ var Game = {
|
||||
screenBottomUI.printRightText(sessionStorageManager.getPlayerName());
|
||||
|
||||
|
||||
this.startGame();
|
||||
// this.countDown();
|
||||
// this.startGame();
|
||||
|
||||
this.spaceship.setActive(true);
|
||||
this.countDown();
|
||||
},
|
||||
|
||||
|
||||
@@ -82,11 +104,11 @@ var Game = {
|
||||
initListeners: function() {
|
||||
},
|
||||
|
||||
/*
|
||||
countDown() {
|
||||
var style = { font: "bold 200px Arial", fill: "#fff", boundsAlignH: "center", boundsAlignV: "middle" };
|
||||
this.countDownText = game.add.text(0, 0, "", style);
|
||||
this.countDownText.setTextBounds(0, 0, game.world.width, game.world.height);
|
||||
countDown: function() {
|
||||
var style = { font: "bold 200px Arial", fill: "#fff", wordWrap: true, wordWrapWidth: game.world.centerX, align: "center" };
|
||||
this.countDownText = game.add.text(game.world.centerX, game.world.centerY, "", style);
|
||||
// this.countDownText.setTextBounds(0, 0, game.world.width, game.world.height);
|
||||
this.countDownText.anchor.set(0.5);
|
||||
this.countDownText.stroke = "#333";
|
||||
this.countDownText.strokeThickness = 50;
|
||||
|
||||
@@ -94,9 +116,9 @@ var Game = {
|
||||
if(isDebugMode())
|
||||
this.countDownNumber = 1;
|
||||
this.tweenCountDown();
|
||||
}
|
||||
},
|
||||
|
||||
tweenCountDown() {
|
||||
tweenCountDown: function() {
|
||||
if(this.countDownNumber === 0) {
|
||||
this.startGame();
|
||||
return;
|
||||
@@ -110,10 +132,10 @@ var Game = {
|
||||
countDownTween.onComplete.add(this.tweenCountDown, this);
|
||||
|
||||
this.countDownNumber--;
|
||||
}
|
||||
*/
|
||||
},
|
||||
|
||||
startGame: function() {
|
||||
this.stopWatch.start();
|
||||
this.ellapsedTime = 0;
|
||||
this.timerEvent = game.time.events.loop(Phaser.Timer.SECOND, this.updateTimer, this);
|
||||
},
|
||||
@@ -159,17 +181,34 @@ var Game = {
|
||||
gameOver: function() {
|
||||
var gameOverText = new GameOverText();
|
||||
|
||||
game.time.events.add(GAME_OVER_WAIT_TIME_MS, this.goResult, this);
|
||||
var recordTime = this.stopWatch.stop();
|
||||
sessionStorageManager.setRecord(recordTime);
|
||||
|
||||
game.time.events.add(Game.GAME_OVER_WAIT_TIME_MS, this.goResult, this);
|
||||
},
|
||||
|
||||
goResult: function() {
|
||||
location.href = '../../web/client/result.html';
|
||||
},
|
||||
|
||||
getScore: function() {
|
||||
return (this.alienTimer.activatedAlienIndex) * 2;
|
||||
},
|
||||
showExplosionParticle: function() {
|
||||
var hitStarEmitter = game.add.emitter(
|
||||
this.spaceship.x,
|
||||
this.spaceship.y,
|
||||
10
|
||||
);
|
||||
hitStarEmitter.makeParticles('star');
|
||||
hitStarEmitter.minParticleScale = 1;
|
||||
hitStarEmitter.maxParticleScale = 3;
|
||||
hitStarEmitter.forEach(
|
||||
function(particle) {
|
||||
particle.tint = 0xFFd700;
|
||||
}
|
||||
);
|
||||
hitStarEmitter.gravity = 0;
|
||||
hitStarEmitter.start(true, 1000, null, 100);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Game.GAME_OVER_WAIT_TIME_MS = 2000;
|
||||
Game.GAME_OVER_WAIT_TIME_MS = 3000;
|
||||
Reference in New Issue
Block a user