Skip to content

Commit

Permalink
CLIENT-GAME: Fix request changes
Browse files Browse the repository at this point in the history
PATCH
  • Loading branch information
KitetsuK committed Oct 3, 2023
1 parent 2bed528 commit 608aee6
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 37 deletions.
72 changes: 38 additions & 34 deletions src/Client/Systems/Events/EventsSystems.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,56 +57,60 @@ namespace Systems {

const Types::Rect spriteRect = {300, 121, 32, 10};
const std::string bulletPath = "assets/R-TypeSheet/r-typesheet1.gif";
constexpr float playerWidth = 5.0F;
constexpr float playerHeight = 5.0F;
constexpr float bulletWidth = 5.0F;
constexpr float bulletHeight = 5.0F;
const Types::CollisionRect collisionRect = {1, 1};
const Types::Velocity velocity = {-0.7F, 0.0F};
const Types::Missiles missileType = {"classic"};
const Types::Missiles missileType = {Types::MissileTypes::CLASSIC};
const Types::Health health = {1};
const Types::Dammage dammage = {10};

static void createMissile(std::size_t id, Registry::components<Types::Position> &arrPosition)
{
if (arrPosition.exist(id)) {
std::size_t entityId = Registry::getInstance().addEntity();

Registry::getInstance()
.getComponents<Types::Position>()
.insertBack({arrPosition[id].x, arrPosition[id].y});
Registry::getInstance()
.getComponents<Raylib::Sprite>()
.insertBack(
{bulletPath, bulletWidth, bulletHeight, entityId});
Registry::getInstance()
.getComponents<Types::Rect>()
.insertBack(spriteRect);
Registry::getInstance()
.getComponents<Types::CollisionRect>()
.insertBack(collisionRect);
Registry::getInstance()
.getComponents<Types::Missiles>()
.insertBack(missileType);
Registry::getInstance()
.getComponents<Types::Velocity>()
.insertBack(velocity);
Registry::getInstance()
.getComponents<Types::Health>()
.insertBack(health);
Registry::getInstance()
.getComponents<Types::Dammage>()
.insertBack(dammage);
Registry::getInstance().setToFrontLayers(entityId);
}
}

void playerShootBullet(std::size_t, std::size_t)
{
Registry::components<Types::Player> arrPlayer =
Registry::getInstance().getComponents<Types::Player>();
Registry::components<Types::Position> arrPosition =
Registry::getInstance().getComponents<Types::Position>();
Registry::components<Types::Rect> arrRect =
Registry::getInstance().getComponents<Types::Rect>();

std::vector<std::size_t> ids = arrPlayer.getExistingsId();

if (Raylib::isKeyDown(Raylib::KeyboardKey::KB_SPACE)) {
for (auto &id : ids) {
if (arrPosition.exist(id) && arrRect.exist(id)) {
std::size_t entityId = Registry::getInstance().addEntity();
Registry::getInstance()
.getComponents<Types::Position>()
.insertBack({arrPosition[id].x, arrPosition[id].y});
Registry::getInstance()
.getComponents<Raylib::Sprite>()
.insertBack(
{bulletPath, playerWidth, playerHeight, entityId});
Registry::getInstance()
.getComponents<Types::Rect>()
.insertBack(spriteRect);
Registry::getInstance()
.getComponents<Types::CollisionRect>()
.insertBack(collisionRect);
Registry::getInstance()
.getComponents<Types::Missiles>()
.insertBack(missileType);
Registry::getInstance()
.getComponents<Types::Velocity>()
.insertBack(velocity);
Registry::getInstance()
.getComponents<Types::Health>()
.insertBack(health);
Registry::getInstance()
.getComponents<Types::Dammage>()
.insertBack(dammage);
Registry::getInstance().setToFrontLayers(entityId);
}
createMissile(id, arrPosition);
}
}
}
Expand Down
5 changes: 4 additions & 1 deletion src/ECS/ECSCustomTypes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@

namespace Types {

enum MissileTypes {CLASSIC};


struct CollisionRect {
float width;
float height;
Expand Down Expand Up @@ -43,7 +46,7 @@ namespace Types {

struct Missiles {
// maybe enum better ?
std::string type;
MissileTypes type;
};

} // namespace Types
4 changes: 2 additions & 2 deletions src/ECS/Systems/Systems.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ namespace Systems {
.getComponents<Types::RectangleShape>()
.insert(
id,
{arrCollisionRect[id].width + 2,
arrCollisionRect[id].height + 2});
{arrCollisionRect[id].width ,
arrCollisionRect[id].height});
}
}
}
Expand Down

0 comments on commit 608aee6

Please sign in to comment.