Skip to content

Commit

Permalink
CLIENT-GAME: Add begin of collisionRectOffset
Browse files Browse the repository at this point in the history
  • Loading branch information
TTENSHII committed Nov 3, 2023
1 parent 88c3bc5 commit 9028d29
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 25 deletions.
20 changes: 15 additions & 5 deletions assets/Json/bullets.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
36 changes: 27 additions & 9 deletions assets/Json/enemies.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
},
"collisionRect": {
"width": 1000,
"height":1000
"height":1000,
"offsetX": 0,
"offsetY": 0
},
"velocity": {
"speedX": -40,
Expand Down Expand Up @@ -65,7 +67,9 @@
},
"collisionRect": {
"width": 1000,
"height":1000
"height":1000,
"offsetX": 0,
"offsetY": 0
},
"velocity": {
"speedX": -40,
Expand Down Expand Up @@ -145,7 +149,9 @@
},
"collisionRect": {
"width": 1000,
"height":1000
"height":1000,
"offsetX": 0,
"offsetY": 0
},
"velocity": {
"speedX": -40,
Expand Down Expand Up @@ -214,7 +220,9 @@
},
"collisionRect": {
"width": 850,
"height": 1287
"height": 1287,
"offsetX": 0,
"offsetY": 0
},
"velocity": {
"speedX": -20,
Expand Down Expand Up @@ -276,7 +284,9 @@
},
"collisionRect": {
"width": 480,
"height": 932
"height": 932,
"offsetX": 0,
"offsetY": 0
},
"velocity": {
"speedX": -20,
Expand Down Expand Up @@ -344,7 +354,9 @@
},
"collisionRect": {
"width": 2320,
"height": 3400
"height": 3400,
"offsetX": 0,
"offsetY": 0
},
"velocity": {
"speedX": -20,
Expand Down Expand Up @@ -533,7 +545,9 @@
},
"collisionRect": {
"width": 2320,
"height": 3400
"height": 3400,
"offsetX": 0,
"offsetY": 0
},
"velocity": {
"speedX": -20,
Expand Down Expand Up @@ -716,7 +730,9 @@
},
"collisionRect": {
"width": 2150,
"height": 4000
"height": 4000,
"offsetX": 0,
"offsetY": 0
},
"velocity": {
"speedX": -20,
Expand Down Expand Up @@ -928,7 +944,9 @@
},
"collisionRect": {
"width": 512,
"height": 512
"height": 512,
"offsetX": 0,
"offsetY": 0
},
"velocity": {
"speedX": -20,
Expand Down
4 changes: 3 additions & 1 deletion assets/Json/playerData.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
},
"collisionRect": {
"width": 500,
"height": 500
"height": 500,
"offsetX": 0,
"offsetY": 0
},
"animRect": [
{
Expand Down
10 changes: 6 additions & 4 deletions src/Client/Systems/Events/EventsSystems.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ namespace Systems {
Json &json = Json::getInstance();
Registry &registry = Registry::getInstance();
Registry::components<Types::CollisionRect> arrCol = registry.getComponents<Types::CollisionRect>();

//TODO
if (arrCol.exist(id)) {
Types::CollisionRect &col = arrCol[id];
float posX = Maths::intToFloatConservingDecimals(pos.x)
Expand Down Expand Up @@ -259,15 +259,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);
Expand Down
5 changes: 3 additions & 2 deletions src/Client/Systems/Graphic/GraphicSystems.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ namespace Systems {
for (auto &id : ids) {
if (arrPosition.exist(id) && !arrRectangleShape.exist(id)) {
Types::RectangleShape rectShape = {
Maths::intToFloatConservingDecimals(arrCollisionRect[id].width),
Maths::intToFloatConservingDecimals(arrCollisionRect[id].height)};
Maths::intToFloatConservingDecimals(arrCollisionRect[id].width) - Maths::intToFloatConservingDecimals(arrCollisionRect[id].offsetX),
Maths::intToFloatConservingDecimals(arrCollisionRect[id].height) - Maths::intToFloatConservingDecimals(arrCollisionRect[id].offsetY),
};
Registry::getInstance().getComponents<Types::RectangleShape>().insert(id, rectShape);
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/ECS/ECSCustomTypes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/ECS/Systems/BulletsSystems.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ namespace Systems {
velocities[id].speedY = -velocities[id].speedY;
}
}
}
} // TODO
}

static void updateZigzagPhysics(std::vector<std::size_t> ids)
Expand Down
4 changes: 2 additions & 2 deletions src/ECS/Systems/Systems.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ namespace Systems {
Registry::components<Types::Position> arrPosition = registry.getComponents<Types::Position>();
Registry::components<Types::CollisionRect> arrCollisionRect =
registry.getComponents<Types::CollisionRect>();

//TODO
for (std::size_t id : ids) {
if (arrPosition[id].x < 0) {
arrPosition[id].x = 0;
Expand Down Expand Up @@ -133,7 +133,7 @@ namespace Systems {
std::vector<std::size_t> &ids,
Registry::components<Types::Position> arrPosition,
Registry::components<Types::CollisionRect> arrCollisionRect)
{
{ // TODO
std::size_t id = *itIds;
Types::Position entityPos = arrPosition[id];
Types::CollisionRect entityColl = arrCollisionRect[id];
Expand Down

0 comments on commit 9028d29

Please sign in to comment.