Compare commits
8 Commits
67c0696061
...
96d879076a
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
96d879076a | ||
|
|
8f3528f9a1 | ||
| 0f415b6ed6 | |||
|
|
52a52ef960 | ||
|
|
90ad3392cb | ||
|
|
dc5c76f888 | ||
|
|
bdce619e68 | ||
|
|
13af968a04 |
@ -41,3 +41,9 @@ check_and_download("https://gitlab.com/libeigen/eigen/-/archive/5.0.0/eigen-5.0.
|
||||
|
||||
# 6) Boost
|
||||
check_and_download("https://archives.boost.io/release/1.90.0/source/boost_1_90_0.zip" "boost_1_90_0.zip" "boost_1_90_0" "boost")
|
||||
|
||||
# 7) FreeType
|
||||
check_and_download("https://download.savannah.gnu.org/releases/freetype/freetype-2.14.1.tar.gz" "freetype-2.14.1.tar.gz" "freetype-2.14.1" "CMakeLists.txt")
|
||||
|
||||
# 8) SDL_ttf
|
||||
check_and_download("https://github.com/libsdl-org/SDL_ttf/archive/refs/tags/release-2.24.0.zip" "release-2.24.0.zip" "SDL_ttf-release-2.24.0" "CMakeLists.txt")
|
||||
|
||||
@ -314,7 +314,215 @@ set_target_properties(libzip_external_lib PROPERTIES
|
||||
)
|
||||
|
||||
# ===========================================
|
||||
# 5) Eigen (5.0.0.zip → eigen-5.0.0) - HEADER-ONLY
|
||||
# 5) FreeType (2.14.1) - dependency for SDL_ttf
|
||||
# ===========================================
|
||||
set(FREETYPE_SRC_DIR "${THIRDPARTY_DIR}/freetype-2.14.1")
|
||||
set(FREETYPE_BASE_DIR "${FREETYPE_SRC_DIR}/install")
|
||||
|
||||
set(_have_freetype TRUE)
|
||||
foreach(cfg IN LISTS BUILD_CONFIGS)
|
||||
if(NOT EXISTS "${FREETYPE_BASE_DIR}-${cfg}/lib/freetype.lib" AND
|
||||
NOT EXISTS "${FREETYPE_BASE_DIR}-${cfg}/lib/freetyped.lib")
|
||||
set(_have_freetype FALSE)
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
if(NOT _have_freetype)
|
||||
foreach(cfg IN LISTS BUILD_CONFIGS)
|
||||
log("Configuring FreeType (${cfg}) ...")
|
||||
execute_process(
|
||||
COMMAND ${CMAKE_COMMAND}
|
||||
-G "${CMAKE_GENERATOR}"
|
||||
-S "${FREETYPE_SRC_DIR}"
|
||||
-B "${FREETYPE_SRC_DIR}/build-${cfg}"
|
||||
-DCMAKE_INSTALL_PREFIX=${FREETYPE_BASE_DIR}-${cfg}
|
||||
-DCMAKE_PREFIX_PATH="${ZLIB_INSTALL_DIR};${LIBPNG_INSTALL_DIR}"
|
||||
-DCMAKE_DISABLE_FIND_PACKAGE_HarfBuzz=TRUE
|
||||
-DCMAKE_DISABLE_FIND_PACKAGE_BZip2=TRUE
|
||||
-DFT_DISABLE_BROTLI=ON
|
||||
-DBUILD_SHARED_LIBS=OFF
|
||||
RESULT_VARIABLE _ft_cfg_res
|
||||
)
|
||||
if(NOT _ft_cfg_res EQUAL 0)
|
||||
message(FATAL_ERROR "FreeType configure failed for ${cfg}")
|
||||
endif()
|
||||
|
||||
log("Building FreeType (${cfg}) ...")
|
||||
execute_process(
|
||||
COMMAND ${CMAKE_COMMAND}
|
||||
--build "${FREETYPE_SRC_DIR}/build-${cfg}" --config ${cfg}
|
||||
RESULT_VARIABLE _ft_build_res
|
||||
)
|
||||
if(NOT _ft_build_res EQUAL 0)
|
||||
message(FATAL_ERROR "FreeType build failed for ${cfg}")
|
||||
endif()
|
||||
|
||||
log("Installing FreeType (${cfg}) ...")
|
||||
execute_process(
|
||||
COMMAND ${CMAKE_COMMAND}
|
||||
--install "${FREETYPE_SRC_DIR}/build-${cfg}" --config ${cfg}
|
||||
RESULT_VARIABLE _ft_inst_res
|
||||
)
|
||||
if(NOT _ft_inst_res EQUAL 0)
|
||||
message(FATAL_ERROR "FreeType install failed for ${cfg}")
|
||||
endif()
|
||||
endforeach()
|
||||
endif()
|
||||
|
||||
set(_ft_debug_lib "")
|
||||
foreach(cand
|
||||
"${FREETYPE_BASE_DIR}-Debug/lib/freetyped.lib"
|
||||
"${FREETYPE_BASE_DIR}-Debug/lib/freetype.lib"
|
||||
)
|
||||
if(EXISTS "${cand}")
|
||||
set(_ft_debug_lib "${cand}")
|
||||
break()
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
set(_ft_release_lib "")
|
||||
foreach(cand
|
||||
"${FREETYPE_BASE_DIR}-Release/lib/freetype.lib"
|
||||
)
|
||||
if(EXISTS "${cand}")
|
||||
set(_ft_release_lib "${cand}")
|
||||
break()
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
if(_ft_debug_lib STREQUAL "" OR _ft_release_lib STREQUAL "")
|
||||
message(FATAL_ERROR "FreeType libs not found in ${FREETYPE_BASE_DIR}-Debug/Release")
|
||||
endif()
|
||||
|
||||
add_library(freetype_external_lib UNKNOWN IMPORTED GLOBAL)
|
||||
set_target_properties(freetype_external_lib PROPERTIES
|
||||
IMPORTED_LOCATION_DEBUG "${_ft_debug_lib}"
|
||||
IMPORTED_LOCATION_RELEASE "${_ft_release_lib}"
|
||||
INTERFACE_INCLUDE_DIRECTORIES
|
||||
"$<IF:$<CONFIG:Debug>,${FREETYPE_BASE_DIR}-Debug/include,${FREETYPE_BASE_DIR}-Release/include>"
|
||||
)
|
||||
|
||||
# ===========================================
|
||||
# 6) SDL_ttf (2.24.0)
|
||||
# ===========================================
|
||||
set(SDL2TTF_SRC_DIR "${THIRDPARTY_DIR}/SDL_ttf-release-2.24.0")
|
||||
set(SDL2TTF_BASE_DIR "${SDL2TTF_SRC_DIR}/install")
|
||||
|
||||
set(_have_sdl2ttf TRUE)
|
||||
foreach(cfg IN LISTS BUILD_CONFIGS)
|
||||
if(NOT EXISTS "${SDL2TTF_BASE_DIR}-${cfg}/lib/SDL2_ttf.lib" AND
|
||||
NOT EXISTS "${SDL2TTF_BASE_DIR}-${cfg}/lib/SDL2_ttfd.lib")
|
||||
set(_have_sdl2ttf FALSE)
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
if(NOT _have_sdl2ttf)
|
||||
foreach(cfg IN LISTS BUILD_CONFIGS)
|
||||
|
||||
if(cfg STREQUAL "Debug")
|
||||
set(_SDL2_LIB "${SDL2_INSTALL_DIR}/lib/SDL2d.lib")
|
||||
else()
|
||||
set(_SDL2_LIB "${SDL2_INSTALL_DIR}/lib/SDL2.lib")
|
||||
endif()
|
||||
|
||||
set(_FT_PREFIX "${FREETYPE_BASE_DIR}-${cfg}")
|
||||
|
||||
set(_FT_LIB "")
|
||||
foreach(cand
|
||||
"${_FT_PREFIX}/lib/freetyped.lib"
|
||||
"${_FT_PREFIX}/lib/freetype.lib"
|
||||
)
|
||||
if(EXISTS "${cand}")
|
||||
set(_FT_LIB "${cand}")
|
||||
break()
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
if(_FT_LIB STREQUAL "")
|
||||
message(FATAL_ERROR "FreeType library not found for ${cfg}")
|
||||
endif()
|
||||
|
||||
log("Configuring SDL_ttf (${cfg}) ...")
|
||||
execute_process(
|
||||
COMMAND ${CMAKE_COMMAND}
|
||||
-G "${CMAKE_GENERATOR}"
|
||||
-S "${SDL2TTF_SRC_DIR}"
|
||||
-B "${SDL2TTF_SRC_DIR}/build-${cfg}"
|
||||
-DCMAKE_INSTALL_PREFIX=${SDL2TTF_BASE_DIR}-${cfg}
|
||||
-DCMAKE_PREFIX_PATH=${_FT_PREFIX};${SDL2_INSTALL_DIR}
|
||||
-DSDL2_LIBRARY=${_SDL2_LIB}
|
||||
-DSDL2_INCLUDE_DIR=${SDL2_INSTALL_DIR}/include/SDL2
|
||||
-DFREETYPE_LIBRARY=${_FT_LIB}
|
||||
-DFREETYPE_INCLUDE_DIR=${_FT_PREFIX}/include
|
||||
-DFREETYPE_INCLUDE_DIRS=${_FT_PREFIX}/include
|
||||
-DSDL2TTF_VENDORED=OFF
|
||||
-DSDL2TTF_SAMPLES=OFF
|
||||
RESULT_VARIABLE _ttf_cfg_res
|
||||
)
|
||||
if(NOT _ttf_cfg_res EQUAL 0)
|
||||
message(FATAL_ERROR "SDL_ttf configure failed for ${cfg}")
|
||||
endif()
|
||||
|
||||
log("Building SDL_ttf (${cfg}) ...")
|
||||
execute_process(
|
||||
COMMAND ${CMAKE_COMMAND}
|
||||
--build "${SDL2TTF_SRC_DIR}/build-${cfg}" --config ${cfg}
|
||||
RESULT_VARIABLE _ttf_build_res
|
||||
)
|
||||
if(NOT _ttf_build_res EQUAL 0)
|
||||
message(FATAL_ERROR "SDL_ttf build failed for ${cfg}")
|
||||
endif()
|
||||
|
||||
log("Installing SDL_ttf (${cfg}) ...")
|
||||
execute_process(
|
||||
COMMAND ${CMAKE_COMMAND}
|
||||
--install "${SDL2TTF_SRC_DIR}/build-${cfg}" --config ${cfg}
|
||||
RESULT_VARIABLE _ttf_inst_res
|
||||
)
|
||||
if(NOT _ttf_inst_res EQUAL 0)
|
||||
message(FATAL_ERROR "SDL_ttf install failed for ${cfg}")
|
||||
endif()
|
||||
|
||||
endforeach()
|
||||
endif()
|
||||
|
||||
set(_ttf_debug_lib "")
|
||||
foreach(cand
|
||||
"${SDL2TTF_BASE_DIR}-Debug/lib/SDL2_ttfd.lib"
|
||||
"${SDL2TTF_BASE_DIR}-Debug/lib/SDL2_ttf.lib"
|
||||
)
|
||||
if(EXISTS "${cand}")
|
||||
set(_ttf_debug_lib "${cand}")
|
||||
break()
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
set(_ttf_release_lib "")
|
||||
foreach(cand
|
||||
"${SDL2TTF_BASE_DIR}-Release/lib/SDL2_ttf.lib"
|
||||
)
|
||||
if(EXISTS "${cand}")
|
||||
set(_ttf_release_lib "${cand}")
|
||||
break()
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
if(_ttf_debug_lib STREQUAL "" OR _ttf_release_lib STREQUAL "")
|
||||
message(FATAL_ERROR "SDL_ttf libs not found in install-Debug / install-Release")
|
||||
endif()
|
||||
|
||||
add_library(SDL2_ttf_external_lib UNKNOWN IMPORTED GLOBAL)
|
||||
set_target_properties(SDL2_ttf_external_lib PROPERTIES
|
||||
IMPORTED_LOCATION_DEBUG "${_ttf_debug_lib}"
|
||||
IMPORTED_LOCATION_RELEASE "${_ttf_release_lib}"
|
||||
INTERFACE_INCLUDE_DIRECTORIES
|
||||
"$<IF:$<CONFIG:Debug>,${SDL2TTF_BASE_DIR}-Debug/include,${SDL2TTF_BASE_DIR}-Release/include>;$<IF:$<CONFIG:Debug>,${SDL2TTF_BASE_DIR}-Debug/include/SDL2,${SDL2TTF_BASE_DIR}-Release/include/SDL2>"
|
||||
INTERFACE_LINK_LIBRARIES
|
||||
"SDL2_external_lib;freetype_external_lib"
|
||||
)
|
||||
|
||||
# ===========================================
|
||||
# 7) Eigen (5.0.0.zip → eigen-5.0.0) - HEADER-ONLY
|
||||
# ===========================================
|
||||
set(EIGEN_SRC_DIR "${THIRDPARTY_DIR}/eigen-5.0.0")
|
||||
|
||||
@ -324,7 +532,7 @@ if(NOT TARGET eigen_external_lib)
|
||||
endif()
|
||||
|
||||
# ===========================================
|
||||
# 6) Boost (1.90.0) - HEADER-ONLY
|
||||
# 8) Boost (1.90.0) - HEADER-ONLY
|
||||
# ===========================================
|
||||
set(BOOST_VERSION "1.90.0")
|
||||
set(BOOST_ARCHIVE_NAME "boost_1_90_0.zip")
|
||||
|
||||
@ -91,6 +91,8 @@ target_link_libraries(space-game001 PRIVATE
|
||||
libpng_external_lib
|
||||
zlib_external_lib
|
||||
libzip_external_lib
|
||||
freetype_external_lib
|
||||
SDL2_ttf_external_lib
|
||||
eigen_external_lib
|
||||
boost_external_lib
|
||||
)
|
||||
@ -114,6 +116,8 @@ if (WIN32)
|
||||
|
||||
set(ZLIB_DLL_SRC "$<IF:$<CONFIG:Debug>,${ZLIB_INSTALL_DIR}/bin/zlibd.dll,${ZLIB_INSTALL_DIR}/bin/zlib.dll>")
|
||||
set(ZLIB_DLL_DST "$<IF:$<CONFIG:Debug>,$<TARGET_FILE_DIR:space-game001>/zlibd.dll,$<TARGET_FILE_DIR:space-game001>/zlib.dll>")
|
||||
|
||||
set(SDL2TTF_DLL_SRC "$<IF:$<CONFIG:Debug>,${SDL2TTF_BASE_DIR}-Debug/bin/SDL2_ttfd.dll,${SDL2TTF_BASE_DIR}-Release/bin/SDL2_ttf.dll>")
|
||||
|
||||
|
||||
add_custom_command(TARGET space-game001 POST_BUILD
|
||||
@ -132,6 +136,10 @@ if (WIN32)
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different
|
||||
"${ZLIB_DLL_SRC}"
|
||||
"${ZLIB_DLL_DST}"
|
||||
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different
|
||||
"${SDL2TTF_DLL_SRC}"
|
||||
"$<TARGET_FILE_DIR:space-game001>"
|
||||
)
|
||||
endif()
|
||||
|
||||
|
||||
@ -9,7 +9,7 @@
|
||||
"lifeTimeRange": [200.0, 800.0],
|
||||
"emissionRate": 50.0,
|
||||
"maxParticles": 5,
|
||||
"particleSize": 0.5,
|
||||
"particleSize": 2,
|
||||
"biasX": 0.1,
|
||||
"shaderProgramName": "default"
|
||||
}
|
||||
@ -10,10 +10,12 @@
|
||||
#endif
|
||||
namespace ZL {
|
||||
|
||||
|
||||
|
||||
int Environment::windowHeaderHeight = 0;
|
||||
int Environment::width = 0;
|
||||
int Environment::height = 0;
|
||||
float Environment::zoom = 36.f;
|
||||
float Environment::zoom = DEFAULT_ZOOM;
|
||||
|
||||
|
||||
SDL_Window* Environment::window = nullptr;
|
||||
|
||||
@ -10,6 +10,8 @@
|
||||
|
||||
namespace ZL {
|
||||
|
||||
constexpr float DEFAULT_ZOOM = 36.f;
|
||||
|
||||
class Environment {
|
||||
public:
|
||||
static int windowHeaderHeight;
|
||||
|
||||
164
src/Game.cpp
164
src/Game.cpp
@ -1,6 +1,7 @@
|
||||
#include "Game.h"
|
||||
#include "AnimatedModel.h"
|
||||
#include "BoneAnimatedModel.h"
|
||||
#include "planet/PlanetData.h"
|
||||
#include "utils/Utils.h"
|
||||
#include "render/OpenGlExtensions.h"
|
||||
#include <iostream>
|
||||
@ -263,7 +264,7 @@ namespace ZL
|
||||
//spaceshipTexture = std::make_unique<Texture>(CreateTextureDataFromPng("resources/DefaultMaterial_BaseColor_shine.png", CONST_ZIP_FILE));
|
||||
//spaceshipBase = LoadFromTextFile02("resources/spaceship006.txt", CONST_ZIP_FILE);
|
||||
//spaceshipBase.RotateByMatrix(Eigen::Quaternionf(Eigen::AngleAxisf(M_PI / 2.0, Eigen::Vector3f::UnitY())).toRotationMatrix());// QuatFromRotateAroundY(M_PI / 2.0).toRotationMatrix());
|
||||
|
||||
|
||||
//spaceshipTexture = std::make_unique<Texture>(CreateTextureDataFromPng("./resources/cap_D.png", CONST_ZIP_FILE));
|
||||
//spaceshipBase = LoadFromTextFile02("./resources/spaceship006x.txt", CONST_ZIP_FILE);
|
||||
//spaceshipBase.RotateByMatrix(Eigen::Quaternionf(Eigen::AngleAxisf(-M_PI / 2.0, Eigen::Vector3f::UnitY())).toRotationMatrix());// QuatFromRotateAroundY(M_PI / 2.0).toRotationMatrix());
|
||||
@ -745,23 +746,31 @@ namespace ZL
|
||||
projectileEmitter.update(static_cast<float>(delta));
|
||||
|
||||
explosionEmitter.update(static_cast<float>(delta));
|
||||
if (showExplosion) {
|
||||
uint64_t now = SDL_GetTicks64();
|
||||
if (lastExplosionTime != 0 && now - lastExplosionTime >= explosionDurationMs) {
|
||||
showExplosion = false;
|
||||
explosionEmitter.setEmissionPoints(std::vector<Vector3f>());
|
||||
explosionEmitter.setUseWorldSpace(false);
|
||||
}
|
||||
}
|
||||
if (shipAlive) {
|
||||
float distToSurface = planetObject.distanceToPlanetSurface(Environment::shipState.position);
|
||||
if (distToSurface <= 0.0f) {
|
||||
|
||||
Vector3f localForward = { 0,0,-1 };
|
||||
Vector3f worldForward = (Environment::shipState.rotation * localForward).normalized();
|
||||
const float backDistance = 400.0f;
|
||||
Environment::shipState.position = Environment::shipState.position - worldForward * backDistance;
|
||||
Vector3f dir = (Environment::shipState.position - PlanetData::PLANET_CENTER_OFFSET).normalized();
|
||||
Vector3f collisionPoint = PlanetData::PLANET_CENTER_OFFSET + dir * PlanetData::PLANET_RADIUS;
|
||||
Environment::shipState.position = PlanetData::PLANET_CENTER_OFFSET + dir * (PlanetData::PLANET_RADIUS + shipCollisionRadius + 0.1f);
|
||||
|
||||
shipAlive = false;
|
||||
gameOver = true;
|
||||
Environment::shipState.velocity = 0.0f;
|
||||
showExplosion = true;
|
||||
|
||||
explosionEmitter.setUseWorldSpace(false);
|
||||
explosionEmitter.setEmissionPoints(std::vector<Vector3f>{ Vector3f{ 0.0f,0.0f,0.0f } });
|
||||
explosionEmitter.setUseWorldSpace(true);
|
||||
explosionEmitter.setEmissionPoints(std::vector<Vector3f>{ collisionPoint });
|
||||
explosionEmitter.emit();
|
||||
lastExplosionTime = SDL_GetTicks64();
|
||||
|
||||
std::cerr << "GAME OVER: collision with planet (moved back and exploded)\n";
|
||||
|
||||
@ -773,8 +782,14 @@ namespace ZL
|
||||
this->uiGameOverShown = false;
|
||||
this->showExplosion = false;
|
||||
this->explosionEmitter.setEmissionPoints(std::vector<Vector3f>());
|
||||
|
||||
Environment::shipState.position = Vector3f{ 0, 0, 45000.f };
|
||||
Environment::shipState.velocity = 0.0f;
|
||||
Environment::shipState.rotation = Eigen::Matrix3f::Identity();
|
||||
Environment::inverseShipMatrix = Eigen::Matrix3f::Identity();
|
||||
Environment::zoom = DEFAULT_ZOOM;
|
||||
Environment::tapDownHold = false;
|
||||
|
||||
uiManager.popMenu();
|
||||
std::cerr << "Game restarted\n";
|
||||
});
|
||||
@ -790,6 +805,109 @@ namespace ZL
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
bool stoneCollided = false;
|
||||
int collidedTriIdx = -1;
|
||||
Vector3f collidedStonePos = Vector3f{ 0.0f, 0.0f, 0.0f };
|
||||
float collidedStoneRadius = 0.0f;
|
||||
|
||||
for (int triIdx : planetObject.triangleIndicesToDraw) {
|
||||
if (triIdx < 0 || triIdx >= static_cast<int>(planetObject.planetStones.allInstances.size()))
|
||||
continue;
|
||||
|
||||
if (planetObject.planetStones.statuses.size() <= static_cast<size_t>(triIdx))
|
||||
continue;
|
||||
|
||||
if (planetObject.planetStones.statuses[triIdx] != ChunkStatus::Live)
|
||||
continue;
|
||||
|
||||
const auto& instances = planetObject.planetStones.allInstances[triIdx];
|
||||
for (const auto& inst : instances) {
|
||||
|
||||
Vector3f stoneWorld = inst.position;
|
||||
Vector3f diff = Environment::shipState.position - stoneWorld;
|
||||
|
||||
float maxScale = (std::max)({ inst.scale(0), inst.scale(1), inst.scale(2) });
|
||||
float stoneRadius = StoneParams::BASE_SCALE * maxScale * 0.9f;
|
||||
float thresh = shipCollisionRadius + stoneRadius;
|
||||
|
||||
if (diff.squaredNorm() <= thresh * thresh) {
|
||||
stoneCollided = true;
|
||||
collidedTriIdx = triIdx;
|
||||
collidedStonePos = stoneWorld;
|
||||
collidedStoneRadius = stoneRadius;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (stoneCollided) break;
|
||||
}
|
||||
|
||||
if (stoneCollided) {
|
||||
Vector3f away = (Environment::shipState.position - collidedStonePos);
|
||||
if (away.squaredNorm() <= 1e-6f) {
|
||||
away = Vector3f{ 0.0f, 1.0f, 0.0f };
|
||||
}
|
||||
away.normalize();
|
||||
|
||||
Environment::shipState.position = collidedStonePos + away * (collidedStoneRadius + shipCollisionRadius + 0.1f);
|
||||
|
||||
shipAlive = false;
|
||||
gameOver = true;
|
||||
Environment::shipState.velocity = 0.0f;
|
||||
showExplosion = true;
|
||||
|
||||
explosionEmitter.setUseWorldSpace(true);
|
||||
explosionEmitter.setEmissionPoints(std::vector<Vector3f>{ collidedStonePos });
|
||||
explosionEmitter.emit();
|
||||
lastExplosionTime = SDL_GetTicks64();
|
||||
|
||||
std::cerr << "GAME OVER: collision with stone on triangle " << collidedTriIdx << std::endl;
|
||||
|
||||
if (collidedTriIdx >= 0 && collidedTriIdx < static_cast<int>(planetObject.stonesToRender.size())) {
|
||||
planetObject.stonesToRender[collidedTriIdx].data.PositionData.clear();
|
||||
planetObject.stonesToRender[collidedTriIdx].vao.reset();
|
||||
planetObject.stonesToRender[collidedTriIdx].positionVBO.reset();
|
||||
planetObject.stonesToRender[collidedTriIdx].normalVBO.reset();
|
||||
planetObject.stonesToRender[collidedTriIdx].tangentVBO.reset();
|
||||
planetObject.stonesToRender[collidedTriIdx].binormalVBO.reset();
|
||||
planetObject.stonesToRender[collidedTriIdx].colorVBO.reset();
|
||||
planetObject.stonesToRender[collidedTriIdx].texCoordVBO.reset();
|
||||
}
|
||||
if (collidedTriIdx >= 0 && collidedTriIdx < static_cast<int>(planetObject.planetStones.statuses.size())) {
|
||||
planetObject.planetStones.statuses[collidedTriIdx] = ChunkStatus::Empty;
|
||||
}
|
||||
|
||||
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::shipState.position = Vector3f{ 0, 0, 45000.f };
|
||||
Environment::shipState.velocity = 0.0f;
|
||||
Environment::shipState.rotation = Eigen::Matrix3f::Identity();
|
||||
Environment::inverseShipMatrix = Eigen::Matrix3f::Identity();
|
||||
Environment::zoom = DEFAULT_ZOOM;
|
||||
Environment::tapDownHold = false;
|
||||
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) {
|
||||
@ -811,10 +929,42 @@ namespace ZL
|
||||
explosionEmitter.setUseWorldSpace(true);
|
||||
explosionEmitter.setEmissionPoints(std::vector<Vector3f>{ boxWorld });
|
||||
explosionEmitter.emit();
|
||||
lastExplosionTime = SDL_GetTicks64();
|
||||
|
||||
std::cerr << "Box destroyed at index " << i << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
const float projectileHitRadius = 1.5f;
|
||||
for (auto& p : projectiles) {
|
||||
if (!p || !p->isActive()) continue;
|
||||
Vector3f ppos = p->getPosition();
|
||||
Vector3f projInBoxSpace = Environment::inverseShipMatrix * (ppos - Environment::shipState.position);
|
||||
for (int i = 0; i < boxCoordsArr.size(); ++i) {
|
||||
if (!boxAlive[i]) continue;
|
||||
Vector3f boxWorld = boxCoordsArr[i].pos + Vector3f{ 0.0f, 6.0f, 45000.0f };
|
||||
Vector3f dd = ppos - boxWorld;
|
||||
float thresh = boxCollisionRadius + projectileHitRadius;
|
||||
if (dd.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;
|
||||
explosionEmitter.setUseWorldSpace(true);
|
||||
explosionEmitter.setEmissionPoints(std::vector<Vector3f>{ boxWorld });
|
||||
explosionEmitter.emit();
|
||||
lastExplosionTime = SDL_GetTicks64();
|
||||
|
||||
p->deactivate();
|
||||
std::cerr << "Box destroyed by projectile at index " << i << std::endl;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
uiManager.update(static_cast<float>(delta));
|
||||
lastTickCount = newTickCount;
|
||||
}
|
||||
|
||||
@ -93,14 +93,16 @@ namespace ZL {
|
||||
int maxProjectiles = 32;
|
||||
std::vector<Vector3f> shipLocalEmissionPoints;
|
||||
|
||||
|
||||
|
||||
bool shipAlive = true;
|
||||
bool gameOver = false;
|
||||
std::vector<bool> boxAlive;
|
||||
float shipCollisionRadius = 3.5f;
|
||||
float shipCollisionRadius = 15.0f;
|
||||
float boxCollisionRadius = 2.0f;
|
||||
bool uiGameOverShown = false;
|
||||
bool showExplosion = false;
|
||||
uint64_t lastExplosionTime = 0;
|
||||
const uint64_t explosionDurationMs = 500;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@ -18,7 +18,7 @@ namespace ZL {
|
||||
bool isActive() const { return active; }
|
||||
|
||||
Vector3f getPosition() const { return pos; }
|
||||
|
||||
void deactivate() { active = false; }
|
||||
private:
|
||||
Vector3f pos;
|
||||
Vector3f vel;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user