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