Показать сообщение отдельно
  #28 (permalink)  
Старый 11.10.2017, 05:36
Профессор
Отправить личное сообщение для Rise Посмотреть профиль Найти все сообщения от Rise
 
Регистрация: 07.11.2013
Сообщений: 4,662

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);
		}
	}
}
Ответить с цитированием