malinovsky,
class Player extends Rect {
constructor(options) {
Object.assign(this, { rate: 0.4, delay: 0 }, options);
}
update(game) {
this.delay -= game.delta;
if (keyEvent.space && this.delay < 0) {
this.delay = this.rate;
game.world.add(new Shot(this.x, this.y, 7, 7, 'red', 100));
}
}
}
class Ship extends Rect {
constructor(options) {
Object.assign(this, { rate: 0.8, delay: 0 }, options);
}
update(game) {
this.delay -= game.delta;
if (this.delay < 0) {
this.delay = this.rate;
game.world.add(new Shot(this.x, this.y, 7, 7, 'green', -100));
}
}
}
class Attack {
constructor(options) {
Object.assign(this, { size: 10, rate: 0.5, delay: 0 }, options);
}
update(game) {
this.delay -= game.delta;
if (this.delay < 0) {
this.delay = Math.random() * this.rate;
game.world.add(new Ship(Math.random() * 590, 5, 10, 10, 'green', 100));
if (!--this.size) game.world.delete(this);
}
}
}