Skip to content

Commit

Permalink
Merge branch 'freature/RB-159-enhance-waves' of github.com:X-R-G-B/R-…
Browse files Browse the repository at this point in the history
…Bus into freature/RB-159-enhance-waves
  • Loading branch information
romainpanno committed Nov 3, 2023
2 parents d04692e + b9e83d7 commit 84fced6
Show file tree
Hide file tree
Showing 10 changed files with 93 additions and 53 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
38 changes: 28 additions & 10 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 @@ -532,8 +544,10 @@
"height": 381
},
"collisionRect": {
"width": 2320,
"height": 3400
"width": 1320,
"height": 3400,
"offsetX": 1000,
"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: 1 addition & 9 deletions assets/Json/waves.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 7 additions & 3 deletions src/Client/Systems/Events/EventsSystems.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion src/Client/Systems/Graphic/GraphicSystems.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Types::RectangleShape>().insert(id, rectShape);
}
}
Expand Down
24 changes: 18 additions & 6 deletions src/Client/Systems/Graphic/SpriteSystems.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,22 @@ namespace Systems {
std::lock_guard<std::mutex> lock(Registry::getInstance().mutex);
Registry &registry = Registry::getInstance();
Registry::components<Types::Position> arrPosition = registry.getComponents<Types::Position>();
Registry::components<Types::CollisionRect> arrCollision =
registry.getComponents<Types::CollisionRect>();
Registry::components<Types::RectangleShape> arrRect =
registry.getComponents<Types::RectangleShape>();
std::vector<std::size_t> 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<float>(Raylib::getScreenWidth()))
/ denominator;
Expand All @@ -102,19 +109,24 @@ namespace Systems {
Registry::components<Types::Rotation> arrRotation =
Registry::getInstance().getComponents<Types::Rotation>();
Registry::components<Types::Color> arrColor = Registry::getInstance().getComponents<Types::Color>();
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<float>(Raylib::getScreenWidth())) / denominator
/ static_cast<float>(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(
Expand Down Expand Up @@ -220,6 +232,6 @@ namespace Systems {

std::vector<std::function<void(std::size_t, std::size_t)>> GraphicSystems::getSpriteSystems()
{
return {updateAnimation, rectRenderer, spriteRenderer, createSprite};
return {updateAnimation, spriteRenderer, createSprite, rectRenderer};
}
} // namespace Systems
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
8 changes: 4 additions & 4 deletions src/ECS/Systems/BulletsSystems.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
25 changes: 12 additions & 13 deletions src/ECS/Systems/Systems.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down

0 comments on commit 84fced6

Please sign in to comment.