Change the way fire happens
This commit is contained in:
parent
210c191d41
commit
2ffd8124f2
67
src/Game.cpp
67
src/Game.cpp
@ -364,38 +364,7 @@ namespace ZL
|
|||||||
});
|
});
|
||||||
|
|
||||||
uiManager.setButtonCallback("shootButton", [this](const std::string& name) {
|
uiManager.setButtonCallback("shootButton", [this](const std::string& name) {
|
||||||
uint64_t now = SDL_GetTicks64();
|
firePressed = true;
|
||||||
if (now - lastProjectileFireTime >= static_cast<uint64_t>(projectileCooldownMs)) {
|
|
||||||
lastProjectileFireTime = now;
|
|
||||||
const float projectileSpeed = 60.0f;
|
|
||||||
|
|
||||||
this->fireProjectiles();
|
|
||||||
|
|
||||||
Eigen::Vector3f localForward = { 0, 0, -1 };
|
|
||||||
Eigen::Vector3f worldForward = (Environment::shipState.rotation * localForward).normalized();
|
|
||||||
|
|
||||||
Eigen::Vector3f centerPos = Environment::shipState.position +
|
|
||||||
Environment::shipState.rotation * Vector3f{ 0, 0.9f, 5.0f };
|
|
||||||
|
|
||||||
Eigen::Quaternionf q(Environment::shipState.rotation);
|
|
||||||
float speedToSend = projectileSpeed + Environment::shipState.velocity;
|
|
||||||
int shotCount = 2;
|
|
||||||
|
|
||||||
std::string fireMsg = "FIRE:" +
|
|
||||||
std::to_string(now) + ":" +
|
|
||||||
std::to_string(centerPos.x()) + ":" +
|
|
||||||
std::to_string(centerPos.y()) + ":" +
|
|
||||||
std::to_string(centerPos.z()) + ":" +
|
|
||||||
std::to_string(q.w()) + ":" +
|
|
||||||
std::to_string(q.x()) + ":" +
|
|
||||||
std::to_string(q.y()) + ":" +
|
|
||||||
std::to_string(q.z()) + ":" +
|
|
||||||
std::to_string(speedToSend) + ":" +
|
|
||||||
std::to_string(shotCount);
|
|
||||||
|
|
||||||
//Temporary disable to avoid de-sync
|
|
||||||
//networkClient->Send(fireMsg);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
uiManager.setSliderCallback("velocitySlider", [this](const std::string& name, float value) {
|
uiManager.setSliderCallback("velocitySlider", [this](const std::string& name, float value) {
|
||||||
@ -922,6 +891,40 @@ namespace ZL
|
|||||||
sparkEmitter.update(static_cast<float>(delta));
|
sparkEmitter.update(static_cast<float>(delta));
|
||||||
planetObject.update(static_cast<float>(delta));
|
planetObject.update(static_cast<float>(delta));
|
||||||
|
|
||||||
|
if (firePressed)
|
||||||
|
{
|
||||||
|
firePressed = false;
|
||||||
|
if (now_ms - lastProjectileFireTime >= static_cast<uint64_t>(projectileCooldownMs)) {
|
||||||
|
lastProjectileFireTime = now_ms;
|
||||||
|
const float projectileSpeed = 250.0f;
|
||||||
|
|
||||||
|
this->fireProjectiles();
|
||||||
|
|
||||||
|
Eigen::Vector3f localForward = { 0, 0, -1 };
|
||||||
|
Eigen::Vector3f worldForward = (Environment::shipState.rotation * localForward).normalized();
|
||||||
|
|
||||||
|
Eigen::Vector3f centerPos = Environment::shipState.position +
|
||||||
|
Environment::shipState.rotation * Vector3f{ 0, 0.9f, 5.0f };
|
||||||
|
|
||||||
|
Eigen::Quaternionf q(Environment::shipState.rotation);
|
||||||
|
float speedToSend = projectileSpeed + Environment::shipState.velocity;
|
||||||
|
int shotCount = 2;
|
||||||
|
|
||||||
|
std::string fireMsg = "FIRE:" +
|
||||||
|
std::to_string(now_ms) + ":" +
|
||||||
|
std::to_string(centerPos.x()) + ":" +
|
||||||
|
std::to_string(centerPos.y()) + ":" +
|
||||||
|
std::to_string(centerPos.z()) + ":" +
|
||||||
|
std::to_string(q.w()) + ":" +
|
||||||
|
std::to_string(q.x()) + ":" +
|
||||||
|
std::to_string(q.y()) + ":" +
|
||||||
|
std::to_string(q.z()) + ":" +
|
||||||
|
std::to_string(speedToSend) + ":" +
|
||||||
|
std::to_string(shotCount);
|
||||||
|
|
||||||
|
networkClient->Send(fireMsg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//Handle input:
|
//Handle input:
|
||||||
|
|||||||
@ -105,7 +105,7 @@ namespace ZL {
|
|||||||
std::vector<std::unique_ptr<Projectile>> projectiles;
|
std::vector<std::unique_ptr<Projectile>> projectiles;
|
||||||
std::shared_ptr<Texture> projectileTexture;
|
std::shared_ptr<Texture> projectileTexture;
|
||||||
float projectileCooldownMs = 500.0f;
|
float projectileCooldownMs = 500.0f;
|
||||||
uint64_t lastProjectileFireTime = 0;
|
int64_t lastProjectileFireTime = 0;
|
||||||
int maxProjectiles = 32;
|
int maxProjectiles = 32;
|
||||||
std::vector<Vector3f> shipLocalEmissionPoints;
|
std::vector<Vector3f> shipLocalEmissionPoints;
|
||||||
|
|
||||||
@ -119,6 +119,7 @@ namespace ZL {
|
|||||||
bool showExplosion = false;
|
bool showExplosion = false;
|
||||||
uint64_t lastExplosionTime = 0;
|
uint64_t lastExplosionTime = 0;
|
||||||
const uint64_t explosionDurationMs = 500;
|
const uint64_t explosionDurationMs = 500;
|
||||||
|
bool firePressed = false;
|
||||||
|
|
||||||
|
|
||||||
bool serverBoxesApplied = false;
|
bool serverBoxesApplied = false;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user