Added pickup boxes
This commit is contained in:
1 parent
86a9f38c3b
commit
84a5e888a0
14 files changed
+300
-7
No files matched your search
+74
-2
@@ -317,6 +317,26 @@ namespace ZL
|
||||
firePressed = true;
|
||||
};
|
||||
|
||||
menuManager.onTakeButtonPressed = [this]() {
|
||||
if (Environment::shipState.shipType != 1) return;
|
||||
if (!networkClient) return;
|
||||
|
||||
int bestIdx = -1;
|
||||
float bestDistSq = BOX_PICKUP_RADIUS * BOX_PICKUP_RADIUS;
|
||||
for (size_t i = 0; i < boxCoordsArr.size(); ++i) {
|
||||
if (i >= boxAlive.size() || !boxAlive[i]) continue;
|
||||
Vector3f boxWorld = boxCoordsArr[i].pos + Vector3f{ 0.f, 0.f, 45000.f };
|
||||
float distSq = (Environment::shipState.position - boxWorld).squaredNorm();
|
||||
if (distSq <= bestDistSq) {
|
||||
bestDistSq = distSq;
|
||||
bestIdx = static_cast<int>(i);
|
||||
}
|
||||
}
|
||||
if (bestIdx >= 0) {
|
||||
networkClient->Send("BOX_PICKUP:" + std::to_string(bestIdx));
|
||||
}
|
||||
};
|
||||
|
||||
bool cfgLoaded = sparkEmitter.loadFromJsonFile("resources/config/spark_config.json", renderer, CONST_ZIP_FILE);
|
||||
bool cfgLoaded2 = sparkEmitterCargo.loadFromJsonFile("resources/config/spark_config_cargo.json", renderer, CONST_ZIP_FILE);
|
||||
sparkEmitter.setIsActive(false);
|
||||
@@ -395,7 +415,7 @@ namespace ZL
|
||||
boxLabels.clear();
|
||||
boxLabels.reserve(boxCoordsArr.size());
|
||||
for (size_t i = 0; i < boxCoordsArr.size(); ++i) {
|
||||
boxLabels.push_back("Box " + std::to_string(i + 1));
|
||||
boxLabels.push_back("Box " + std::to_string(i));
|
||||
}
|
||||
|
||||
if (!cfgLoaded)
|
||||
@@ -658,6 +678,11 @@ namespace ZL
|
||||
for (size_t i = 0; i < n; ++i) {
|
||||
if (destroyedFlags[i]) boxAlive[i] = false; // destroyed => не рисуем
|
||||
}
|
||||
boxLabels.clear();
|
||||
boxLabels.resize(boxCoordsArr.size());
|
||||
for (size_t i = 0; i < boxCoordsArr.size(); ++i) {
|
||||
boxLabels[i] = "Box " + std::to_string(i);
|
||||
}
|
||||
serverBoxesApplied = true;
|
||||
}
|
||||
}
|
||||
@@ -1776,6 +1801,24 @@ namespace ZL
|
||||
std::string velocityStr = "Velocity: " + std::to_string(static_cast<int>(Environment::shipState.velocity));
|
||||
menuManager.uiManager.setText("velocityText", velocityStr);
|
||||
}
|
||||
|
||||
bool canPickup = false;
|
||||
if (Environment::shipState.shipType == 1) {
|
||||
for (size_t i = 0; i < boxCoordsArr.size(); ++i) {
|
||||
if (i >= boxAlive.size() || !boxAlive[i]) continue;
|
||||
Vector3f boxWorld = boxCoordsArr[i].pos + Vector3f{ 0.f, 0.f, 45000.f };
|
||||
float distSq = (Environment::shipState.position - boxWorld).squaredNorm();
|
||||
if (distSq <= BOX_PICKUP_RADIUS * BOX_PICKUP_RADIUS) {
|
||||
canPickup = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (canPickup != nearPickupBox) {
|
||||
nearPickupBox = canPickup;
|
||||
if (auto btn = menuManager.uiManager.findButton("takeButton"))
|
||||
btn->state = canPickup ? ButtonState::Normal : ButtonState::Disabled;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1890,7 +1933,7 @@ namespace ZL
|
||||
if (d.killerId == localId) {
|
||||
this->playerScore += 1;
|
||||
std::cout << "Client: Increased local score to " << this->playerScore << std::endl;
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1952,6 +1995,35 @@ namespace ZL
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
auto boxPickups = networkClient->getPendingBoxPickups();
|
||||
for (const auto& pickup : boxPickups) {
|
||||
int idx = pickup.boxIndex;
|
||||
if (idx >= 0 && idx < (int)boxCoordsArr.size() && idx < (int)boxAlive.size()) {
|
||||
if (boxAlive[idx]) {
|
||||
boxAlive[idx] = false;
|
||||
boxRenderArr[idx].data.PositionData.clear();
|
||||
boxRenderArr[idx].vao.reset();
|
||||
boxRenderArr[idx].positionVBO.reset();
|
||||
boxRenderArr[idx].texCoordVBO.reset();
|
||||
std::cout << "Client: Box " << idx << " picked up by player " << pickup.pickedUpBy << "\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
auto boxRespawns = networkClient->getPendingBoxRespawns();
|
||||
for (const auto& respawn : boxRespawns) {
|
||||
int idx = respawn.boxIndex;
|
||||
if (idx >= 0 && idx < (int)boxCoordsArr.size()) {
|
||||
boxCoordsArr[idx].pos = respawn.position;
|
||||
boxCoordsArr[idx].m = respawn.rotation;
|
||||
boxAlive[idx] = true;
|
||||
boxRenderArr[idx].AssignFrom(boxBase);
|
||||
boxRenderArr[idx].RefreshVBO();
|
||||
std::cout << "Client: Box " << idx << " respawned" << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Space::handleDown(int mx, int my)
|
||||
|
||||
Reference in new issue
Block a user