Fix: change cockpit color

This commit is contained in:
2019-01-06 07:51:54 +09:00
parent 40f1da6e8a
commit 3fce5e25fa
2 changed files with 58 additions and 12 deletions
@@ -19,8 +19,8 @@ function FlyingSaucer(lineIndex) {
var BODY_OFFSET_Y = 28;
var JET_OFFSET_Y = 52;
var cockpit = this.makeCockpit(0, COCKPIT_OFFSET_Y);
this.addChild(cockpit);
this.cockpit = this.makeCockpit(0, COCKPIT_OFFSET_Y);
this.addChild(this.cockpit);
this.jetLeft = this.makeJet(-50, JET_OFFSET_Y);
this.addChild(this.jetLeft);
@@ -50,6 +50,7 @@ FlyingSaucer.prototype.initVariables = function() {
this.wordLevel = 0;
this.wordScore = 0;
this.speed = FlyingSaucer.DEFAULT_SPEED;
this.jetStatus = FlyingSaucer.JET_STATUS_HIGH;
this.scoreManager = null;
this.heartManager = null;
@@ -71,7 +72,7 @@ FlyingSaucer.prototype.makeCockpit = function(posX, posY) {
FlyingSaucer.prototype.makeJet = function(posX, posY) {
var jet = game.make.sprite(posX, posY, 'ship_jet');
jet.anchor.set(0.5);
jet.tint = 0xffff00;
jet.tint = FlyingSaucer.JET_COLOR_HIGH;
return jet;
}
@@ -102,6 +103,8 @@ FlyingSaucer.prototype.update = function() {
this.wordText.y = this.y + FlyingSaucer.WORD_TEXT_OFFSET_Y;
this.updateJetColor();
if(this.y > FlyingSaucer.CRASH_POS_Y)
this.crash();
} else {
@@ -109,6 +112,29 @@ FlyingSaucer.prototype.update = function() {
}
}
FlyingSaucer.prototype.updateJetColor = function() {
var landingRatio = this.getLandingRatio();
if(this.jetStatus == FlyingSaucer.JET_STATUS_HIGH && landingRatio < 0.9) {
this.jetStatus = FlyingSaucer.JET_STATUS_MIDDLE;
this.changeJetColor(FlyingSaucer.JET_COLOR_MIDDLE);
} else if(this.jetStatus == FlyingSaucer.JET_STATUS_MIDDLE && landingRatio < 0.1) {
this.jetStatus = FlyingSaucer.JET_STATUS_LOW;
this.changeJetColor(FlyingSaucer.JET_COLOR_LOW);
}
}
FlyingSaucer.prototype.changeJetColor = function(color) {
this.jetLeft.tint = color;
this.jetCenter.tint = color;
this.jetRight.tint = color;
}
FlyingSaucer.prototype.changeCockpitColor = function(color) {
this.cockpit.tint = FlyingSaucer.COKCPIT_COLOR[this.wordLevel - 1];
}
FlyingSaucer.prototype.setScoreManager = function(scoreManager) {
this.scoreManager = scoreManager;
}
@@ -150,6 +176,11 @@ FlyingSaucer.prototype.setActive = function(isActivated) {
FlyingSaucer.prototype.moveInitialPos = function() {
this.x = 100 + this.lineIndex * 200;
this.y = FlyingSaucer.START_POS_Y;
this.speed += FlyingSaucer.SPEED_UP_AMOUNT;
this.changeCockpitColor();
this.jetStatus = FlyingSaucer.JET_STATUS_HIGH;
this.changeJetColor(FlyingSaucer.JET_COLOR_HIGH);
this.wordText.x = this.x;
this.wordText.y = this.y + FlyingSaucer.WORD_TEXT_OFFSET_Y;
@@ -159,12 +190,13 @@ FlyingSaucer.prototype.moveInitialPos = function() {
FlyingSaucer.prototype.startAttack = function() {
this.moveInitialPos();
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.moveInitialPos();
this.setActive(true);
}
@@ -197,7 +229,7 @@ FlyingSaucer.prototype.checkInputText = function(inputText) {
this.wordText.addColor(FlyingSaucer.TEXT_COLOR_NORMAL, index);
}
FlyingSaucer.prototype.getClearTiming = function(inputText) {
FlyingSaucer.prototype.getLandingRatio = function(inputText) {
var heightDown = FlyingSaucer.CRASH_POS_Y - FlyingSaucer.START_POS_Y;
var distanceDown = this.y - FlyingSaucer.START_POS_Y;
return (heightDown - distanceDown) / heightDown;
@@ -210,7 +242,7 @@ FlyingSaucer.prototype.checkWord = function(inputText) {
// var word = this.wordText.text;
if(this.word == inputText) {
this.gameLevelManager.clearWord(this.wordLevel, this.getClearTiming());
this.gameLevelManager.clearWord(this.wordLevel, this.getLandingRatio());
this.wordManager.removeWord(this.wordLevel, this.word);
this.setWord("");
this.setActive(false);
@@ -230,9 +262,9 @@ FlyingSaucer.prototype.explode = function(inputText) {
}
FlyingSaucer.prototype.plusScore = function(inputText) {
console.log(this.wordScore);
console.log(this.getClearTiming());
var totalScore = Math.floor(this.wordScore * (this.getClearTiming() * 100));
// console.log(this.wordScore);
// console.log(this.getLandingRatio());
var totalScore = Math.floor(this.wordScore * (this.getLandingRatio() * 100));
this.scoreManager.plusScore(totalScore);
var scoreText = new ScoreText(this.x, this.y, totalScore);
}
@@ -265,11 +297,25 @@ FlyingSaucer.loadResource = function() {
FlyingSaucer.DEFAULT_SPEED = 10; // dot per sec
FlyingSaucer.SPEED_UP_AMOUNT = 4; // dot per sec
FlyingSaucer.SPEED_DOWN_AMOUNT = FlyingSaucer.SPEED_UP_AMOUNT / 2; // 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
FlyingSaucer.TEXT_COLOR_NORMAL = "#000000";
FlyingSaucer.TEXT_COLOR_CORRECT = "#ffff4d";
FlyingSaucer.TEXT_COLOR_NORMAL = "#000000";
FlyingSaucer.TEXT_COLOR_CORRECT = "#ffff4d";
FlyingSaucer.JET_STATUS_HIGH = 0;
FlyingSaucer.JET_STATUS_MIDDLE = 1;
FlyingSaucer.JET_STATUS_LOW = 2;
FlyingSaucer.JET_COLOR_HIGH = 0x00ffff;
FlyingSaucer.JET_COLOR_MIDDLE = 0xffff00;
FlyingSaucer.JET_COLOR_LOW = 0xff0000;
FlyingSaucer.COKCPIT_COLOR = [
0xff0000, 0xff6600, 0xff0000, 0x00ffff, 0x00ffff, 0x6666ff, 0xff00ff
]
@@ -26,6 +26,6 @@ GameLevelManager.prototype.clearWord = function(wordLevel, clearTiming) {
}
GameLevelManager.LEVELUP_TIMING = 0.9;
GameLevelManager.LEVELUP_TIMING = 0.5;
GameLevelManager.MAX_KOR_WORD_LEVEL = 7;