added locations
This commit is contained in:
1 parent
fe01a5d1b2
commit
1bf54b5367
7 files changed
+865
-4
No files matched your search
@@ -495,6 +495,15 @@ namespace ZL
|
||||
case SDLK_3:
|
||||
if (audioPlayer) audioPlayer->stopMusicAsync();
|
||||
break;
|
||||
case SDLK_c:
|
||||
{
|
||||
std::cout << "[GAME] Location change triggered by key press" << std::endl;
|
||||
static size_t locIndex = 0;
|
||||
static std::vector<std::string> locations = { "default", "forest" };
|
||||
locIndex = (locIndex + 1) % locations.size();
|
||||
changeLocation(locations[locIndex]);
|
||||
break;
|
||||
}
|
||||
case SDLK_f:
|
||||
currentLocation->dialogueSystem.startDialogue("test_choice_dialogue");
|
||||
break;
|
||||
@@ -581,4 +590,17 @@ namespace ZL
|
||||
|
||||
}
|
||||
|
||||
void Game::changeLocation(const std::string& newLocationId)
|
||||
{
|
||||
if (!currentLocation) {
|
||||
std::cout << "[GAME] No current location" << std::endl;
|
||||
return;
|
||||
}
|
||||
std::cout << "[GAME] Changing location to: " << newLocationId << std::endl;
|
||||
currentLocation->unload();
|
||||
currentLocation = std::make_shared<Location>(renderer, inventory, newLocationId);
|
||||
currentLocation->setup();
|
||||
std::cout << "[GAME] Location changed" << std::endl;
|
||||
}
|
||||
|
||||
} // namespace ZL
|
||||
@@ -53,6 +53,8 @@ namespace ZL {
|
||||
|
||||
MenuManager menuManager;
|
||||
|
||||
void changeLocation(const std::string& locId);
|
||||
|
||||
private:
|
||||
bool rightMouseDown = false;
|
||||
int lastMouseX = 0;
|
||||
|
||||
+127
-3
@@ -20,14 +20,15 @@ namespace ZL
|
||||
|
||||
static constexpr float CAMERA_FOV_Y = 1.0f / 1.5f;
|
||||
|
||||
Location::Location(Renderer& iRenderer, Inventory& iInventory)
|
||||
Location::Location(Renderer& iRenderer, Inventory& iInventory, const std::string& locId)
|
||||
: renderer(iRenderer)
|
||||
, inventory(iInventory)
|
||||
, locationId(locId)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void Location::setup()
|
||||
/*void Location::setup()
|
||||
{
|
||||
roomTexture = std::make_unique<Texture>(CreateTextureDataFromPng("resources/w/room005.png", CONST_ZIP_FILE));
|
||||
roomMesh.data = LoadFromTextFile02("resources/w/room001.txt", CONST_ZIP_FILE);
|
||||
@@ -110,9 +111,96 @@ namespace ZL
|
||||
2.0f,
|
||||
true,
|
||||
false
|
||||
});*/
|
||||
});
|
||||
|
||||
|
||||
}*/
|
||||
|
||||
void Location::setup()
|
||||
{
|
||||
std::string roomTexPath;
|
||||
std::string roomMeshPath;
|
||||
std::string gameObjectsPath;
|
||||
std::string interactiveObjectsPath;
|
||||
std::string npcsPath;
|
||||
|
||||
if (locationId == "forest")
|
||||
{
|
||||
std::cout << "[LOCATION] Setting up FOREST location (using placeholder resources)" << std::endl;
|
||||
roomTexPath = "resources/w/room005.png";
|
||||
roomMeshPath = "resources/w/room001.txt";
|
||||
gameObjectsPath = "resources/config2/gameobjects2.json";
|
||||
interactiveObjectsPath = "resources/config2/gameobjects2.json";
|
||||
npcsPath = "resources/config2/npcs2.json";
|
||||
}
|
||||
else // default
|
||||
{
|
||||
std::cout << "[LOCATION] Setting up DEFAULT location" << std::endl;
|
||||
roomTexPath = "resources/w/room005.png";
|
||||
roomMeshPath = "resources/w/room001.txt";
|
||||
gameObjectsPath = "resources/config2/gameobjects.json";
|
||||
interactiveObjectsPath = "resources/config2/gameobjects.json";
|
||||
npcsPath = "resources/config2/npcs.json";
|
||||
}
|
||||
|
||||
roomTexture = std::make_unique<Texture>(CreateTextureDataFromPng(roomTexPath.c_str(), CONST_ZIP_FILE));
|
||||
roomMesh.data = LoadFromTextFile02(roomMeshPath.c_str(), CONST_ZIP_FILE);
|
||||
roomMesh.data.RotateByMatrix(Eigen::Quaternionf(Eigen::AngleAxisf(-M_PI * 0.5, Eigen::Vector3f::UnitY())).toRotationMatrix());
|
||||
roomMesh.RefreshVBO();
|
||||
|
||||
gameObjects = GameObjectLoader::loadAndCreateGameObjects(gameObjectsPath, renderer, CONST_ZIP_FILE);
|
||||
|
||||
interactiveObjects = GameObjectLoader::loadAndCreateInteractiveObjects(interactiveObjectsPath, renderer, CONST_ZIP_FILE);
|
||||
|
||||
auto playerTexture = std::make_shared<Texture>(CreateTextureDataFromPng("resources/w/gg/IMG_20260413_182354_992.png", CONST_ZIP_FILE));
|
||||
player = std::make_unique<Character>();
|
||||
player->loadBinaryAnimation(AnimationState::STAND, "resources/w/gg/gg_stand_idle001.anim", CONST_ZIP_FILE);
|
||||
player->loadBinaryAnimation(AnimationState::WALK, "resources/w/gg/gg_walking001.anim", CONST_ZIP_FILE);
|
||||
player->loadBinaryAnimation(AnimationState::STAND_TO_ACTION, "resources/w/gg/gg_stand_to_action002.anim", CONST_ZIP_FILE);
|
||||
player->loadBinaryAnimation(AnimationState::ACTION_ATTACK, "resources/w/gg/gg_action_attack001.anim", CONST_ZIP_FILE);
|
||||
player->loadBinaryAnimation(AnimationState::ACTION_IDLE, "resources/w/gg/gg_action_idle001.anim", CONST_ZIP_FILE);
|
||||
player->loadBinaryAnimation(AnimationState::ACTION_TO_STAND, "resources/w/gg/gg_action_to_stand001.anim", CONST_ZIP_FILE);
|
||||
player->setTexture(playerTexture);
|
||||
player->walkSpeed = 3.0f;
|
||||
player->rotationSpeed = 8.0f;
|
||||
player->modelScale = 1.f;
|
||||
player->modelCorrectionRotation = Eigen::Quaternionf(Eigen::AngleAxisf(M_PI, Eigen::Vector3f::UnitY()));
|
||||
player->canAttack = true;
|
||||
player->isPlayer = true;
|
||||
std::cout << "Load resources step 9" << std::endl;
|
||||
|
||||
npcs = GameObjectLoader::loadAndCreateNpcs(npcsPath, CONST_ZIP_FILE);
|
||||
|
||||
auto ghostTexture = std::make_shared<Texture>(CreateTextureDataFromPng("resources/w/ghost_skin001.png", CONST_ZIP_FILE));
|
||||
std::cout << "Load resources step 11" << std::endl;
|
||||
auto npc02 = std::make_unique<Character>();
|
||||
npc02->loadBinaryAnimation(AnimationState::STAND, "resources/w/default_float001.anim", CONST_ZIP_FILE);
|
||||
npc02->loadBinaryAnimation(AnimationState::WALK, "resources/w/default_float001.anim", CONST_ZIP_FILE);
|
||||
npc02->loadBinaryAnimation(AnimationState::ACTION_IDLE, "resources/w/float_attack003_cut.anim", CONST_ZIP_FILE);
|
||||
npc02->loadBinaryAnimation(AnimationState::ACTION_ATTACK, "resources/w/float_attack003.anim", CONST_ZIP_FILE);
|
||||
npc02->loadBinaryAnimation(AnimationState::STAND_TO_ACTION, "resources/w/default_float001_cut.anim", CONST_ZIP_FILE);
|
||||
npc02->loadBinaryAnimation(AnimationState::ACTION_TO_STAND, "resources/w/default_float001_cut.anim", CONST_ZIP_FILE);
|
||||
npc02->setTexture(ghostTexture);
|
||||
npc02->walkSpeed = 1.5f;
|
||||
npc02->rotationSpeed = 8.0f;
|
||||
npc02->modelScale = 0.01f;
|
||||
npc02->modelCorrectionRotation = Eigen::Quaternionf(Eigen::AngleAxisf(M_PI, Eigen::Vector3f::UnitY()));
|
||||
npc02->position = Eigen::Vector3f(0.f, 0.f, -20.f);
|
||||
npc02->setTarget(npc02->position);
|
||||
npc02->canAttack = true;
|
||||
npc02->attackTarget = player.get();
|
||||
npcs.push_back(std::move(npc02));
|
||||
|
||||
shadowMap = std::make_unique<ShadowMap>(2048, 40.0f, 0.1f, 100.0f);
|
||||
shadowMap->setLightDirection(Eigen::Vector3f(-0.5f, -1.0f, -0.3f));
|
||||
std::cout << "Shadow map initialized" << std::endl;
|
||||
|
||||
setupNavigation();
|
||||
|
||||
scriptEngine.init(this, &inventory);
|
||||
|
||||
dialogueSystem.init(renderer, CONST_ZIP_FILE);
|
||||
dialogueSystem.loadDatabase("resources/dialogue/sample_dialogues.json");
|
||||
}
|
||||
|
||||
void Location::setupNavigation()
|
||||
@@ -666,5 +754,41 @@ namespace ZL
|
||||
return dialogueSystem.getFlag(flag);
|
||||
}
|
||||
|
||||
void Location::cleanup()
|
||||
{
|
||||
std::cout << "[LOCATION] Starting cleanup..." << std::endl;
|
||||
|
||||
npcs.clear();
|
||||
|
||||
interactiveObjects.clear();
|
||||
|
||||
gameObjects.clear();
|
||||
|
||||
player.reset();
|
||||
|
||||
roomTexture.reset();
|
||||
|
||||
//dialogueSystem.dialogueDatabase.clear();
|
||||
|
||||
navigation = PathFinder();
|
||||
|
||||
cameraAzimuth = 0.0f;
|
||||
cameraInclination = M_PI * 30.f / 180.f;
|
||||
|
||||
targetInteractiveObject = nullptr;
|
||||
rightMouseDown = false;
|
||||
lastMouseX = 0;
|
||||
lastMouseY = 0;
|
||||
|
||||
std::cout << "[LOCATION] Cleanup complete" << std::endl;
|
||||
}
|
||||
|
||||
void Location::unload()
|
||||
{
|
||||
std::cout << "[LOCATION] Starting unload..." << std::endl;
|
||||
cleanup();
|
||||
std::cout << "[LOCATION] Unload complete" << std::endl;
|
||||
}
|
||||
|
||||
|
||||
} // namespace ZL
|
||||
+7
-1
@@ -16,7 +16,7 @@ namespace ZL
|
||||
class Location
|
||||
{
|
||||
public:
|
||||
Location(Renderer& iRenderer, Inventory& iInventory);
|
||||
Location(Renderer& iRenderer, Inventory& iInventory, const std::string& locId = "default");
|
||||
|
||||
|
||||
std::shared_ptr<Texture> roomTexture;
|
||||
@@ -73,9 +73,15 @@ namespace ZL
|
||||
void setDialogueFlag(const std::string& flag, int value);
|
||||
int getDialogueFlag(const std::string& flag) const;
|
||||
|
||||
void cleanup();
|
||||
void unload();
|
||||
|
||||
protected:
|
||||
Renderer& renderer;
|
||||
Inventory& inventory;
|
||||
|
||||
private:
|
||||
std::string locationId;
|
||||
};
|
||||
|
||||
} // namespace ZL
|
||||
Reference in new issue
Block a user