Files
chocomae/src/game/mouse/dodge/game.js
T
2018-12-02 20:25:14 +09:00

214 lines
5.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,
(function() {
this.spaceship.alpha = 0;
this.spaceship.body.enable = false;
this.showExplosionParticle();
this.gameOver();
}).bind(this) // onCollisionHandler
);
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());
});
*/
this.stopWatch = new StopWatch(
60, // sec
(function() {
this.setClickEnable(false);
this.gameOver();
}).bind(this)
);
// bottom ui
var screenBottomUI = new ScreenBottomUI();
screenBottomUI.printLeftTextWithAppHighestRecord(sessionStorageManager.getAppHighestRecord());
screenBottomUI.printCenterText(sessionStorageManager.getPlayingAppKoreanName());
screenBottomUI.printRightText(sessionStorageManager.getPlayerName());
// this.startGame();
this.spaceship.setActive(true);
this.countDown();
},
back: function() {
sessionStorageManager.resetPlayingAppData();
location.href = '../../web/client/menu_app.html';
},
initListeners: function() {
},
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;
this.countDownNumber = 3;
if(isDebugMode())
this.countDownNumber = 1;
this.tweenCountDown();
},
tweenCountDown: function() {
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.stopWatch.start();
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();
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';
},
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 = 3000;