Merge branch 'spark'
This commit is contained in:
commit
8d58e41459
7 files changed
+200
-17
No files matched your search
+87
-4
@@ -204,6 +204,8 @@ namespace ZL
|
||||
|
||||
bool cfgLoaded = sparkEmitter.loadFromJsonFile("resources/config/spark_config.json", renderer, CONST_ZIP_FILE);
|
||||
bool projCfgLoaded = projectileEmitter.loadFromJsonFile("resources/config/spark_projectile_config.json", renderer, CONST_ZIP_FILE);
|
||||
bool explosionCfgLoaded = explosionEmitter.loadFromJsonFile("resources/config/explosion_config.json", renderer, CONST_ZIP_FILE);
|
||||
explosionEmitter.setEmissionPoints(std::vector<Vector3f>());
|
||||
projectileEmitter.setEmissionPoints(std::vector<Vector3f>());
|
||||
uiManager.loadFromFile("resources/config/ui.json", renderer, CONST_ZIP_FILE);
|
||||
|
||||
@@ -349,6 +351,7 @@ namespace ZL
|
||||
boxRenderArr[i].RefreshVBO();
|
||||
}
|
||||
|
||||
boxAlive.resize(boxCoordsArr.size(), true);
|
||||
|
||||
std::cout << "Init step 4 " << std::endl;
|
||||
|
||||
@@ -461,19 +464,28 @@ namespace ZL
|
||||
renderer.TranslateMatrix({ 0,0, -1.0f * Environment::zoom });
|
||||
|
||||
renderer.TranslateMatrix({ 0, -Environment::zoom * 0.03f, 0 });
|
||||
glBindTexture(GL_TEXTURE_2D, spaceshipTexture->getTexID());
|
||||
renderer.DrawVertexRenderStruct(spaceship);
|
||||
if (shipAlive) {
|
||||
glBindTexture(GL_TEXTURE_2D, spaceshipTexture->getTexID());
|
||||
renderer.DrawVertexRenderStruct(spaceship);
|
||||
}
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
for (const auto& p : projectiles) {
|
||||
if (p && p->isActive()) {
|
||||
p->draw(renderer);
|
||||
}
|
||||
}
|
||||
|
||||
if (shipAlive) {
|
||||
sparkEmitter.draw(renderer, Environment::zoom, Environment::width, Environment::height);
|
||||
projectileEmitter.draw(renderer, Environment::zoom, Environment::width, Environment::height);
|
||||
}
|
||||
|
||||
if (showExplosion) {
|
||||
explosionEmitter.draw(renderer, Environment::zoom, Environment::width, Environment::height);
|
||||
}
|
||||
|
||||
sparkEmitter.draw(renderer, Environment::zoom, Environment::width, Environment::height);
|
||||
projectileEmitter.draw(renderer, Environment::zoom, Environment::width, Environment::height);
|
||||
glDisable(GL_BLEND);
|
||||
renderer.PopMatrix();
|
||||
renderer.PopProjectionMatrix();
|
||||
@@ -503,6 +515,7 @@ namespace ZL
|
||||
|
||||
for (int i = 0; i < boxCoordsArr.size(); i++)
|
||||
{
|
||||
if (!boxAlive[i]) continue;
|
||||
renderer.PushMatrix();
|
||||
|
||||
renderer.LoadIdentity();
|
||||
@@ -677,6 +690,76 @@ namespace ZL
|
||||
sparkEmitter.update(static_cast<float>(delta));
|
||||
projectileEmitter.update(static_cast<float>(delta));
|
||||
|
||||
explosionEmitter.update(static_cast<float>(delta));
|
||||
if (shipAlive) {
|
||||
float distToSurface = planetObject.distanceToPlanetSurface(Environment::shipPosition);
|
||||
if (distToSurface <= 0.0f) {
|
||||
Vector3f localForward = { 0,0,-1 };
|
||||
Vector3f worldForward = (Environment::shipMatrix * localForward).normalized();
|
||||
const float backDistance = 400.0f;
|
||||
Environment::shipPosition = Environment::shipPosition - worldForward * backDistance;
|
||||
|
||||
shipAlive = false;
|
||||
gameOver = true;
|
||||
Environment::shipVelocity = 0.0f;
|
||||
showExplosion = true;
|
||||
|
||||
explosionEmitter.setUseWorldSpace(false);
|
||||
explosionEmitter.setEmissionPoints(std::vector<Vector3f>{ Vector3f{ 0.0f,0.0f,0.0f } });
|
||||
explosionEmitter.emit();
|
||||
|
||||
std::cerr << "GAME OVER: collision with planet (moved back and exploded)\n";
|
||||
|
||||
if (!uiGameOverShown) {
|
||||
if (uiManager.pushMenuFromFile("resources/config/game_over.json", this->renderer, CONST_ZIP_FILE)) {
|
||||
uiManager.setButtonCallback("restartButton", [this](const std::string& name) {
|
||||
this->shipAlive = true;
|
||||
this->gameOver = false;
|
||||
this->uiGameOverShown = false;
|
||||
this->showExplosion = false;
|
||||
this->explosionEmitter.setEmissionPoints(std::vector<Vector3f>());
|
||||
Environment::shipPosition = Vector3f{ 0, 0, 45000.f };
|
||||
Environment::shipVelocity = 0.0f;
|
||||
uiManager.popMenu();
|
||||
std::cerr << "Game restarted\n";
|
||||
});
|
||||
|
||||
uiManager.setButtonCallback("gameOverExitButton", [this](const std::string& name) {
|
||||
Environment::exitGameLoop = true;
|
||||
});
|
||||
|
||||
uiGameOverShown = true;
|
||||
}
|
||||
else {
|
||||
std::cerr << "Failed to load game_over.json\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < boxCoordsArr.size(); ++i) {
|
||||
if (!boxAlive[i]) continue;
|
||||
Vector3f boxWorld = boxCoordsArr[i].pos + Vector3f{ 0.0f, 0.0f, 45000.0f };
|
||||
Vector3f diff = Environment::shipPosition - boxWorld;
|
||||
float thresh = shipCollisionRadius + boxCollisionRadius;
|
||||
if (diff.squaredNorm() <= thresh * thresh) {
|
||||
boxAlive[i] = false;
|
||||
|
||||
boxRenderArr[i].data.PositionData.clear();
|
||||
boxRenderArr[i].vao.reset();
|
||||
boxRenderArr[i].positionVBO.reset();
|
||||
boxRenderArr[i].texCoordVBO.reset();
|
||||
showExplosion = true;
|
||||
|
||||
Vector3f rel = boxWorld - Environment::shipPosition;
|
||||
Vector3f camPos = Environment::inverseShipMatrix * rel;
|
||||
explosionEmitter.setUseWorldSpace(true);
|
||||
explosionEmitter.setEmissionPoints(std::vector<Vector3f>{ boxWorld });
|
||||
explosionEmitter.emit();
|
||||
|
||||
std::cerr << "Box destroyed at index " << i << std::endl;
|
||||
}
|
||||
}
|
||||
uiManager.update(static_cast<float>(delta));
|
||||
//#endif
|
||||
lastTickCount = newTickCount;
|
||||
|
||||
Reference in new issue
Block a user