diff --git a/assets/Json/bullets.json b/assets/Json/bullets.json index 674e7742..87fe1020 100644 --- a/assets/Json/bullets.json +++ b/assets/Json/bullets.json @@ -11,7 +11,9 @@ "waitTimeBullet": 500, "collisionRect": { "width": 450, - "height": 450 + "height": 450, + "offsetX": 0, + "offsetY": 0 }, "spritePath": "assets/R-TypeSheet/WaterBullets.png", "soundPath": "assets/Audio/Sounds/laser.ogg", @@ -77,7 +79,9 @@ "waitTimeBullet": 200, "collisionRect": { "width": 200, - "height": 200 + "height": 200, + "offsetX": 0, + "offsetY": 0 }, "spritePath": "assets/R-TypeSheet/classic-bullets.png", "soundPath": "assets/Audio/Sounds/glitch.ogg", @@ -230,7 +234,9 @@ "waitTimeBullet": 500, "collisionRect": { "width": 300, - "height": 300 + "height": 300, + "offsetX": 0, + "offsetY": 0 }, "spritePath": "assets/R-TypeSheet/GreenBullets.png", "soundPath": "assets/Audio/Sounds/laser2.ogg", @@ -287,7 +293,9 @@ "waitTimeBullet": 1000, "collisionRect": { "width": 500, - "height": 500 + "height": 500, + "offsetX": 0, + "offsetY": 0 }, "spritePath": "assets/R-TypeSheet/PurpleBullets.png", "soundPath": "assets/Audio/Sounds/forceField.ogg", @@ -344,7 +352,9 @@ "waitTimeBullet": 1000, "collisionRect": { "width": 500, - "height": 500 + "height": 500, + "offsetX": 0, + "offsetY": 0 }, "spritePath": "assets/R-TypeSheet/jutteurs-bullet.png", "soundPath": "assets/Audio/Sounds/forceField.ogg", diff --git a/assets/Json/enemies.json b/assets/Json/enemies.json index ea31ecf0..54a19dfe 100644 --- a/assets/Json/enemies.json +++ b/assets/Json/enemies.json @@ -15,7 +15,9 @@ }, "collisionRect": { "width": 1000, - "height":1000 + "height":1000, + "offsetX": 0, + "offsetY": 0 }, "velocity": { "speedX": -40, @@ -65,7 +67,9 @@ }, "collisionRect": { "width": 1000, - "height":1000 + "height":1000, + "offsetX": 0, + "offsetY": 0 }, "velocity": { "speedX": -40, @@ -145,7 +149,9 @@ }, "collisionRect": { "width": 1000, - "height":1000 + "height":1000, + "offsetX": 0, + "offsetY": 0 }, "velocity": { "speedX": -40, @@ -214,7 +220,9 @@ }, "collisionRect": { "width": 850, - "height": 1287 + "height": 1287, + "offsetX": 0, + "offsetY": 0 }, "velocity": { "speedX": -20, @@ -276,7 +284,9 @@ }, "collisionRect": { "width": 480, - "height": 932 + "height": 932, + "offsetX": 0, + "offsetY": 0 }, "velocity": { "speedX": -20, @@ -344,7 +354,9 @@ }, "collisionRect": { "width": 2320, - "height": 3400 + "height": 3400, + "offsetX": 0, + "offsetY": 0 }, "velocity": { "speedX": -20, @@ -532,8 +544,10 @@ "height": 381 }, "collisionRect": { - "width": 2320, - "height": 3400 + "width": 1320, + "height": 3400, + "offsetX": 1000, + "offsetY": 0 }, "velocity": { "speedX": -20, @@ -716,7 +730,9 @@ }, "collisionRect": { "width": 2150, - "height": 4000 + "height": 4000, + "offsetX": 0, + "offsetY": 0 }, "velocity": { "speedX": -20, @@ -928,7 +944,9 @@ }, "collisionRect": { "width": 512, - "height": 512 + "height": 512, + "offsetX": 0, + "offsetY": 0 }, "velocity": { "speedX": -20, diff --git a/assets/Json/playerData.json b/assets/Json/playerData.json index 04117f74..4aca7008 100644 --- a/assets/Json/playerData.json +++ b/assets/Json/playerData.json @@ -18,7 +18,9 @@ }, "collisionRect": { "width": 500, - "height": 500 + "height": 500, + "offsetX": 0, + "offsetY": 0 }, "animRect": [ { diff --git a/assets/Json/waves.json b/assets/Json/waves.json index 83b69f9e..852ed704 100644 --- a/assets/Json/waves.json +++ b/assets/Json/waves.json @@ -28,15 +28,7 @@ "msBeforeSpawn" : 2000 }, { - "id": "big-daemon", - "position" : { - "x": 10500, - "y": 4500 - }, - "msBeforeSpawn" : 2000 - }, - { - "id": "big-purple-boss", + "id": "green-head", "position" : { "x": 10500, "y": 2500 diff --git a/src/Client/Systems/Events/EventsSystems.cpp b/src/Client/Systems/Events/EventsSystems.cpp index 0af092e2..3204bad8 100644 --- a/src/Client/Systems/Events/EventsSystems.cpp +++ b/src/Client/Systems/Events/EventsSystems.cpp @@ -93,8 +93,10 @@ namespace Systems { if (arrCol.exist(id)) { Types::CollisionRect &col = arrCol[id]; float posX = Maths::intToFloatConservingDecimals(pos.x) + + (Maths::intToFloatConservingDecimals(col.offsetX)) + (Maths::intToFloatConservingDecimals(col.width) / 2.F); float posY = Maths::intToFloatConservingDecimals(pos.y) + + (Maths::intToFloatConservingDecimals(col.offsetY)) + (Maths::intToFloatConservingDecimals(col.height) / 2.F); newPos.x = Maths::floatToIntConservingDecimals(posX); newPos.y = Maths::floatToIntConservingDecimals(posY); @@ -259,15 +261,17 @@ namespace Systems { void EventsSystems::handleEndGameEvent(std::size_t /*unused*/, std::size_t /*unused*/) { constexpr std::size_t secondBeforeEnd = 5; - static std::size_t clockId = Registry::getInstance().getClock().create(false); + static std::size_t clockId = Registry::getInstance().getClock().create(false); std::size_t elapsedSeconds = Registry::getInstance().getClock().elapsedSecondsSince(clockId); std::string seconds = std::to_string(secondBeforeEnd - elapsedSeconds); std::string endGameMessage; if (isGameWin() == true) { - endGameMessage = "You win! Redirecting to menu in " + seconds + " seconds"; + endGameMessage = + "You win! Redirecting to menu in " + seconds + (seconds == "1" ? " second" : " seconds"); } else { - endGameMessage = "You lose! Redirecting to menu in " + seconds + " seconds"; + endGameMessage = + "You lose! Redirecting to menu in " + seconds + (seconds == "1" ? " second" : " seconds"); } modifEndGameText(endGameMessage); diff --git a/src/Client/Systems/Graphic/GraphicSystems.cpp b/src/Client/Systems/Graphic/GraphicSystems.cpp index 6e66e9df..141f0545 100644 --- a/src/Client/Systems/Graphic/GraphicSystems.cpp +++ b/src/Client/Systems/Graphic/GraphicSystems.cpp @@ -35,7 +35,8 @@ namespace Systems { if (arrPosition.exist(id) && !arrRectangleShape.exist(id)) { Types::RectangleShape rectShape = { Maths::intToFloatConservingDecimals(arrCollisionRect[id].width), - Maths::intToFloatConservingDecimals(arrCollisionRect[id].height)}; + Maths::intToFloatConservingDecimals(arrCollisionRect[id].height), + }; Registry::getInstance().getComponents().insert(id, rectShape); } } diff --git a/src/Client/Systems/Graphic/SpriteSystems.cpp b/src/Client/Systems/Graphic/SpriteSystems.cpp index 0b6c4a61..3177c840 100644 --- a/src/Client/Systems/Graphic/SpriteSystems.cpp +++ b/src/Client/Systems/Graphic/SpriteSystems.cpp @@ -68,15 +68,22 @@ namespace Systems { std::lock_guard lock(Registry::getInstance().mutex); Registry ®istry = Registry::getInstance(); Registry::components arrPosition = registry.getComponents(); + Registry::components arrCollision = + registry.getComponents(); Registry::components arrRect = registry.getComponents(); std::vector ids = registry.getEntitiesByComponents({typeid(Types::RectangleShape), typeid(Types::Position)}); for (auto id : ids) { - Types::Position &position = arrPosition[id]; + Types::Position position = arrPosition[id]; Types::RectangleShape &rectangle = arrRect[id]; + if (arrCollision.exist(id)) { + position.x += arrCollision[id].offsetX; + position.y += arrCollision[id].offsetY; + } + float x = (Maths::intToFloatConservingDecimals(position.x) * static_cast(Raylib::getScreenWidth())) / denominator; @@ -102,19 +109,24 @@ namespace Systems { Registry::components arrRotation = Registry::getInstance().getComponents(); Registry::components arrColor = Registry::getInstance().getComponents(); - float scale = 1.0F; float rotation = 0; Raylib::Color tint = Raylib::White; Raylib::Vector2 spritePos = {0, 0}; + Raylib::Vector2 origin = {0, 0}; rotation = arrRotation.exist(entityId) ? arrRotation[entityId].rotate : rotation; tint = arrColor.exist(entityId) ? arrColor[entityId].color : tint; - scale = (sprite.getWidth() * static_cast(Raylib::getScreenWidth())) / denominator - / static_cast(sprite.getTextureWidth()); spritePos = calculatePosition( Maths::intToFloatConservingDecimals(position.x), Maths::intToFloatConservingDecimals(position.y)); - sprite.drawEx(spritePos, rotation, scale, tint); + + Raylib::Vector2 size = calculateSize(sprite); + sprite.drawPro( + Raylib::Rectangle(0.F, 0.F, sprite.getTextureWidth(), sprite.getTextureHeight()), + Raylib::Rectangle(spritePos.x, spritePos.y, size.x, size.y), + origin, + rotation, + tint); } static void drawSpriteWithRect( @@ -220,6 +232,6 @@ namespace Systems { std::vector> GraphicSystems::getSpriteSystems() { - return {updateAnimation, rectRenderer, spriteRenderer, createSprite}; + return {updateAnimation, spriteRenderer, createSprite, rectRenderer}; } } // namespace Systems diff --git a/src/ECS/ECSCustomTypes.hpp b/src/ECS/ECSCustomTypes.hpp index 32d03b16..085e9d0f 100644 --- a/src/ECS/ECSCustomTypes.hpp +++ b/src/ECS/ECSCustomTypes.hpp @@ -26,8 +26,10 @@ namespace Types { struct CollisionRect { int width; int height; + int offsetX; + int offsetY; - NLOHMANN_DEFINE_TYPE_INTRUSIVE(CollisionRect, width, height); + NLOHMANN_DEFINE_TYPE_INTRUSIVE(CollisionRect, width, height, offsetX, offsetY); }; struct Position { diff --git a/src/ECS/Systems/BulletsSystems.cpp b/src/ECS/Systems/BulletsSystems.cpp index a805e159..bb679bc9 100644 --- a/src/ECS/Systems/BulletsSystems.cpp +++ b/src/ECS/Systems/BulletsSystems.cpp @@ -146,10 +146,10 @@ namespace Systems { for (std::size_t id : ids) { if (velocities.exist(id) && collisionRects.exist(id) && positions.exist(id)) { - if (Maths::intToFloatConservingDecimals(positions[id].y) <= 0 - || Maths::intToFloatConservingDecimals(positions[id].y) - + Maths::intToFloatConservingDecimals(collisionRects[id].height) - >= 100) { + float realPosY = Maths::intToFloatConservingDecimals(positions[id].y) + + Maths::intToFloatConservingDecimals(collisionRects[id].offsetY); + if (realPosY <= 0 + || realPosY + Maths::intToFloatConservingDecimals(collisionRects[id].height) >= 100) { velocities[id].speedY = -velocities[id].speedY; } } diff --git a/src/ECS/Systems/Systems.cpp b/src/ECS/Systems/Systems.cpp index 138c0b35..8218b144 100644 --- a/src/ECS/Systems/Systems.cpp +++ b/src/ECS/Systems/Systems.cpp @@ -137,24 +137,23 @@ namespace Systems { std::size_t id = *itIds; Types::Position entityPos = arrPosition[id]; Types::CollisionRect entityColl = arrCollisionRect[id]; - + Types::Position realPosFstEntity = {entityPos.x + entityColl.offsetX, entityPos.y + entityColl.offsetY}; itIds++; while (itIds != ids.end()) { if (arrCollisionRect.exist(*itIds)) { - Types::CollisionRect sndEntityRect = arrCollisionRect[*itIds]; - Types::Position sndEntityPos = arrPosition[*itIds]; - if (Maths::intToFloatConservingDecimals(entityPos.x) - < (Maths::intToFloatConservingDecimals(sndEntityPos.x) - + Maths::intToFloatConservingDecimals(sndEntityRect.width)) - && (Maths::intToFloatConservingDecimals(entityPos.x) + Types::Position realPosSndEntity = {arrPosition[*itIds].x + arrCollisionRect[*itIds].offsetX, arrPosition[*itIds].y + arrCollisionRect[*itIds].offsetY}; + if (Maths::intToFloatConservingDecimals(realPosFstEntity.x) + < (Maths::intToFloatConservingDecimals(realPosSndEntity.x) + + Maths::intToFloatConservingDecimals(arrCollisionRect[*itIds].width)) + && (Maths::intToFloatConservingDecimals(realPosFstEntity.x) + Maths::intToFloatConservingDecimals(entityColl.width)) - > Maths::intToFloatConservingDecimals(sndEntityPos.x) - && Maths::intToFloatConservingDecimals(entityPos.y) - < (Maths::intToFloatConservingDecimals(sndEntityPos.y) - + Maths::intToFloatConservingDecimals(sndEntityRect.height)) - && (Maths::intToFloatConservingDecimals(entityPos.y) + > Maths::intToFloatConservingDecimals(realPosSndEntity.x) + && Maths::intToFloatConservingDecimals(realPosFstEntity.y) + < (Maths::intToFloatConservingDecimals(realPosSndEntity.y) + + Maths::intToFloatConservingDecimals(arrCollisionRect[*itIds].height)) + && (Maths::intToFloatConservingDecimals(realPosFstEntity.y) + Maths::intToFloatConservingDecimals(entityColl.height)) - > Maths::intToFloatConservingDecimals(sndEntityPos.y)) { + > Maths::intToFloatConservingDecimals(realPosSndEntity.y)) { checkSide(id, *itIds); } }