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

malinovsky,
class Game {
	constructor(canvas, ...entities) {
		// ...
		this.world = new Set(entities);
		this.cache = new Set();
		// ...
	}
	// ...
	update() {
		for (let entity of this.world) if (entity.update) entity.update(this);
		for (let entity of this.cache) {
			this.world.delete(entity);
			this.cache.delete(entity);
		}
	}
	// ...
}

class Ship extends Rect {
	// ...
	update(game) {
		// ...
		if (game.collide(this, PLAYER | SHOT | LINE )) game.cache.add(this);
	}
}

const game = new Game(canvas, new Player(), new Attack());
Ответить с цитированием