Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void TWorld::SpawnShips(TPlanet& from, TPlanet& to, float energyPercents, size_t playerId, size_t maxShips) {
- float totalShipsEnergy = from.Energy * energyPercents;
- from.Energy -= totalShipsEnergy;
- size_t shipsCount = std::min(1 + (int)(totalShipsEnergy / 7.0), int(maxShips));
- float energyPerShip = totalShipsEnergy / shipsCount;
- QPointF direction;
- direction.setX(to.Position.x() - from.Position.x());
- direction.setY(to.Position.y() - from.Position.y());
- Normalize(direction);
- QPointF shipPosition = from.Position;
- shipPosition.setX(shipPosition.x() + direction.x() * (from.Radius + 6.0));
- shipPosition.setY(shipPosition.y() + direction.y() * (from.Radius + 6.0));
- QPointF shipSpeed = direction;
- shipSpeed.setX(shipSpeed.x() * 2.5);
- shipSpeed.setY(shipSpeed.y() * 2.5);
- for (size_t i = 0; i < shipsCount; ++i) {
- TShip ship;
- ship.Position = shipPosition;
- ship.Position.setX(ship.Position.x() + rand() % 6 - 3);
- ship.Position.setY(ship.Position.y() + rand() % 6 - 3);
- ship.Energy = energyPerShip;
- ship.PlayerId = playerId;
- ship.Speed = shipSpeed;
- ship.Target = to.Position;
- from.SpawnQueue.push_back(ship);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement