Пример #1
0
void MeteorSpawner::spawn(Player &p)
{
	int n = 1; // number of meteors to spawn

	if (canSpawn())
	{
		POINT start;
		POINT end;
		int velocity;

		for (int i = index; i < (n + index); i++)
		{
			i = i % MAX_METEORS;

			if (meteors[i].isAlive()) // don't overwrite existing meteors
				continue;

			start.x = rand() % (B_WIDTH + 80) - 40;
			start.y = -50;
			end.x = p.getPosition().x + ((rand() % 200) - 100);
			end.y = B_HEIGHT;

			if (start.x == end.x) // TODO: handle undefined slopes
			{
				end.x++;
			}

			meteors[i] = Meteor(start, end);
		}

		index = (index + n) % MAX_METEORS;
		ticks = 0; // reset
	}
	else
	{
		ticks++;
		if (delay != 0)
			delay--;
	}
}
Пример #2
0
void Production::update() {
    if(mUnits.size() > 0) {
        Unit* unit = mUnits[0];
        if(!unit->isBuilding()) {
            unit->startBuildNoCost();
        }
        unit->update();
        if(unit->isBuilt()) {
            if(canSpawn()) {
                spawn(unit);
            } else {
                Object* objAtSpawn = Game::get()->world()->at(mSpawnPos);
                if(objAtSpawn != nullptr) {
                    Unit* blockingUnit = objAtSpawn->as<Unit>();
                    if(blockingUnit != nullptr) {
                        unit->attack(blockingUnit);
                    }
                }
            }
        }
    }
    Buildable::update();
}