From a8c76dee3cff94d4911bb3e6bb46db59d332898a Mon Sep 17 00:00:00 2001 From: Vladislav Khorev Date: Thu, 5 Mar 2026 23:58:35 +0300 Subject: [PATCH] Working on fixing minor bugs --- proj-web/space-game001plain.html | 24 ------ resources/button_minus.png | 3 + resources/button_minus_pressed.png | 3 + resources/button_plus.png | 3 + resources/button_plus_pressed.png | 3 + resources/config/spark_config.json | 6 +- resources/config/spark_config_cargo.json | 20 +++++ resources/config/spark_projectile_config.json | 12 +-- resources/config/ui.json | 56 ++++++++++--- resources/fire.png | 4 +- resources/fire2.png | 4 +- resources/fire_disabled.png | 3 + resources/game_over/Variant5.png | 4 +- resources/game_over/Variant6.png | 4 +- resources/main_menu/Variant5.png | 4 +- resources/main_menu/Variant6.png | 4 +- resources/main_menu/Variant7.png | 4 +- resources/main_menu/Variant8.png | 4 +- resources/spark.png | 4 +- resources/spark2.png | 4 +- resources/spark3.png | 3 + src/Game.cpp | 12 +++ src/MenuManager.cpp | 16 ++++ src/Projectile.cpp | 2 +- src/Projectile.h | 2 +- src/Space.cpp | 79 +++++++++++++++---- src/Space.h | 1 + src/SparkEmitter.cpp | 64 +++++++++++---- src/SparkEmitter.h | 8 +- src/UiManager.cpp | 27 +++++-- src/UiManager.h | 9 ++- src/network/ClientState.h | 2 +- 32 files changed, 288 insertions(+), 110 deletions(-) create mode 100644 resources/button_minus.png create mode 100644 resources/button_minus_pressed.png create mode 100644 resources/button_plus.png create mode 100644 resources/button_plus_pressed.png create mode 100644 resources/config/spark_config_cargo.json create mode 100644 resources/fire_disabled.png create mode 100644 resources/spark3.png diff --git a/proj-web/space-game001plain.html b/proj-web/space-game001plain.html index 72892cd..d3c1953 100644 --- a/proj-web/space-game001plain.html +++ b/proj-web/space-game001plain.html @@ -17,23 +17,10 @@ width: 100vw; height: 100vh; border: none; } - /* Кнопка Fullscreen */ - #fs-button { - position: absolute; - top: 10px; right: 10px; - padding: 10px; - z-index: 10; - background: rgba(255,255,255,0.3); - color: white; border: 1px solid white; - cursor: pointer; - font-family: sans-serif; - border-radius: 5px; - } #status { color: white; position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); } -
Downloading...
@@ -49,17 +36,6 @@ } }; - // Кнопка Fullscreen - document.getElementById('fs-button').addEventListener('click', function() { - if (!document.fullscreenElement) { - document.documentElement.requestFullscreen().catch(e => { - console.error(`Error attempting to enable full-screen mode: ${e.message}`); - }); - } else { - document.exitFullscreen(); - } - }); - // Обработка ориентации window.addEventListener("orientationchange", function() { // Chrome на Android обновляет innerWidth/Height не мгновенно. diff --git a/resources/button_minus.png b/resources/button_minus.png new file mode 100644 index 0000000..8fd6fec --- /dev/null +++ b/resources/button_minus.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8425f4b75b63b138810c92449c93baffd39acef9f5c9ead69687c3e8b0c577c6 +size 14922 diff --git a/resources/button_minus_pressed.png b/resources/button_minus_pressed.png new file mode 100644 index 0000000..7cd9a42 --- /dev/null +++ b/resources/button_minus_pressed.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:729fc37ad29bd53b13232a0242b89142cbf29c08bfbce8834a403b265ff5a700 +size 28545 diff --git a/resources/button_plus.png b/resources/button_plus.png new file mode 100644 index 0000000..4d48ebc --- /dev/null +++ b/resources/button_plus.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5551fbec116add9541e797b53928e36c8fe8835ad2e2e118241b4148a2ccb4c1 +size 15058 diff --git a/resources/button_plus_pressed.png b/resources/button_plus_pressed.png new file mode 100644 index 0000000..b5e51ce --- /dev/null +++ b/resources/button_plus_pressed.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ad20d915c39c968d29d94a3e30099e40ea5a7da8f82d4775a0976fdfacadf93e +size 27821 diff --git a/resources/config/spark_config.json b/resources/config/spark_config.json index cbe6c47..d7ec09e 100644 --- a/resources/config/spark_config.json +++ b/resources/config/spark_config.json @@ -1,14 +1,14 @@ { - "emissionRate": 100.0, + "emissionRate": 10.0, "maxParticles": 200, "particleSize": 0.3, "biasX": 0.3, "emissionPoints": [ { - "position": [-1.3, 0, 0.0] + "position": [-1.0, 1.4, -3.5] }, { - "position": [1.3, 0.0, 0.0] + "position": [1.0, 1.4, -3.5] } ], "speedRange": [0.5, 2.0], diff --git a/resources/config/spark_config_cargo.json b/resources/config/spark_config_cargo.json new file mode 100644 index 0000000..1fbe1a0 --- /dev/null +++ b/resources/config/spark_config_cargo.json @@ -0,0 +1,20 @@ +{ + "emissionRate": 10.0, + "maxParticles": 200, + "particleSize": 0.3, + "biasX": 0.3, + "emissionPoints": [ + { + "position": [0.0, 2.8, -3.5] + }, + { + "position": [0.0, 1.5, -3.5] + } + ], + "speedRange": [0.5, 2.0], + "zSpeedRange": [1.0, 3.0], + "scaleRange": [0.8, 1.2], + "lifeTimeRange": [600.0, 1400.0], + "texture": "resources/spark.png", + "shaderProgramName": "spark" +} \ No newline at end of file diff --git a/resources/config/spark_projectile_config.json b/resources/config/spark_projectile_config.json index 7fbe467..9e303e9 100644 --- a/resources/config/spark_projectile_config.json +++ b/resources/config/spark_projectile_config.json @@ -2,14 +2,14 @@ "emissionPoints": [ { "position": [0.0, 0.0, 0.0] } ], - "texture": "resources/spark_white.png", - "speedRange": [10.0, 30.0], + "texture": "resources/spark2.png", + "speedRange": [5.0, 10.0], "zSpeedRange": [-1.0, 1.0], - "scaleRange": [0.5, 1.0], + "scaleRange": [0.5, 2.0], "lifeTimeRange": [200.0, 800.0], - "emissionRate": 50.0, - "maxParticles": 10, - "particleSize": 0.5, + "emissionRate": 30.0, + "maxParticles": 150, + "particleSize": 1.0, "biasX": 0.1, "shaderProgramName": "default" } \ No newline at end of file diff --git a/resources/config/ui.json b/resources/config/ui.json index 100b161..06e895a 100644 --- a/resources/config/ui.json +++ b/resources/config/ui.json @@ -6,6 +6,20 @@ "width": "match_parent", "height": "match_parent", "children": [ + { + "type": "TextView", + "name": "velocityText", + "x": 10, + "y": 10, + "width": 200, + "height": 40, + "horizontal_gravity": "left", + "vertical_gravity": "top", + "text": "Velocity: 0", + "fontSize": 24, + "color": [1.0, 1.0, 1.0, 1.0], + "centered": false + }, { "type": "Button", "name": "shootButton", @@ -18,7 +32,8 @@ "textures": { "normal": "resources/fire.png", "hover": "resources/fire2.png", - "pressed": "resources/fire.png" + "pressed": "resources/fire2.png", + "disabled": "resources/fire_disabled.png" } }, { @@ -33,23 +48,40 @@ "textures": { "normal": "resources/fire.png", "hover": "resources/fire2.png", - "pressed": "resources/fire.png" + "pressed": "resources/fire2.png", + "disabled": "resources/fire_disabled.png" } }, { - "type": "Slider", - "name": "velocitySlider", - "x": 10, - "y": 200, - "width": 80, - "height": 300, - "value": 0.0, - "orientation": "vertical", + "type": "Button", + "name": "minusButton", + "x": -20, + "y": 110, + "width": 150, + "height": 150, + "border" : 20, "horizontal_gravity": "right", "vertical_gravity": "bottom", "textures": { - "track": "resources/velocitySliderTexture.png", - "knob": "resources/velocitySliderButton.png" + "normal": "resources/button_minus.png", + "hover": "resources/button_minus_pressed.png", + "pressed": "resources/button_minus_pressed.png" + } + }, + { + "type": "Button", + "name": "plusButton", + "x": -20, + "y": 220, + "width": 150, + "height": 150, + "border" : 20, + "horizontal_gravity": "right", + "vertical_gravity": "bottom", + "textures": { + "normal": "resources/button_plus.png", + "hover": "resources/button_plus_pressed.png", + "pressed": "resources/button_plus_pressed.png" } } ] diff --git a/resources/fire.png b/resources/fire.png index 4ca886d..07e9346 100644 --- a/resources/fire.png +++ b/resources/fire.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:9eec617d529a9631ceea24c40ffd8665f15f987920bba501ba5234379c56ed2c -size 71713 +oid sha256:5efff9f73d98fa230bfa247b3302c530275aba103638d5a220aa09f94bc629df +size 100748 diff --git a/resources/fire2.png b/resources/fire2.png index 1760044..cc9b372 100644 --- a/resources/fire2.png +++ b/resources/fire2.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:6201f627673caf52c13fdaf2303374cb704d1ed8e700d5f6d65cb04a743f3201 -size 91233 +oid sha256:1a329b0c8847a33061e769891cb04d82544d573fcd836514eb98021340e975a1 +size 116746 diff --git a/resources/fire_disabled.png b/resources/fire_disabled.png new file mode 100644 index 0000000..008d469 --- /dev/null +++ b/resources/fire_disabled.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b78ea265d945ccdea12a319ee288f9e99cc472c745300ee1a5f3393726082710 +size 111366 diff --git a/resources/game_over/Variant5.png b/resources/game_over/Variant5.png index 705ffcb..08c15b5 100644 --- a/resources/game_over/Variant5.png +++ b/resources/game_over/Variant5.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:76b4ab0bcfedfad0110e907430d31db71fbc61680e767c4e3263ead2afe478ba -size 5729 +oid sha256:44b90a4684f39ad8498194a8e130a02a4b5bb241364c8db05a069a05349eb547 +size 10072 diff --git a/resources/game_over/Variant6.png b/resources/game_over/Variant6.png index d18f3bc..58beb4f 100644 --- a/resources/game_over/Variant6.png +++ b/resources/game_over/Variant6.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:119e152699afe2d610ad0f73dafde75269bd8ea0d6973f2e10db20f3c592c213 -size 5653 +oid sha256:c2d3e1fb2e45fe0a5641784a65606114a8a0343a3e45a11141f331a38e1bdd88 +size 9597 diff --git a/resources/main_menu/Variant5.png b/resources/main_menu/Variant5.png index f52915a..54c357d 100644 --- a/resources/main_menu/Variant5.png +++ b/resources/main_menu/Variant5.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:1f07e77372d0a131772303b7cb0c89d34570cbc4d1822378f3565e724594636b -size 4866 +oid sha256:a2ef90493bbdbaf7779bb091d49c90613e79c25c4d3b553927d69312b944e0cc +size 8311 diff --git a/resources/main_menu/Variant6.png b/resources/main_menu/Variant6.png index c5fc531..8978164 100644 --- a/resources/main_menu/Variant6.png +++ b/resources/main_menu/Variant6.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:15efda31a108efcb4cbf3d7d5e4d4f99c96f2464390f3a9b01c5aa310580938b -size 4427 +oid sha256:69b42cd78a376d55a0f17dfa83906cd09c264d04832e8f1991f773bb7756b22f +size 7445 diff --git a/resources/main_menu/Variant7.png b/resources/main_menu/Variant7.png index fd6bcf3..2bc3793 100644 --- a/resources/main_menu/Variant7.png +++ b/resources/main_menu/Variant7.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:59d1bec35c88c068e4874824b3fcb60b50f38565f6fa5d3df5660c2b718ec1ca -size 3536 +oid sha256:780846ab6b6487b01054e6a624352fe7fbe1db67c0dfd4c29994ffc45b978239 +size 6593 diff --git a/resources/main_menu/Variant8.png b/resources/main_menu/Variant8.png index d72ae82..17e4e40 100644 --- a/resources/main_menu/Variant8.png +++ b/resources/main_menu/Variant8.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:02e7369f9ba5bf7f152ea3f62353da7b3c2d75e52f93bd99f5f03e8f2bb76821 -size 3451 +oid sha256:636a46a4b822d4aad03481c58929bca46c8513ad1e502a48446fd682888699b5 +size 6266 diff --git a/resources/spark.png b/resources/spark.png index 4ed63fd..9f78b0d 100644 --- a/resources/spark.png +++ b/resources/spark.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:8885a2b593c5dc0e8ac5cf5204bf3d82eb45ad6dae9b56e2bc88a41e61144c89 -size 2222 +oid sha256:fe73ae8d4ac8d878a65a3d84b16075582223bb028d1a431b5c6af257811850c4 +size 2742 diff --git a/resources/spark2.png b/resources/spark2.png index b0e806f..dcc9896 100644 --- a/resources/spark2.png +++ b/resources/spark2.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:11cde0c85c95f91eb9ace65cead22a37ba80d215897f32a2d6be1410210c1acf -size 2656 +oid sha256:7a22261dfa7a9f14f79bcac6af502c7092bdebc1d30f3cbd2df4c8e3ba4ac99e +size 2700 diff --git a/resources/spark3.png b/resources/spark3.png new file mode 100644 index 0000000..32049bc --- /dev/null +++ b/resources/spark3.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2017634739f985c00a681d1623c7fe37dbeaa52dbc4665b5593e59a9d7e2e753 +size 2656 diff --git a/src/Game.cpp b/src/Game.cpp index 6893d5c..4aa8d80 100644 --- a/src/Game.cpp +++ b/src/Game.cpp @@ -150,6 +150,18 @@ namespace ZL Environment::shipState.nickname = nickname; Environment::shipState.shipType = shipType; + + if (Environment::shipState.shipType == 1) + { + menuManager.uiManager.findButton("shootButton")->state = ButtonState::Disabled; + menuManager.uiManager.findButton("shootButton2")->state = ButtonState::Disabled; + } + else + { + menuManager.uiManager.findButton("shootButton")->state = ButtonState::Normal; + menuManager.uiManager.findButton("shootButton2")->state = ButtonState::Normal; + } + auto localClient = new LocalClient; ClientState st = Environment::shipState; st.id = localClient->GetClientId(); diff --git a/src/MenuManager.cpp b/src/MenuManager.cpp index c5b072d..80643fe 100644 --- a/src/MenuManager.cpp +++ b/src/MenuManager.cpp @@ -103,6 +103,22 @@ namespace ZL { uiManager.setButtonCallback("shootButton2", [this](const std::string& name) { onFirePressed(); }); + uiManager.setButtonCallback("plusButton", [this](const std::string& name) { + int newVel = Environment::shipState.selectedVelocity+1; + if (newVel > 4) + { + newVel = 4; + } + onVelocityChanged(newVel); + }); + uiManager.setButtonCallback("minusButton", [this](const std::string& name) { + int newVel = Environment::shipState.selectedVelocity-1; + if (newVel < 0) + { + newVel = 0; + } + onVelocityChanged(newVel); + }); uiManager.setSliderCallback("velocitySlider", [this](const std::string& name, float value) { int newVel = roundf(value * 10); diff --git a/src/Projectile.cpp b/src/Projectile.cpp index 9f98d4f..ee2eaba 100644 --- a/src/Projectile.cpp +++ b/src/Projectile.cpp @@ -1,4 +1,4 @@ -#include "Projectile.h" +#include "Projectile.h" namespace ZL { diff --git a/src/Projectile.h b/src/Projectile.h index e72552e..2f3b4cc 100644 --- a/src/Projectile.h +++ b/src/Projectile.h @@ -1,4 +1,4 @@ -#pragma once +#pragma once #include "render/Renderer.h" #include "render/TextureManager.h" diff --git a/src/Space.cpp b/src/Space.cpp index 54c945d..9b22995 100644 --- a/src/Space.cpp +++ b/src/Space.cpp @@ -282,6 +282,20 @@ namespace ZL menuManager.onVelocityChanged = [this](float newVelocity) { newShipVelocity = newVelocity; + if (Environment::shipState.shipType == 0) + { + if (newVelocity > 2) + { + this->menuManager.uiManager.findButton("shootButton")->state = ButtonState::Disabled; + this->menuManager.uiManager.findButton("shootButton2")->state = ButtonState::Disabled; + + } + else + { + this->menuManager.uiManager.findButton("shootButton")->state = ButtonState::Normal; + this->menuManager.uiManager.findButton("shootButton2")->state = ButtonState::Normal; + } + } }; menuManager.onFirePressed = [this]() { @@ -289,10 +303,13 @@ namespace ZL }; 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); bool projCfgLoaded = projectileEmitter.loadFromJsonFile("resources/config/spark_projectile_config.json", renderer, CONST_ZIP_FILE); bool explosionCfgLoaded = explosionEmitter.loadFromJsonFile("resources/config/explosion_config.json", renderer, CONST_ZIP_FILE); explosionEmitter.setEmissionPoints(std::vector()); - projectileEmitter.setEmissionPoints(std::vector()); + //projectileEmitter.setEmissionPoints({ Vector3f{0,0,45000} }); + //projectileEmitter.setUseWorldSpace(true); + cubemapTexture = std::make_shared( std::array{ @@ -315,7 +332,9 @@ namespace ZL spaceshipBase = LoadFromTextFile02("resources/spaceshipnew001.txt", CONST_ZIP_FILE); spaceshipBase.RotateByMatrix(Eigen::Quaternionf(Eigen::AngleAxisf(M_PI, Eigen::Vector3f::UnitY())).toRotationMatrix());// QuatFromRotateAroundY(M_PI / 2.0).toRotationMatrix()); + spaceshipBase.Move(Vector3f{ 1.2, 0, -5 }); + spaceshipBase.Scale(0.4f); spaceship.AssignFrom(spaceshipBase); spaceship.RefreshVBO(); @@ -501,12 +520,18 @@ namespace ZL renderer.EnableVertexAttribArray(vTexCoordName); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE); + renderer.PushMatrix(); + renderer.LoadIdentity(); + renderer.TranslateMatrix({ 0,0, -1.0f * Environment::zoom }); + renderer.RotateMatrix(Environment::inverseShipMatrix); + renderer.TranslateMatrix(-Environment::shipState.position); for (const auto& p : projectiles) { if (p && p->isActive()) { - p->draw(renderer); + //p->draw(renderer); p->projectileEmitter.draw(renderer, Environment::zoom, Environment::width, Environment::height); } } + renderer.PopMatrix(); glDisable(GL_BLEND); renderer.DisableVertexAttribArray(vPositionName); @@ -519,12 +544,17 @@ namespace ZL renderer.PushMatrix(); renderer.TranslateMatrix({ 0, 0, 16 }); renderer.TranslateMatrix({ 0, -6.f, 0 }); - sparkEmitter.draw(renderer, Environment::zoom, Environment::width, Environment::height); + if (Environment::shipState.shipType == 1) { + sparkEmitterCargo.draw(renderer, Environment::zoom, Environment::width, Environment::height, false); + } + else { + sparkEmitter.draw(renderer, Environment::zoom, Environment::width, Environment::height, false); + } renderer.PopMatrix(); } if (showExplosion) { - explosionEmitter.draw(renderer, Environment::zoom, Environment::width, Environment::height); + explosionEmitter.draw(renderer, Environment::zoom, Environment::width, Environment::height, false); } //glBindTexture(GL_TEXTURE_2D, basePlatformTexture->getTexID()); @@ -1450,7 +1480,17 @@ namespace ZL auto now_ms = newTickCount; - sparkEmitter.update(static_cast(delta)); + SparkEmitter* sparkEmitterPtr; + + if (Environment::shipState.shipType == 1) { + sparkEmitterPtr = &sparkEmitterCargo; + } + else + { + sparkEmitterPtr = &sparkEmitter; + + } + sparkEmitterPtr->update(static_cast(delta)); planetObject.update(static_cast(delta)); if (firePressed) @@ -1594,9 +1634,9 @@ namespace ZL for (const auto& p : projectiles) { if (p && p->isActive()) { Vector3f worldPos = p->getPosition(); - Vector3f rel = worldPos - Environment::shipState.position; - Vector3f camPos = Environment::inverseShipMatrix * rel; - p->projectileEmitter.setEmissionPoints({ camPos }); + //Vector3f rel = worldPos - Environment::shipState.position; + //Vector3f camPos = Environment::inverseShipMatrix * rel; + p->projectileEmitter.setEmissionPoints({ worldPos }); p->projectileEmitter.emit(); p->projectileEmitter.update(static_cast(delta)); } @@ -1610,16 +1650,25 @@ namespace ZL projectileEmitter.setEmissionPoints(std::vector()); }*/ - std::vector shipCameraPoints; - for (const auto& lp : shipLocalEmissionPoints) { - Vector3f adjusted = lp + Vector3f{ 0.0f, -Environment::zoom * 0.03f, 0.0f }; - shipCameraPoints.push_back(adjusted); + if (Environment::shipState.velocity > 0.1f) { + + sparkEmitterPtr->setIsActive(true); + + std::vector shipCameraPoints; + for (const auto& lp : shipLocalEmissionPoints) { + Vector3f adjusted = lp + Vector3f{ 0.0f, -Environment::zoom * 0.03f, 0.0f }; + shipCameraPoints.push_back(adjusted); + } + if (!shipCameraPoints.empty()) { + sparkEmitterPtr->setEmissionPoints(shipCameraPoints); + } } - if (!shipCameraPoints.empty()) { - sparkEmitter.setEmissionPoints(shipCameraPoints); + else + { + sparkEmitterPtr->setIsActive(false); } - sparkEmitter.update(static_cast(delta)); + sparkEmitterPtr->update(static_cast(delta)); //projectileEmitter.update(static_cast(delta)); explosionEmitter.update(static_cast(delta)); diff --git a/src/Space.h b/src/Space.h index 9008a69..94f50c6 100644 --- a/src/Space.h +++ b/src/Space.h @@ -88,6 +88,7 @@ namespace ZL { VertexDataStruct boxBase; SparkEmitter sparkEmitter; + SparkEmitter sparkEmitterCargo; SparkEmitter projectileEmitter; SparkEmitter explosionEmitter; PlanetObject planetObject; diff --git a/src/SparkEmitter.cpp b/src/SparkEmitter.cpp index 5f70710..748afd5 100644 --- a/src/SparkEmitter.cpp +++ b/src/SparkEmitter.cpp @@ -74,7 +74,7 @@ namespace ZL { texture = tex; } - void SparkEmitter::prepareDrawData() { + void SparkEmitter::prepareDrawData(bool withRotation) { if (!drawDataDirty) return; drawPositions.clear(); @@ -91,10 +91,10 @@ namespace ZL { for (const auto& particle : particles) { if (particle.active) { Vector3f posCam; - if (useWorldSpace) { + if (withRotation) { Vector3f rel = particle.position - Environment::shipState.position; posCam = Environment::inverseShipMatrix * rel; - } + } else { posCam = particle.position; } @@ -120,29 +120,59 @@ namespace ZL { float size = particleSize * particle.scale; - drawPositions.push_back({ posCam(0) - size, posCam(1) - size, posCam(2) }); - drawTexCoords.push_back({ 0.0f, 0.0f }); + if (withRotation) + { - drawPositions.push_back({ posCam(0) - size, posCam(1) + size, posCam(2) }); - drawTexCoords.push_back({ 0.0f, 1.0f }); + drawPositions.push_back(Environment::shipState.rotation * Vector3f{ -size, -size, 0 } + posCam); + drawTexCoords.push_back({ 0.0f, 0.0f }); - drawPositions.push_back({ posCam(0) + size, posCam(1) + size, posCam(2) }); - drawTexCoords.push_back({ 1.0f, 1.0f }); + drawPositions.push_back(Environment::shipState.rotation * Vector3f{ -size, size,0 } + posCam); + drawTexCoords.push_back({ 0.0f, 1.0f }); - drawPositions.push_back({ posCam(0) - size, posCam(1) - size, posCam(2) }); - drawTexCoords.push_back({ 0.0f, 0.0f }); + drawPositions.push_back(Environment::shipState.rotation * Vector3f{ size,size, 0 } + posCam); + drawTexCoords.push_back({ 1.0f, 1.0f }); - drawPositions.push_back({ posCam(0) + size, posCam(1) + size, posCam(2) }); - drawTexCoords.push_back({ 1.0f, 1.0f }); + drawPositions.push_back(Environment::shipState.rotation * Vector3f{ -size, -size, 0 } + posCam); + drawTexCoords.push_back({ 0.0f, 0.0f }); - drawPositions.push_back({ posCam(0) + size, posCam(1) - size, posCam(2) }); - drawTexCoords.push_back({ 1.0f, 0.0f }); + drawPositions.push_back(Environment::shipState.rotation * Vector3f{ size, size,0 } + posCam); + drawTexCoords.push_back({ 1.0f, 1.0f }); + + drawPositions.push_back(Environment::shipState.rotation * Vector3f{ size, -size, 0 } + posCam); + drawTexCoords.push_back({ 1.0f, 0.0f }); + } + else + { + drawPositions.push_back({ posCam(0) - size, posCam(1) - size, posCam(2) }); + drawTexCoords.push_back({ 0.0f, 0.0f }); + + drawPositions.push_back({ posCam(0) - size, posCam(1) + size, posCam(2) }); + drawTexCoords.push_back({ 0.0f, 1.0f }); + + drawPositions.push_back({ posCam(0) + size, posCam(1) + size, posCam(2) }); + drawTexCoords.push_back({ 1.0f, 1.0f }); + + drawPositions.push_back({ posCam(0) - size, posCam(1) - size, posCam(2) }); + drawTexCoords.push_back({ 0.0f, 0.0f }); + + drawPositions.push_back({ posCam(0) + size, posCam(1) + size, posCam(2) }); + drawTexCoords.push_back({ 1.0f, 1.0f }); + + drawPositions.push_back({ posCam(0) + size, posCam(1) - size, posCam(2) }); + drawTexCoords.push_back({ 1.0f, 0.0f }); + + } } drawDataDirty = false; } - void SparkEmitter::draw(Renderer& renderer, float zoom, int screenWidth, int screenHeight) { + void SparkEmitter::draw(Renderer& renderer, float zoom, int screenWidth, int screenHeight) + { + draw(renderer, zoom, screenWidth, screenHeight, true); + } + + void SparkEmitter::draw(Renderer& renderer, float zoom, int screenWidth, int screenHeight, bool withRotation) { if (!configured) { throw std::runtime_error("Failed to load spark emitter config file 1!"); } @@ -155,7 +185,7 @@ namespace ZL { throw std::runtime_error("Failed to load spark emitter config file 2!"); } - prepareDrawData(); + prepareDrawData(withRotation); if (drawPositions.empty()) { return; diff --git a/src/SparkEmitter.h b/src/SparkEmitter.h index 812b828..744c32f 100644 --- a/src/SparkEmitter.h +++ b/src/SparkEmitter.h @@ -50,7 +50,7 @@ namespace ZL { std::string shaderProgramName; bool configured; - void prepareDrawData(); + void prepareDrawData(bool withRotation); bool useWorldSpace; public: @@ -76,11 +76,17 @@ namespace ZL { void emit(); void draw(Renderer& renderer, float zoom, int screenWidth, int screenHeight); + void draw(Renderer& renderer, float zoom, int screenWidth, int screenHeight, bool withRotation); const std::vector& getParticles() const; size_t getActiveParticleCount() const; std::shared_ptr getTexture() const { return texture; } + void setIsActive(bool newActive) + { + isActive = newActive; + } + private: void initParticle(SparkParticle& particle, int emitterIndex); Vector3f getRandomVelocity(int emitterIndex); diff --git a/src/UiManager.cpp b/src/UiManager.cpp index 1359250..8a7bcf9 100644 --- a/src/UiManager.cpp +++ b/src/UiManager.cpp @@ -57,6 +57,7 @@ namespace ZL { case ButtonState::Normal: tex = &texNormal; break; case ButtonState::Hover: tex = &texHover; break; case ButtonState::Pressed: tex = &texPressed; break; + case ButtonState::Disabled: tex = &texDisabled; break; } if (!(*tex)) return; @@ -290,6 +291,9 @@ namespace ZL { btn->texNormal = loadTex("normal"); btn->texHover = loadTex("hover"); btn->texPressed = loadTex("pressed"); + btn->texDisabled = loadTex("disabled"); + + btn->border = j.value("border", 0.0f); node->button = btn; } @@ -1049,11 +1053,14 @@ namespace ZL { void UiManager::onMouseMove(int x, int y) { for (auto& b : buttons) { - if (b->rect.contains((float)x, (float)y)) { - if (b->state != ButtonState::Pressed) b->state = ButtonState::Hover; - } - else { - if (b->state != ButtonState::Pressed) b->state = ButtonState::Normal; + if (b->state != ButtonState::Disabled) + { + if (b->rect.containsConsideringBorder((float)x, (float)y, b->border)) { + if (b->state != ButtonState::Pressed) b->state = ButtonState::Hover; + } + else { + if (b->state != ButtonState::Pressed) b->state = ButtonState::Normal; + } } } @@ -1074,11 +1081,15 @@ namespace ZL { } } + void UiManager::onMouseDown(int x, int y) { for (auto& b : buttons) { - if (b->rect.contains((float)x, (float)y)) { - b->state = ButtonState::Pressed; - pressedButton = b; + if (b->state != ButtonState::Disabled) + { + if (b->rect.containsConsideringBorder((float)x, (float)y, b->border)) { + b->state = ButtonState::Pressed; + pressedButton = b; + } } } diff --git a/src/UiManager.h b/src/UiManager.h index 56f95ad..a03fa85 100644 --- a/src/UiManager.h +++ b/src/UiManager.h @@ -23,12 +23,17 @@ namespace ZL { bool contains(float px, float py) const { return px >= x && px <= x + w && py >= y && py <= y + h; } + + bool containsConsideringBorder(float px, float py, float border) const { + return px >= x+border && px <= x + w-border && py >= y+border && py <= y + h-border; + } }; enum class ButtonState { Normal, Hover, - Pressed + Pressed, + Disabled }; enum class LayoutType { @@ -76,9 +81,11 @@ namespace ZL { struct UiButton { std::string name; UiRect rect; + float border = 0; std::shared_ptr texNormal; std::shared_ptr texHover; std::shared_ptr texPressed; + std::shared_ptr texDisabled; ButtonState state = ButtonState::Normal; VertexRenderStruct mesh; diff --git a/src/network/ClientState.h b/src/network/ClientState.h index 5bbd8b3..0812892 100644 --- a/src/network/ClientState.h +++ b/src/network/ClientState.h @@ -14,7 +14,7 @@ constexpr auto NET_SECRET = "880b3713b9ff3e7a94b2712d54679e1f"; #define ENABLE_NETWORK_CHECKSUM constexpr float ANGULAR_ACCEL = 0.005f * 1000.0f; -constexpr float SHIP_ACCEL = 1.0f * 1000.0f; +constexpr float SHIP_ACCEL = 1.0f * 200.0f; constexpr float ROTATION_SENSITIVITY = 0.002f; constexpr float PLANET_RADIUS = 20000.f;