Add: FlyingSaucer class
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user