Files
chocomae/src/game/mouse/dodge/game.js
T
2018-12-02 15:52:18 +09:00

175 lines
4.4 KiB
JavaScript

var Game = {
create: function() {
game.physics.enable(this, Phaser.Physics.ARCADE);
this.game.stage.backgroundColor = "#000000"; // '#4d4d4d';
this.scoreManager = new ScoreManager();
sessionStorageManager.setIsNewAppHighestRecord(false);
var experienceAppTimer = new ExperienceAppTimer();
experienceAppTimer.setTimeOverListener(
(function() { this.gameOver(); }).bind(this)
);
// keyboard shortcut
this.keyboardShortcut = new KeyboardShortcut();
this.keyboardShortcut.addCallback(
Phaser.KeyCode.ESC, // keyCode
null, // keyDownHandler
(function() { this.back(); }).bind(this), // keyUpHandler
"dodge" // callerClassName
);
// game stage
var stars = game.add.group();
for (var i = 0; i < 128; i++)
{
var randomY = game.rnd.integerInRange(60, GAME_SCREEN_SIZE.y - 80);
stars.create(game.world.randomX, randomY, 'star');
}
// contents
this.spaceship = new Spaceship();
this.aliens = [];
for(var i = 0; i < 100; i++) {
var alien = new Alien(this.spaceship);
this.aliens.push(alien);
}
// top ui
var screenTopUI = new ScreenTopUI();
screenTopUI.makeBackButton( (function() { this.back(); }).bind(this) );
screenTopUI.makeFullScreenButton();
var scoreBoard = new ScoreBoard();
this.scoreManager.addOnChangeScoreListener( function(score) {
sessionStorageManager.setRecord(score);
scoreBoard.printScore(NumberUtil.numberWithCommas(score));
});
this.scoreManager.addOnChangeHighScoreListener( function(highScore) {
// console.log(highScore);
// sessionStorageManager.setAppHighestRecord(highScore);
sessionStorageManager.setIsNewBestRecrd(true);
// screenBottomUI.printLeftTextWithAppHighestRecord(sessionStorageManager.getAppHighestRecord());
});
// bottom ui
var screenBottomUI = new ScreenBottomUI();
screenBottomUI.printLeftTextWithAppHighestRecord(sessionStorageManager.getAppHighestRecord());
screenBottomUI.printCenterText(sessionStorageManager.getPlayingAppKoreanName());
screenBottomUI.printRightText(sessionStorageManager.getPlayerName());
this.startGame();
// this.countDown();
},
back: function() {
sessionStorageManager.resetPlayingAppData();
location.href = '../../web/client/menu_app.html';
},
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);
this.countDownText.stroke = "#333";
this.countDownText.strokeThickness = 50;
this.countDownNumber = 3;
if(isDebugMode())
this.countDownNumber = 1;
this.tweenCountDown();
}
tweenCountDown() {
if(this.countDownNumber === 0) {
this.startGame();
return;
}
this.countDownText.text = this.countDownNumber.toString();
this.countDownText.alpha = 1;
var countDownTween = game.add.tween(this.countDownText);
countDownTween.to( { alpha: 0 }, 1000, Phaser.Easing.Linear.None, true);
countDownTween.onComplete.add(this.tweenCountDown, this);
this.countDownNumber--;
}
*/
startGame: function() {
this.ellapsedTime = 0;
this.timerEvent = game.time.events.loop(Phaser.Timer.SECOND, this.updateTimer, this);
},
updateTimer: function() {
this.ellapsedTime += 1;
// console.log(this.ellapsedTime);
if(this.ellapsedTime == 2)
this.sendWave(1);
else if(this.ellapsedTime == 4)
this.sendWave(2);
else if(this.ellapsedTime == 6)
this.sendWave(3);
else if(this.ellapsedTime == 8)
this.sendWave(4);
else if(this.ellapsedTime == 10)
this.sendWave(5);
else if(this.ellapsedTime == 12)
this.sendWave(6);
else if(this.ellapsedTime == 14)
this.sendWave(7);
else if(this.ellapsedTime == 16)
this.sendWave(8);
else if(this.ellapsedTime == 18)
this.sendWave(9);
},
sendWave: function(waveNo) {
if(waveNo == 1) {
for(var i = 0; i < 20; i++)
this.aliens[i].setActive(true);
return;
}
var beginAlienIndex = waveNo * 10;
var endAlienIndex = (waveNo + 1) * 10;
for(var i = beginAlienIndex; i < endAlienIndex; i++)
this.aliens[i].setActive(true);
},
gameOver: function() {
var gameOverText = new GameOverText();
game.time.events.add(GAME_OVER_WAIT_TIME_MS, this.goResult, this);
},
goResult: function() {
location.href = '../../web/client/result.html';
},
getScore: function() {
return (this.alienTimer.activatedAlienIndex) * 2;
},
}
Game.GAME_OVER_WAIT_TIME_MS = 2000;