Fix: go next word level with timing

This commit is contained in:
2019-01-06 07:20:16 +09:00
parent 9d11f4034c
commit 40f1da6e8a
3 changed files with 65 additions and 22 deletions
@@ -34,6 +34,8 @@ function FlyingSaucer(lineIndex) {
var shipBody = this.makeShipBody(0, BODY_OFFSET_Y);
this.addChild(shipBody);
this.explodeEmitter = this.makeExplodeEmitter();
var style = { font: "20px Arial", fill: FlyingSaucer.TEXT_COLOR_NORMAL};
this.wordText = game.add.text(0, 0, "text", style);
@@ -46,7 +48,7 @@ function FlyingSaucer(lineIndex) {
FlyingSaucer.prototype.initVariables = function() {
this.isActivated = false;
this.wordLevel = 0;
this.score = 0;
this.wordScore = 0;
this.speed = FlyingSaucer.DEFAULT_SPEED;
this.scoreManager = null;
@@ -81,6 +83,17 @@ FlyingSaucer.prototype.makeShipBody = function(posX, posY) {
return body;
}
FlyingSaucer.prototype.makeExplodeEmitter = function() {
explodeEmitter = game.add.emitter(this.x, this.y, 10);
explodeEmitter.makeParticles('star');
explodeEmitter.minParticleScale = 1;
explodeEmitter.maxParticleScale = 3;
explodeEmitter.forEach( function(particle) { particle.tint = 0xadff2f; } );
explodeEmitter.gravity = 0;
return explodeEmitter;
}
FlyingSaucer.prototype.update = function() {
if(this.isActivated) {
@@ -89,7 +102,7 @@ FlyingSaucer.prototype.update = function() {
this.wordText.y = this.y + FlyingSaucer.WORD_TEXT_OFFSET_Y;
if(this.y > GAME_SCREEN_SIZE.y - 200)
if(this.y > FlyingSaucer.CRASH_POS_Y)
this.crash();
} else {
this.stop();
@@ -136,28 +149,22 @@ FlyingSaucer.prototype.setActive = function(isActivated) {
FlyingSaucer.prototype.moveInitialPos = function() {
this.x = 100 + this.lineIndex * 200;
this.y = 100;
this.y = FlyingSaucer.START_POS_Y;
this.wordText.x = this.x;
this.wordText.y = this.y + FlyingSaucer.WORD_TEXT_OFFSET_Y;
this.wordText.clearColors();
this.wordText.addColor(FlyingSaucer.TEXT_COLOR_NORMAL, 0);
this.explodeEmitter = game.add.emitter(this.x, this.y, 10);
this.explodeEmitter.makeParticles('star');
this.explodeEmitter.minParticleScale = 1;
this.explodeEmitter.maxParticleScale = 3;
this.explodeEmitter.forEach( function(particle) { particle.tint = 0xadff2f; } );
this.explodeEmitter.gravity = 0;
}
FlyingSaucer.prototype.startAttack = function() {
this.moveInitialPos();
var wordLevel = this.gameLevelManager.getWordLevel();
var word = this.wordManager.getWord(wordLevel);
this.setWord(word);
this.score = this.gameLevelManager.getWordScore();
this.wordLevel = this.gameLevelManager.getWordLevel();
this.word = this.wordManager.getWord(this.wordLevel);
this.setWord(this.word);
this.wordScore = this.gameLevelManager.getWordScore();
// console.log(this.wordScore);
this.setActive(true);
}
@@ -190,13 +197,21 @@ FlyingSaucer.prototype.checkInputText = function(inputText) {
this.wordText.addColor(FlyingSaucer.TEXT_COLOR_NORMAL, index);
}
FlyingSaucer.prototype.getClearTiming = function(inputText) {
var heightDown = FlyingSaucer.CRASH_POS_Y - FlyingSaucer.START_POS_Y;
var distanceDown = this.y - FlyingSaucer.START_POS_Y;
return (heightDown - distanceDown) / heightDown;
}
FlyingSaucer.prototype.checkWord = function(inputText) {
// console.log("inputText : " + inputText);
// console.log("this.wordText : " + this.wordText);
var word = this.wordText.text;
// var word = this.wordText.text;
if(word == inputText) {
if(this.word == inputText) {
this.gameLevelManager.clearWord(this.wordLevel, this.getClearTiming());
this.wordManager.removeWord(this.wordLevel, this.word);
this.setWord("");
this.setActive(false);
@@ -207,13 +222,19 @@ FlyingSaucer.prototype.checkWord = function(inputText) {
}
FlyingSaucer.prototype.explode = function(inputText) {
this.explodeEmitter.x = this.x;
this.explodeEmitter.y = this.y;
this.explodeEmitter.start(true, 1000, null, 100);
this.timerEvent = game.time.events.add(Phaser.Timer.SECOND, this.startAttack, this);
}
FlyingSaucer.prototype.plusScore = function(inputText) {
this.scoreManager.plusScore(this.score);
var scoreText = new ScoreText(this.x, this.y, this.score);
console.log(this.wordScore);
console.log(this.getClearTiming());
var totalScore = Math.floor(this.wordScore * (this.getClearTiming() * 100));
this.scoreManager.plusScore(totalScore);
var scoreText = new ScoreText(this.x, this.y, totalScore);
}
FlyingSaucer.prototype.crash = function() {
@@ -243,7 +264,10 @@ FlyingSaucer.loadResource = function() {
FlyingSaucer.DEFAULT_SPEED = 10; // dot per sec
FlyingSaucer.DEFAULT_SPEED = 10; // dot per sec
FlyingSaucer.START_POS_Y = 100; // px
FlyingSaucer.CRASH_POS_Y = GAME_SCREEN_SIZE.y - 200; // px
FlyingSaucer.WORD_TEXT_OFFSET_Y = 30; // px