Working on teleports
This commit is contained in:
1 parent
7e94009217
commit
8214342248
15 files changed
+298
-131
No files matched your search
+34
-46
@@ -165,27 +165,25 @@ namespace ZL
|
||||
params1.npcsJsonPath = "resources/config2/npcs.json";
|
||||
params1.dialoguesJsonPath = "resources/dialogue/sample_dialogues.json";
|
||||
params1.navigationJsonPath = "resources/config2/navigation.json";
|
||||
params1.teleportsJsonPath = "resources/config2/teleports.json";
|
||||
params1.scriptPath = "resources/start.lua";
|
||||
params1.playerPosition = Eigen::Vector3f(0.942694, 0, -9.63104);
|
||||
params1.teleportPosition = Eigen::Vector3f(2.64621, 0, -9.37259);
|
||||
params1.teleportRadius = 1.5f;
|
||||
|
||||
location1 = std::make_shared<Location>(renderer, inventory);
|
||||
location1->setup(params1);
|
||||
locations["location1"] = std::make_shared<Location>(renderer, inventory);
|
||||
locations["location1"]->setup(params1);
|
||||
|
||||
LocationSetup params2 = params1;
|
||||
params2.roomMeshPath = "resources/w/exterior/Segmented_Plane002.txt";
|
||||
params2.roomTexturePath = "resources/w/exterior/Segmented_Plane002.png";
|
||||
params2.gameObjectsJsonPath = "resources/config2/gameobjects2.json";
|
||||
params2.navigationJsonPath = "resources/config2/navigation2.json";
|
||||
params2.teleportsJsonPath = "resources/config2/teleports2.json";
|
||||
params2.scriptPath = "resources/start2.lua";
|
||||
params2.playerPosition = Eigen::Vector3f(5, 0, -18.4);
|
||||
|
||||
params2.npcsJsonPath = "resources/config2/npcs2.json";
|
||||
params2.teleportPosition = Eigen::Vector3f(8.2, 0, -9.9);
|
||||
params2.teleportRadius = 1.5f;
|
||||
location2 = std::make_shared<Location>(renderer, inventory);
|
||||
location2->setup(params2);
|
||||
|
||||
locations["location2"] = std::make_shared<Location>(renderer, inventory);
|
||||
locations["location2"]->setup(params2);
|
||||
|
||||
LocationSetup params_dorm;
|
||||
params_dorm.roomMeshPath = "";
|
||||
@@ -194,48 +192,38 @@ namespace ZL
|
||||
params_dorm.npcsJsonPath = "resources/config2/npcs_dorm.json";
|
||||
params_dorm.dialoguesJsonPath = "resources/dialogue/sample_dialogues.json";
|
||||
params_dorm.navigationJsonPath = "resources/config2/navigation_dorm.json";
|
||||
params_dorm.teleportsJsonPath = "resources/config2/teleports_dorm.json";
|
||||
params_dorm.scriptPath = "resources/start_dorm.lua";
|
||||
params_dorm.playerPosition = Eigen::Vector3f(6.0357, 0, -16.0581);
|
||||
params_dorm.teleportPosition = Eigen::Vector3f(-8.32343, 0, -0.152264);
|
||||
params_dorm.teleportRadius = 1.5f;
|
||||
|
||||
location_dorm = std::make_shared<Location>(renderer, inventory);
|
||||
location_dorm->setup(params_dorm);
|
||||
locations["location_dorm"] = std::make_shared<Location>(renderer, inventory);
|
||||
locations["location_dorm"]->setup(params_dorm);
|
||||
|
||||
// Teleport callbacks: stepping into a location's zone hands the player
|
||||
// to the other location at *its* teleport position. We pre-arm the
|
||||
// destination's playerInTeleportZone so the player must walk out and
|
||||
// back in before they can teleport again.
|
||||
location1->onTeleport = [this]() {
|
||||
std::cout << "[TELEPORT] location 1 -> location 2" << std::endl;
|
||||
currentLocation = location2;
|
||||
if (currentLocation->player) {
|
||||
currentLocation->player->position = currentLocation->teleportPosition;
|
||||
currentLocation->player->setTarget(currentLocation->teleportPosition);
|
||||
}
|
||||
currentLocation->playerInTeleportZone = true;
|
||||
};
|
||||
location2->onTeleport = [this]() {
|
||||
std::cout << "[TELEPORT] location 2 -> location 1" << std::endl;
|
||||
currentLocation = location1;
|
||||
if (currentLocation->player) {
|
||||
currentLocation->player->position = currentLocation->teleportPosition;
|
||||
currentLocation->player->setTarget(currentLocation->teleportPosition);
|
||||
}
|
||||
currentLocation->playerInTeleportZone = true;
|
||||
// Teleport callbacks: destination name and position come from the teleport zone data.
|
||||
auto makeTeleportCallback = [this](const std::string& sourceName) {
|
||||
return [this, sourceName](const std::string& destName, const Eigen::Vector3f& destPos, float destRotY) {
|
||||
std::cout << "[TELEPORT] " << sourceName << " -> " << destName << std::endl;
|
||||
auto it = locations.find(destName);
|
||||
if (it == locations.end()) {
|
||||
std::cerr << "[TELEPORT] Unknown destination location: " << destName << std::endl;
|
||||
return;
|
||||
}
|
||||
currentLocation = it->second;
|
||||
if (currentLocation->player) {
|
||||
currentLocation->player->position = destPos;
|
||||
currentLocation->player->setTarget(destPos);
|
||||
currentLocation->player->facingAngle = destRotY;
|
||||
currentLocation->player->targetFacingAngle = destRotY;
|
||||
}
|
||||
currentLocation->cameraAzimuth = destRotY;
|
||||
};
|
||||
};
|
||||
|
||||
location_dorm->onTeleport = [this]() {
|
||||
std::cout << "[TELEPORT] location 2 -> location 1" << std::endl;
|
||||
currentLocation = location2;
|
||||
if (currentLocation->player) {
|
||||
currentLocation->player->position = currentLocation->teleportPosition;
|
||||
currentLocation->player->setTarget(currentLocation->teleportPosition);
|
||||
}
|
||||
currentLocation->playerInTeleportZone = true;
|
||||
};
|
||||
locations["location1"]->onTeleport = makeTeleportCallback("location1");
|
||||
locations["location2"]->onTeleport = makeTeleportCallback("location2");
|
||||
locations["location_dorm"]->onTeleport = makeTeleportCallback("location_dorm");
|
||||
|
||||
currentLocation = location_dorm;
|
||||
currentLocation = locations["location_dorm"];
|
||||
|
||||
std::cout << "Load resurces step 5" << std::endl;
|
||||
|
||||
@@ -540,8 +528,8 @@ namespace ZL
|
||||
break;
|
||||
|
||||
case SDLK_p:
|
||||
currentLocation = (currentLocation == location1) ? location2 : location1;
|
||||
std::cout << "Switched to location " << ((currentLocation == location1) ? "1" : "2") << std::endl;
|
||||
currentLocation = (currentLocation == locations["location1"]) ? locations["location2"] : locations["location1"];
|
||||
std::cout << "Switched to location " << ((currentLocation == locations["location1"]) ? "1" : "2") << std::endl;
|
||||
break;
|
||||
|
||||
case SDLK_l:
|
||||
|
||||
Reference in new issue
Block a user