Add: FlyingSaucer class

This commit is contained in:
2019-01-03 11:43:06 +09:00
parent 7434a43fd0
commit eb41faa179
4 changed files with 133 additions and 0 deletions
@@ -0,0 +1,68 @@
FlyingSaucer.prototype = Object.create(Phaser.Sprite.prototype);
FlyingSaucer.constructor = FlyingSaucer;
function FlyingSaucer(lineIndex) {
this.lineIndex = lineIndex;
this.isActivated = false;
this.speed = FlyingSaucer.DEFAULT_SPEED;
Phaser.Sprite.call(this, game, game.world.centerX, game.world.centerY, 'alien_normal');
game.add.existing(this);
game.physics.arcade.enable(this);
this.scale.set(1);
this.anchor.set(0.5);
this.halfWidth = this.width / 2;
this.moveInitialPos();
// this.setActive(true);
}
FlyingSaucer.prototype.update = function() {
if(this.isActivated) {
var deltaTime = game.time.elapsed / 1000;
this.y += this.speed * deltaTime;
if(this.y > GAME_SCREEN_SIZE.y - 200)
this.moveInitialPos();
} else {
this.stop();
}
}
FlyingSaucer.prototype.setup = function(wordLevel, speedLevel) {
this.wordLevel = wordLevel;
this.speedLevel = speedLevel;
}
FlyingSaucer.prototype.stop = function() {
this.body.velocity.setTo(0, 0);
}
FlyingSaucer.prototype.setActive = function(isActivated) {
this.isActivated = isActivated;
}
FlyingSaucer.prototype.moveInitialPos = function() {
this.x = 50 + this.lineIndex * 100;
this.y = 100;
}
FlyingSaucer.loadResource = function() {
if(!game.cache.checkImageKey('alien_normal'))
game.load.image('alien_normal', '../../../resources/image/character/alien/green_alien.png');
}
FlyingSaucer.DEFAULT_SPEED = 10; // dot per sec
+62
View File
@@ -44,6 +44,31 @@ var WordFlyingSaucer = {
heartGauge.start();
this.initVariables();
for(var i = 0; i < 10; i++) {
var flyingsaucer = new FlyingSaucer(i);
flyingsaucer.setup(this.wordLevel, this.speedLevel);
flyingsaucer.setActive(true);
}
// input text
var INPUT_TEXT_Y = 680;
this.inputText = new InputTypeText(game.world.centerX, INPUT_TEXT_Y);
this.inputText.anchor.set(0.5);
this.inputText.canvasInput.value('');
this.inputText.canvasInput.focus();
this.inputText.canvasInput.placeHolder("입력 후 [ Enter ]키를 누르세요");
// inputText.canvasInput._onkeydown = this.checkInputText;
// inputText.canvasInput._onkeyup = function() {
var self = this;
this.inputText.canvasInput._onkeyup = function() {
self.checkTypingContents(event);
}
@@ -63,6 +88,12 @@ var WordFlyingSaucer = {
location.href = '../../web/client/menu_app.html';
},
initVariables: function() {
this.wordLevel = 0;
this.speedLevel = 0;
},
startGame: function() {
},
@@ -91,6 +122,37 @@ var WordFlyingSaucer = {
location.href = '../../web/client/result.html';
},
checkTypingContents: function(event) {
if(event.keyCode == Phaser.Keyboard.ENTER) {
// console.log("### enter ###");
var inputContent = this.inputText.canvasInput.value();
/*
var typingContent = this.typingRandomContents[this.typingIndex];
if(inputContent === typingContent) {
this.calculateTypingRecord(typingContent);
this.playNextContent();
if(this.typingIndex == this.typingContentLength)
this.gameOver();
// this.goResult();
// this.state.start('TypingTestResult');
}
*/
}
else {
/*
if(this.isTyping == false) {
// console.log(event);
this.setTimeTypingStart();
}
this.showTypingContentHighlight();
*/
}
},
}
@@ -32,6 +32,8 @@ var Loading = {
game.load.image('star', '../../../resources/image/ui/star_particle.png');
HeartGauge.loadResources();
FlyingSaucer.loadResource();
// game.load.image('hand_left', '../../../resources/image/ui/hand_left.png');
// game.load.image('hand_right', '../../../resources/image/ui/hand_right.png');