Add: GameLevelManager, WordManager

This commit is contained in:
2019-01-04 18:32:22 +09:00
parent 1aeff26072
commit bc9610dac4
5 changed files with 118 additions and 43 deletions
@@ -39,15 +39,19 @@ function FlyingSaucer(lineIndex) {
this.wordText = game.add.text(0, 0, "text", style); this.wordText = game.add.text(0, 0, "text", style);
this.wordText.anchor.set(0.5); this.wordText.anchor.set(0.5);
this.startAttack(); this.setActive(true);
// this.setActive(true);
} }
FlyingSaucer.prototype.initVariables = function() { FlyingSaucer.prototype.initVariables = function() {
this.isActivated = false; this.isActivated = false;
this.wordLevel = 0;
this.speed = FlyingSaucer.DEFAULT_SPEED; this.speed = FlyingSaucer.DEFAULT_SPEED;
this.heartManager = null;
this.wordManager = null;
this.gameLevelManager = null;
this.timerEvent = null; this.timerEvent = null;
} }
@@ -84,24 +88,32 @@ FlyingSaucer.prototype.update = function() {
this.wordText.y = this.y + FlyingSaucer.WORD_TEXT_OFFSET_Y; this.wordText.y = this.y + FlyingSaucer.WORD_TEXT_OFFSET_Y;
if(this.y > GAME_SCREEN_SIZE.y - 200) if(this.y > GAME_SCREEN_SIZE.y - 200)
this.moveInitialPos(); this.crash();
} else { } else {
this.stop(); this.stop();
} }
} }
FlyingSaucer.prototype.setup = function(wordLevel, speedLevel) { FlyingSaucer.prototype.setHeartManager = function(heartManager) {
this.wordLevel = wordLevel; this.heartManager = heartManager;
this.speedLevel = speedLevel;
} }
FlyingSaucer.prototype.setWordManager = function(wordManager) {
this.wordManager = wordManager;
}
FlyingSaucer.prototype.setGameLevelManager = function(gameLevelManager) {
this.gameLevelManager = gameLevelManager;
}
FlyingSaucer.prototype.setWord = function(wordText) { FlyingSaucer.prototype.setWord = function(wordText) {
this.wordText.text = wordText; this.wordText.text = wordText;
} }
FlyingSaucer.prototype.stop = function() { FlyingSaucer.prototype.stop = function() {
this.body.velocity.setTo(0, 0); this.body.velocity.setTo(0, 0);
} }
@@ -136,7 +148,13 @@ FlyingSaucer.prototype.moveInitialPos = function() {
FlyingSaucer.prototype.startAttack = function() { FlyingSaucer.prototype.startAttack = function() {
this.moveInitialPos(); this.moveInitialPos();
this.setWord("text"); console.log(this.wordManager);
console.log(this.gameLevelManager);
var wordLevel = this.gameLevelManager.getWordLevel();
console.log(wordLevel);
var word = this.wordManager.getWord(wordLevel);
console.log(word);
this.setWord(word);
this.setActive(true); this.setActive(true);
} }
@@ -188,6 +206,15 @@ FlyingSaucer.prototype.explode = function(inputText) {
this.timerEvent = game.time.events.add(Phaser.Timer.SECOND, this.startAttack, this); this.timerEvent = game.time.events.add(Phaser.Timer.SECOND, this.startAttack, this);
} }
FlyingSaucer.prototype.crash = function() {
this.moveInitialPos();
this.heartManager.breakHearts(1);
}
FlyingSaucer.prototype.destroy = function() {
this.setActive(false);
this.setWord("");
}
FlyingSaucer.loadResource = function() { FlyingSaucer.loadResource = function() {
+52 -33
View File
@@ -6,38 +6,14 @@ var WordFlyingSaucer = {
sessionStorageManager.setIsNewAppHighestRecord(false); sessionStorageManager.setIsNewAppHighestRecord(false);
this.initVariables();
var experienceAppTimer = new ExperienceAppTimer(); var experienceAppTimer = new ExperienceAppTimer();
experienceAppTimer.setTimeOverListener( experienceAppTimer.setTimeOverListener(
(function() { this.timeOver(); }).bind(this) (function() { this.timeOver(); }).bind(this)
); );
this.initVariables();
// game stage
this.game.stage.backgroundColor = "#000000"; // '#4d4d4d';
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');
}
this.flyingsaucers = [];
for(var i = 0; i < 2; i++) {
this.flyingsaucers[i] = new FlyingSaucer(i);
this.flyingsaucers[i].setup(this.wordLevel, this.speedLevel);
this.flyingsaucers[i].setActive(true);
}
// top ui
var screenTopUI = new ScreenTopUI();
screenTopUI.makeBackButton( (function() { this.back(); }).bind(this) );
screenTopUI.makeFullScreenButton();
this.scoreManager = new ScoreManager(); this.scoreManager = new ScoreManager();
this.scoreBoard = new ScoreBoard(); this.scoreBoard = new ScoreBoard();
this.scoreManager.addOnChangeScoreListener( this.scoreManager.addOnChangeScoreListener(
@@ -55,16 +31,41 @@ var WordFlyingSaucer = {
}).bind(this) }).bind(this)
); );
var heartManager = new HeartManager(); this.heartManager = new HeartManager();
var heartGauge = new HeartGauge(heartManager); this.heartManager.addOnChangeGameOverListener(
heartManager.addOnChangeGameOverListener(
(function() { this.gameOver(); }).bind(this) (function() { this.gameOver(); }).bind(this)
); );
// game stage
this.game.stage.backgroundColor = "#000000"; // '#4d4d4d';
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');
}
this.flyingsaucers = [];
for(var i = 0; i < 2; i++) {
this.flyingsaucers[i] = new FlyingSaucer(i);
this.flyingsaucers[i].setHeartManager(this.heartManager);
this.flyingsaucers[i].setWordManager(this.wordManager);
this.flyingsaucers[i].setGameLevelManager(this.gameLevelManager);
this.flyingsaucers[i].setActive(true);
this.flyingsaucers[i].startAttack();
}
// top ui
var screenTopUI = new ScreenTopUI();
screenTopUI.makeBackButton( (function() { this.back(); }).bind(this) );
screenTopUI.makeFullScreenButton();
var heartGauge = new HeartGauge(this.heartManager);
heartGauge.start(); heartGauge.start();
// input text // input text
var INPUT_TEXT_Y = 680; var INPUT_TEXT_Y = 680;
this.inputText = new InputTypeText(game.world.centerX, INPUT_TEXT_Y); this.inputText = new InputTypeText(game.world.centerX, INPUT_TEXT_Y);
@@ -101,7 +102,9 @@ var WordFlyingSaucer = {
initVariables: function() { initVariables: function() {
this.wordLevel = 0; this.wordManager = new WordManager();
this.gameLevelManager = new GameLevelManager();
this.speedLevel = 0; this.speedLevel = 0;
}, },
@@ -133,6 +136,22 @@ var WordFlyingSaucer = {
location.href = '../../web/client/result.html'; location.href = '../../web/client/result.html';
}, },
gameOver: function() {
var gameOverText = new GameOverText();
// this.updateResultRecord();
this.stopAndGoResult();
},
stopAndGoResult: function() {
// remove all flyingsaucers
var count = this.flyingsaucers.length;
for(var i = 0; i < count; i++) {
this.flyingsaucers[i].destroy();
}
game.time.events.add(Phaser.Timer.SECOND * 2, this.goResult, this);
},
checkTypingContents: function(event) { checkTypingContents: function(event) {
var count = this.flyingsaucers.length; var count = this.flyingsaucers.length;
@@ -0,0 +1,9 @@
function GameLevelManager() {
}
GameLevelManager.prototype.getWordLevel = function() {
return 0;
}
// GameLevelManager.HEART_MAX_COUNT = 5;
@@ -0,0 +1,18 @@
function WordManager() {
this.wordList = [];
this.wordList[0] = "hello";
this.wordList[1] = "world";
this.wordIndex = 0;
}
WordManager.prototype.getWord = function(wordLevel) {
this.wordIndex = 1 - this.wordIndex;
return this.wordList[this.wordIndex];
}
WordManager.prototype.removeWord = function(wordLevel, word) {
}
+2
View File
@@ -88,6 +88,8 @@
<script src="../../game/typing/lib/typing_text_manager.js"></script> <script src="../../game/typing/lib/typing_text_manager.js"></script>
<script src="../../game/typing/lib/typing_content_bg.js"></script> <script src="../../game/typing/lib/typing_content_bg.js"></script>
<script src="../../game/typing/word_flyingsaucer/word_manager.js"></script>
<script src="../../game/typing/word_flyingsaucer/game_level_manager.js"></script>
<script src="../../game/typing/word_flyingsaucer/loading.js"></script> <script src="../../game/typing/word_flyingsaucer/loading.js"></script>
<script src="../../game/typing/word_flyingsaucer/flyingsaucer.js"></script> <script src="../../game/typing/word_flyingsaucer/flyingsaucer.js"></script>
<script src="../../game/typing/word_flyingsaucer/game.js?update_date=191225"></script> <script src="../../game/typing/word_flyingsaucer/game.js?update_date=191225"></script>