add restart button to game over screen
This commit is contained in:
@@ -49,6 +49,45 @@ Simulation::Simulation(const GameConfig& config, unsigned int seed)
|
|||||||
|
|
||||||
Simulation::~Simulation() = default;
|
Simulation::~Simulation() = default;
|
||||||
|
|
||||||
|
void Simulation::reset(unsigned int seed)
|
||||||
|
{
|
||||||
|
m_rng.seed(seed);
|
||||||
|
m_currentTick = 0;
|
||||||
|
m_nextId = 1;
|
||||||
|
m_buildingBlocksStock = m_config.world.startingBuildingBlocks;
|
||||||
|
m_gameOver = false;
|
||||||
|
m_hqId = kInvalidEntityId;
|
||||||
|
m_playerStation1Id = kInvalidEntityId;
|
||||||
|
m_playerStation2Id = kInvalidEntityId;
|
||||||
|
m_currentEnemyStationIds[0] = kInvalidEntityId;
|
||||||
|
m_currentEnemyStationIds[1] = kInvalidEntityId;
|
||||||
|
m_fireEvents.clear();
|
||||||
|
m_blueprintDropEvents.clear();
|
||||||
|
|
||||||
|
m_beltSystem = BeltSystem(m_config.world.beltSpeedTilesPerSecond);
|
||||||
|
m_buildingSystem = std::make_unique<BuildingSystem>(
|
||||||
|
m_config,
|
||||||
|
m_beltSystem,
|
||||||
|
[this]() { return allocateId(); },
|
||||||
|
[this](int amount) { m_buildingBlocksStock += amount; },
|
||||||
|
m_rng);
|
||||||
|
m_shipSystem = std::make_unique<ShipSystem>(m_config, [this]() { return allocateId(); });
|
||||||
|
m_scrapSystem = std::make_unique<ScrapSystem>([this]() { return allocateId(); });
|
||||||
|
m_waveSystem = std::make_unique<WaveSystem>(m_config, m_rng);
|
||||||
|
m_combatSystem = std::make_unique<CombatSystem>(m_config);
|
||||||
|
|
||||||
|
m_blueprintLevels.clear();
|
||||||
|
for (const ShipDef& def : m_config.ships.ships)
|
||||||
|
{
|
||||||
|
BlueprintState state;
|
||||||
|
state.unlocked = def.availableFromStart;
|
||||||
|
state.level = def.availableFromStart ? def.blueprint.playerProductionLevel : 0;
|
||||||
|
m_blueprintLevels[def.id] = state;
|
||||||
|
}
|
||||||
|
|
||||||
|
placeInitialStructures();
|
||||||
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
// tick
|
// tick
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|||||||
@@ -29,6 +29,9 @@ public:
|
|||||||
explicit Simulation(const GameConfig& config, unsigned int seed = 0);
|
explicit Simulation(const GameConfig& config, unsigned int seed = 0);
|
||||||
~Simulation();
|
~Simulation();
|
||||||
|
|
||||||
|
// Reinitializes all simulation state as if constructed fresh.
|
||||||
|
void reset(unsigned int seed = 0);
|
||||||
|
|
||||||
// Advances the simulation by one tick. Tick order per architecture.md §Tick Order.
|
// Advances the simulation by one tick. Tick order per architecture.md §Tick Order.
|
||||||
void tick();
|
void tick();
|
||||||
|
|
||||||
|
|||||||
@@ -1121,3 +1121,24 @@ void GameWorldView::setGameSpeed(double multiplier)
|
|||||||
m_sim->buildingBlocksStock(),
|
m_sim->buildingBlocksStock(),
|
||||||
m_gameSpeedMultiplier);
|
m_gameSpeedMultiplier);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GameWorldView::resetForNewGame()
|
||||||
|
{
|
||||||
|
exitBuilderMode();
|
||||||
|
m_activeBeams.clear();
|
||||||
|
m_toasts.clear();
|
||||||
|
m_ghostRotation = Rotation::East;
|
||||||
|
m_ghostValid = false;
|
||||||
|
m_demolishMode = false;
|
||||||
|
m_demolishHoverId = kInvalidEntityId;
|
||||||
|
m_selectedIds.clear();
|
||||||
|
m_boxSelecting = false;
|
||||||
|
m_scrollXTiles = 0.0f;
|
||||||
|
m_scrollLeft = false;
|
||||||
|
m_scrollRight = false;
|
||||||
|
m_gameOverShown = false;
|
||||||
|
m_gameSpeedMultiplier = 1.0;
|
||||||
|
m_prevNonZeroSpeed = 1.0;
|
||||||
|
emit selectionChanged({});
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|||||||
@@ -51,6 +51,7 @@ public slots:
|
|||||||
void enterBuilderMode(BuildingType type);
|
void enterBuilderMode(BuildingType type);
|
||||||
void exitBuilderMode();
|
void exitBuilderMode();
|
||||||
void setGameSpeed(double multiplier);
|
void setGameSpeed(double multiplier);
|
||||||
|
void resetForNewGame();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void initializeGL() override;
|
void initializeGL() override;
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
#include <QHBoxLayout>
|
#include <QHBoxLayout>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
|
#include <QPushButton>
|
||||||
#include <QResizeEvent>
|
#include <QResizeEvent>
|
||||||
#include <QVBoxLayout>
|
#include <QVBoxLayout>
|
||||||
|
|
||||||
@@ -106,7 +107,17 @@ void MainWindow::onGameOver()
|
|||||||
box.setText(QString("HQ destroyed!\nSurvival time: %1:%2")
|
box.setText(QString("HQ destroyed!\nSurvival time: %1:%2")
|
||||||
.arg(minutes, 2, 10, QChar('0'))
|
.arg(minutes, 2, 10, QChar('0'))
|
||||||
.arg(seconds, 2, 10, QChar('0')));
|
.arg(seconds, 2, 10, QChar('0')));
|
||||||
|
QPushButton* restartBtn = box.addButton("Restart", QMessageBox::AcceptRole);
|
||||||
box.addButton("Quit", QMessageBox::RejectRole);
|
box.addButton("Quit", QMessageBox::RejectRole);
|
||||||
box.exec();
|
box.exec();
|
||||||
close();
|
|
||||||
|
if (box.clickedButton() == restartBtn)
|
||||||
|
{
|
||||||
|
m_sim->reset();
|
||||||
|
m_gameWorldView->resetForNewGame();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user