Skip to content

Commit

Permalink
Merge
Browse files Browse the repository at this point in the history
  • Loading branch information
PharaEthan committed Jan 13, 2024
2 parents 9e550d8 + 8bc5db5 commit 4d69cb9
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 44 deletions.
50 changes: 26 additions & 24 deletions Client/src/Layer/RTypeLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,44 +189,46 @@ namespace RType {

int key = event.GetKeyCode();

_Scene->GetWorldPtr()->AsyncForEach<ScriptComponent, TagComponent>([&](Entity *entity, ComponentHandle<ScriptComponent> script, ComponentHandle<TagComponent> tag) {
ScriptComponent &sc = script.Get();
TagComponent &tc = tag.Get();
_Scene->GetWorldPtr()->AsyncForEach<ScriptComponent, TagComponent>(
[&](Entity *entity, ComponentHandle<ScriptComponent> script, ComponentHandle<TagComponent> tag) {
ScriptComponent &sc = script.Get();
TagComponent &tc = tag.Get();

std::ostringstream oss;
oss << _Network->GetIdPlayer();
std::string player = "Player_" + oss.str();
std::ostringstream oss;
oss << _Network->GetIdPlayer();
std::string player = "Player_" + oss.str();

if ((tc.Tag.compare(player) == 0) && sc.Instance != nullptr) {
sc.Instance->OnKeyPressed(key);
if ((tc.Tag.compare(player) == 0) && sc.Instance != nullptr) {
sc.Instance->OnKeyPressed(key);

_Network->SendEvent(false, key, true);
}
_Network->SendEvent(false, key, true);
}

(void)entity;
});
(void)entity;
});

return true;
};

bool RTypeLayer::OnKeyReleasedEvent(KeyReleasedEvent &event) {
int key = event.GetKeyCode();

_Scene->GetWorldPtr()->AsyncForEach<ScriptComponent, TagComponent>([&](Entity *entity, ComponentHandle<ScriptComponent> script, ComponentHandle<TagComponent> tag) {
ScriptComponent &sc = script.Get();
TagComponent &tc = tag.Get();
_Scene->GetWorldPtr()->AsyncForEach<ScriptComponent, TagComponent>(
[&](Entity *entity, ComponentHandle<ScriptComponent> script, ComponentHandle<TagComponent> tag) {
ScriptComponent &sc = script.Get();
TagComponent &tc = tag.Get();

std::ostringstream oss;
oss << _Network->GetIdPlayer();
std::string player = "Player_" + oss.str();
std::ostringstream oss;
oss << _Network->GetIdPlayer();
std::string player = "Player_" + oss.str();

if ((tc.Tag.compare(player) == 0) && sc.Instance != nullptr) {
sc.Instance->OnKeyReleased(key);
_Network->SendEvent(false, key, false);
}
if ((tc.Tag.compare(player) == 0) && sc.Instance != nullptr) {
sc.Instance->OnKeyReleased(key);
_Network->SendEvent(false, key, false);
}

(void)entity;
});
(void)entity;
});

return false;
};
Expand Down
14 changes: 7 additions & 7 deletions R-Type/src/Scripts/Pata-pata/Pata-pata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ namespace RType {
}

void PataPata::UpdateAnimations() {
SpriteRendererComponent &sr = GetComponent<SpriteRendererComponent>();
SpriteRendererComponent &sr = GetComponent<SpriteRendererComponent>();
ComponentHandle<AnimationComponent> anim = HandleEntity.GetEntity()->GetComponent<AnimationComponent>();

if (!anim) {
Expand Down Expand Up @@ -130,8 +130,8 @@ namespace RType {
if (_State == State::DEAD)
return;

TransformComponent &tc = GetComponent<TransformComponent>();
Clock &clock = GetComponent<Clock>();
TransformComponent &tc = GetComponent<TransformComponent>();
Clock &clock = GetComponent<Clock>();

if (clock.ElapsedTime > numOfShoot * _AttackCooldown) {
Scene *scene = HandleEntity.GetScene();
Expand All @@ -143,17 +143,17 @@ namespace RType {
bullet.AddComponent<ScriptComponent>().Bind("BulletEnnemy");

SpriteRendererComponent &sprite = bullet.AddComponent<SpriteRendererComponent>();
ParentComponent &parent = bullet.AddComponent<ParentComponent>();
IDComponent &ID = GetComponent<IDComponent>();
ParentComponent &parent = bullet.AddComponent<ParentComponent>();
IDComponent &ID = GetComponent<IDComponent>();

parent.Parent = ID.ID;
numOfShoot++;
}
}

void PataPata::SinusoidalMovement(Timestep ts) {
RigidBody2DComponent &body = GetComponent<RigidBody2DComponent>();
Clock &clock = GetComponent<Clock>();
RigidBody2DComponent &body = GetComponent<RigidBody2DComponent>();
Clock &clock = GetComponent<Clock>();

_AttackTimer += ts.GetSeconds();

Expand Down
28 changes: 15 additions & 13 deletions Server/src/Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ namespace Exodia {
void Server::InitScenes() {
CollisionSystem *collisionSystem = new CollisionSystem();

std::vector<Exodia::EntitySystem *> systems = {new AnimationSystem(), new MovingSystem(1.5f), collisionSystem, new ClockSystem()};
std::vector<Exodia::EntitySystem *> systems = {new AnimationSystem(), new MovingSystem(1.5f), collisionSystem,
new ClockSystem()};

RType::EntityEventSubscriber *subscribe = new RType::EntityEventSubscriber(_Network);
RType::TakeDamageSubscriber *takeDamage = new RType::TakeDamageSubscriber();
Expand Down Expand Up @@ -230,20 +231,21 @@ namespace Exodia {
void Server::HandleEvent(std::pair<std::pair<uint32_t, bool>, asio::ip::udp::endpoint> event) {
int32_t player_id = _Network.ConnectionPlace(event.second);

_Scene->ForEach<ScriptComponent, TagComponent>([&](Entity *entity, ComponentHandle<ScriptComponent> script, ComponentHandle<TagComponent> tag) {
ScriptComponent &sc = script.Get();
TagComponent &tc = tag.Get();
_Scene->ForEach<ScriptComponent, TagComponent>(
[&](Entity *entity, ComponentHandle<ScriptComponent> script, ComponentHandle<TagComponent> tag) {
ScriptComponent &sc = script.Get();
TagComponent &tc = tag.Get();

if (tc.Tag == std::string("Player_" + std::to_string(player_id)) && sc.Instance != nullptr) {
if (event.first.second)
sc.Instance->OnKeyPressed(event.first.first);
else
sc.Instance->OnKeyReleased(event.first.first);
}
if (tc.Tag == std::string("Player_" + std::to_string(player_id)) && sc.Instance != nullptr) {
if (event.first.second)
sc.Instance->OnKeyPressed(event.first.first);
else
sc.Instance->OnKeyReleased(event.first.first);
}

if (tc.Tag.rfind("Player_") != std::string::npos && entity->HasComponent<RigidBody2DComponent>())
_Network.SendComponentOf(false, entity, "RigidBody2DComponent");
});
if (tc.Tag.rfind("Player_") != std::string::npos && entity->HasComponent<RigidBody2DComponent>())
_Network.SendComponentOf(false, entity, "RigidBody2DComponent");
});
}

/**
Expand Down

0 comments on commit 4d69cb9

Please sign in to comment.