Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/ecs/bullet systems #43

Merged
merged 38 commits into from
Oct 13, 2022
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
4e225c1
feat: add bullet and health components
aurelenc Oct 4, 2022
b74c13a
rtor: bullet component is now damage
aurelenc Oct 4, 2022
7c23e49
feat add shootable component
aurelenc Oct 4, 2022
bf1b2cd
feat: add ability to shoot bullets
aurelenc Oct 4, 2022
d339b9a
fix: code format
aurelenc Oct 4, 2022
66e8c16
Merge branch 'feat/ecs/engine' into feat/ecs/bullet-systems
aurelenc Oct 5, 2022
84500e6
rtor: replace vs headers by epitech headers
aurelenc Oct 5, 2022
c03439e
fix: handlesfmlkeys component bad merge
aurelenc Oct 5, 2022
c7df0b5
feat: add cross platform asset loading
aurelenc Oct 5, 2022
ed9e5fd
Merge branch 'feat/ecs/detach-sfml' into feat/ecs/bullet-systems
aurelenc Oct 7, 2022
55323d0
fix: wrong name of file in include
aurelenc Oct 7, 2022
79e0ed7
docs: update Engine documentation
Bootoyka Oct 9, 2022
8ac02ce
docs: update HandleSFMLEvents documentation
Bootoyka Oct 9, 2022
6eaad1c
docs: update HandleSFMLEvents documentation & smooth for loop
Bootoyka Oct 9, 2022
a2f9e39
docs: update ManageClientEvents documentation and remove heavy if sta…
Bootoyka Oct 9, 2022
0f4db95
misc: airing out the code
Bootoyka Oct 9, 2022
1f41b8e
docs: add Shootable documentation
Bootoyka Oct 9, 2022
dd389f9
feat: add inline to getWindow
Bootoyka Oct 9, 2022
c3eccfd
fix: server compil
aurelenc Oct 10, 2022
481498d
Merge branch 'feat/ecs/bullet-systems' of github.com:TEAM-AAAAAAAAAAA…
aurelenc Oct 10, 2022
8cd0668
fix: weird compil bug with shootable component
aurelenc Oct 10, 2022
c8a7a89
fix: movement system using client component on server
aurelenc Oct 10, 2022
d724ae5
Merge branch 'main' into feat/ecs/bullet-systems
aurelenc Oct 10, 2022
529cc03
rtor: format
aurelenc Oct 10, 2022
bf2a281
feat: add chrono usings to Constant.hpp
aurelenc Oct 10, 2022
71dd75c
rtor: rename class Damage to Projectile
aurelenc Oct 10, 2022
070f8f2
feat: add class Weapon
aurelenc Oct 10, 2022
5f34df1
feat: allow keeping the shoot button pressed to keep shooting
aurelenc Oct 10, 2022
90eb4b1
feat: implement weapon while shooting
aurelenc Oct 10, 2022
1c70de6
fix: init sparse array pos
aurelenc Oct 10, 2022
a97570c
fix: fix some bullets not moving
aurelenc Oct 10, 2022
5c3678d
Merge branch 'feat/ecs/detach-sfml' into feat/ecs/bullet-systems
aurelenc Oct 10, 2022
dde71cc
Merge branch 'feat/ecs/detach-sfml' into feat/ecs/bullet-systems
aurelenc Oct 10, 2022
ac9d0db
rtor: remove garbage
aurelenc Oct 10, 2022
16c6144
Merge branch 'feat/ecs/detach-sfml' into feat/ecs/bullet-systems
aurelenc Oct 10, 2022
d2b7f35
feat: add game map size
aurelenc Oct 10, 2022
daae1f7
Merge branch 'main' into feat/ecs/bullet-systems
aurelenc Oct 11, 2022
f9f6c34
Merge branch 'main' into feat/ecs/bullet-systems
aurelenc Oct 12, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/demo/Demo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include "components/EnemyAI.hpp"
#include "systems/Draw.hpp"
#include "systems/HandleSFMLEvents.hpp"
#include "systems/HandleSFMLMovements.hpp"
#include "systems/HandleSFMLKeys.hpp"
#include "systems/ManageClientEvents.hpp"
#endif

Expand All @@ -37,19 +37,19 @@ ecs::World getGameWorld(ecs::Engine &engine)
world.addSystem(ecs::systems::movement);

#ifdef CLIENT_COMPILATION_MODE
std::filesystem::path playerPath = ecs::crossPlatformPath("src", "demo", "assets", "textures", "players.gif");
world.registry.addComponent<ecs::component::Controllable>(
player, {sf::Keyboard::Z, sf::Keyboard::Q, sf::Keyboard::S, sf::Keyboard::D});
world.registry.addComponent<ecs::component::Drawable>(
player, {"src/demo/assets/textures/players.gif", {1, 1, 32, 16}});
world.registry.addComponent<ecs::component::Drawable>(player, {playerPath, {1, 1, 32, 16}});
world.registry.addComponent<ecs::component::Shootable>(player, {sf::Keyboard::Space});

ecs::Entity enemy = world.registry.spawn_entity();
world.registry.addComponent<ecs::component::Position>(enemy, {500, 500});
world.registry.addComponent<ecs::component::Size>(enemy, {5, 5});
world.registry.addComponent<ecs::component::EnemyAI>(enemy, {});
world.registry.addComponent<ecs::component::Drawable>(
enemy, {"src/demo/assets/textures/players.gif", {1, 18, 32, 16}});
world.registry.addComponent<ecs::component::Drawable>(enemy, {playerPath, {1, 18, 32, 16}});
world.addSystem(ecs::systems::handleSFMLEvents);
world.addSystem(ecs::systems::handleSFMLMovements);
world.addSystem(ecs::systems::handleSFMLKeys);

world.addSystem(ecs::systems::manageClientEvents);
world.addSystem(ecs::systems::draw);
Expand Down
20 changes: 20 additions & 0 deletions src/ecs/AssetManager.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
** EPITECH PROJECT, 2022
** RTYPE
** File description:
** AssetManager
*/

#pragma once

#include <filesystem>

namespace ecs
{
inline std::filesystem::path crossPlatformPath(std::filesystem::path path) { return path; }
template <class... Args>
std::filesystem::path crossPlatformPath(std::filesystem::path path, std::string_view next, Args... args)
{
return crossPlatformPath(path.append(next), args...);
}
} // namespace ecs
1 change: 1 addition & 0 deletions src/ecs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ add_subdirectory(utils)
set(ECS_SRC
${COMPONENTS_SRC}
${SYSTEMS_SRC}
${SRCROOT}/AssetManager.hpp
${SRCROOT}/Constant.hpp
${SRCROOT}/Engine.hpp
${SRCROOT}/Entity.hpp
Expand Down
30 changes: 20 additions & 10 deletions src/ecs/Engine.hpp
Original file line number Diff line number Diff line change
@@ -1,21 +1,31 @@
/*
* File: Engine.hpp
* Project: ecs
* File Created: Tuesday, 4th October 2022 6:33:43 pm
* Author: Aurèle Nicolas ([email protected])
* -----
* Last Modified: Wednesday, 5th October 2022 2:05:52 pm
* Modified By: Aurèle Nicolas ([email protected]>)
* -----
* Copyright 2022 - 2022 Your Company, Your Company
*/
** EPITECH PROJECT, 2022
** RTYPE
** File description:
** Engine
*/

#pragma once

#include <filesystem>
#include <memory>
#include "AssetManager.hpp"
#include "Engine.hpp"
#include "Registry.hpp"
#include "World.hpp"
#include "components/Controllable.hpp"
#include "components/Drawable.hpp"
#include "components/EnemyAI.hpp"
#include "components/Position.hpp"
#include "components/Shootable.hpp"
#include "components/Size.hpp"
#include "components/Velocity.hpp"
#include "systems/Draw.hpp"
#include "systems/HandleSFMLEvents.hpp"
#include "systems/HandleSFMLKeys.hpp"
#include "systems/ManageClientEvents.hpp"
#include "systems/Movement.hpp"
#include "systems/PositionLogger.hpp"

namespace ecs
{
Expand Down
15 changes: 5 additions & 10 deletions src/ecs/Event.hpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
/*
* File: Event.hpp
* Project: ecs
* File Created: Tuesday, 4th October 2022 7:31:30 pm
* Author: Aurèle Nicolas ([email protected])
* -----
* Last Modified: Wednesday, 5th October 2022 2:01:45 pm
* Modified By: Aurèle Nicolas ([email protected]>)
* -----
* Copyright 2022 - 2022 Your Company, Your Company
*/
** EPITECH PROJECT, 2022
** RTYPE
** File description:
** Event
*/

#pragma once

Expand Down
15 changes: 5 additions & 10 deletions src/ecs/World.hpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
/*
* File: World.hpp
* Project: ecs
* File Created: Tuesday, 4th October 2022 6:33:43 pm
* Author: Aurèle Nicolas ([email protected])
* -----
* Last Modified: Wednesday, 5th October 2022 1:57:31 pm
* Modified By: Aurèle Nicolas ([email protected]>)
* -----
* Copyright 2022 - 2022 Your Company, Your Company
*/
** EPITECH PROJECT, 2022
** RTYPE
** File description:
** World
*/

#pragma once

Expand Down
3 changes: 3 additions & 0 deletions src/ecs/components/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@ set(SRCROOT ${PROJECT_SOURCE_DIR}/src/ecs/components)

set(COMPONENTS_SRC
${SRCROOT}/Controllable.hpp
${SRCROOT}/Damage.hpp
${SRCROOT}/Drawable.hpp
${SRCROOT}/EnemyAI.hpp
${SRCROOT}/Health.hpp
${SRCROOT}/Position.hpp
${SRCROOT}/Shootable.hpp
${SRCROOT}/Size.hpp
${SRCROOT}/Velocity.hpp
PARENT_SCOPE
Expand Down
15 changes: 5 additions & 10 deletions src/ecs/components/Controllable.hpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
/*
* File: Controllable.hpp
* Project: components
* File Created: Monday, 3rd October 2022 6:17:46 pm
* Author: Aurèle Nicolas ([email protected])
* -----
* Last Modified: Tuesday, 4th October 2022 7:26:15 pm
* Modified By: Aurèle Nicolas ([email protected]>)
* -----
* Copyright 2022 - 2022 Your Company, Your Company
*/
** EPITECH PROJECT, 2022
** RTYPE
** File description:
** Controllable
*/

#pragma once

Expand Down
15 changes: 15 additions & 0 deletions src/ecs/components/Damage.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
** EPITECH PROJECT, 2022
** RTYPE
** File description:
** Damage
*/

#pragma once

namespace ecs::component
{
struct Damage {
int damage;
};
} // namespace ecs::component
15 changes: 5 additions & 10 deletions src/ecs/components/Direction.hpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
/*
* File: Direction.hpp
* Project: components
* File Created: Tuesday, 4th October 2022 7:10:05 pm
* Author: Aurèle Nicolas ([email protected])
* -----
* Last Modified: Tuesday, 4th October 2022 7:22:19 pm
* Modified By: Aurèle Nicolas ([email protected]>)
* -----
* Copyright 2022 - 2022 Your Company, Your Company
*/
** EPITECH PROJECT, 2022
** RTYPE
** File description:
** Direction
*/

#pragma once

Expand Down
15 changes: 5 additions & 10 deletions src/ecs/components/Drawable.hpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
/*
* File: Drawable.hpp
* Project: components
* File Created: Monday, 3rd October 2022 6:32:42 pm
* Author: Aurèle Nicolas ([email protected])
* -----
* Last Modified: Wednesday, 5th October 2022 2:09:12 pm
* Modified By: Aurèle Nicolas ([email protected]>)
* -----
* Copyright 2022 - 2022 Your Company, Your Company
*/
** EPITECH PROJECT, 2022
** RTYPE
** File description:
** Drawable
*/

#pragma once

Expand Down
15 changes: 5 additions & 10 deletions src/ecs/components/EnemyAI.hpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
/*
* File: EnemyAI.hpp
* Project: components
* File Created: Tuesday, 4th October 2022 6:59:11 pm
* Author: Aurèle Nicolas ([email protected])
* -----
* Last Modified: Tuesday, 4th October 2022 7:26:25 pm
* Modified By: Aurèle Nicolas ([email protected]>)
* -----
* Copyright 2022 - 2022 Your Company, Your Company
*/
** EPITECH PROJECT, 2022
** RTYPE
** File description:
** EnemyAI
*/

#pragma once

Expand Down
15 changes: 15 additions & 0 deletions src/ecs/components/Health.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
** EPITECH PROJECT, 2022
** RTYPE
** File description:
** Health
*/

#pragma once

namespace ecs::component
{
struct Health {
int health;
};
} // namespace ecs::component
15 changes: 5 additions & 10 deletions src/ecs/components/Position.hpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
/*
* File: Position.hpp
* Project: components
* File Created: Monday, 3rd October 2022 3:37:48 pm
* Author: Aurèle Nicolas ([email protected])
* -----
* Last Modified: Tuesday, 4th October 2022 7:26:30 pm
* Modified By: Aurèle Nicolas ([email protected]>)
* -----
* Copyright 2022 - 2022 Your Company, Your Company
*/
** EPITECH PROJECT, 2022
** RTYPE
** File description:
** Position
*/

#pragma once

Expand Down
24 changes: 24 additions & 0 deletions src/ecs/components/Shootable.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
** EPITECH PROJECT, 2022
** RTYPE
** File description:
** Shootable
*/

#pragma once

#include "SFML/Window/Keyboard.hpp"

namespace ecs::component
{
struct Shootable {
Shootable(sf::Keyboard::Key shoot, sf::Keyboard::Key shootSecondary = sf::Keyboard::Key::Unknown)
: Shoot(shoot), ShootSecondary(shootSecondary)
{
}

sf::Keyboard::Key Shoot;

sf::Keyboard::Key ShootSecondary;
};
} // namespace ecs::component
2 changes: 1 addition & 1 deletion src/ecs/systems/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ set(SRCROOT ${PROJECT_SOURCE_DIR}/src/ecs/systems)
set(SYSTEMS_SRC
${SRCROOT}/Draw.hpp
${SRCROOT}/HandleSFMLEvents.hpp
${SRCROOT}/HandleSFMLMovements.hpp
${SRCROOT}/HandleSFMLKeys.hpp
${SRCROOT}/ManageClientEvents.hpp
${SRCROOT}/Movement.hpp
${SRCROOT}/PositionLogger.hpp
Expand Down
15 changes: 5 additions & 10 deletions src/ecs/systems/Draw.hpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
/*
* File: Draw.hpp
* Project: systems
* File Created: Tuesday, 4th October 2022 6:33:43 pm
* Author: Aurèle Nicolas ([email protected])
* -----
* Last Modified: Wednesday, 5th October 2022 2:07:38 pm
* Modified By: Aurèle Nicolas ([email protected]>)
* -----
* Copyright 2022 - 2022 Your Company, Your Company
*/
** EPITECH PROJECT, 2022
** RTYPE
** File description:
** Draw
*/

#pragma once

Expand Down
28 changes: 16 additions & 12 deletions src/ecs/systems/HandleSFMLEvents.hpp
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
/*
* File: HandleSFMLEvents.hpp
* Project: systems
* File Created: Tuesday, 4th October 2022 7:34:35 pm
* Author: Aurèle Nicolas ([email protected])
* -----
* Last Modified: Wednesday, 5th October 2022 2:07:14 pm
* Modified By: Aurèle Nicolas ([email protected]>)
* -----
* Copyright 2022 - 2022 Your Company, Your Company
*/
** EPITECH PROJECT, 2022
** RTYPE
** File description:
** HandleSFMLEvents
*/

#pragma once

#include <functional>
#include "World.hpp"
#include "components/Controllable.hpp"

namespace ecs::systems
{
Expand All @@ -30,7 +24,17 @@ namespace ecs::systems
while (world.getWindow().pollEvent(event)) {
switch (event.type) {
case sf::Event::Closed: world.getWindow().close(); break;
case sf::Event::KeyPressed: break;
case sf::Event::KeyPressed: {
auto const &shootables = world.registry.getComponents<component::Shootable>();

for (size_t i = 0; i < shootables.size(); ++i) {
auto const &shoot = shootables[i];
if (shoot) {
if (event.key.code == shoot.value().Shoot || event.key.code == shoot.value().ShootSecondary)
world.pushEvent(ecs::Event(ecs::Event::EventType::Shoot));
}
}
} break;
default: break;
}
}
Expand Down
Loading