-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
merge: pull request #25 from G-Epitech/rc-snake-game
feat(games): add snake game
- Loading branch information
Showing
56 changed files
with
1,718 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
O |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
@@@@ |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
║═ | ||
~~~~ | ||
╝╚╗╔ |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
target_sources(${PROJECT_NAME} PUBLIC | ||
game/AGame.cpp | ||
game/AGame.hpp | ||
entity/AEntity.cpp | ||
entity/AEntity.hpp | ||
components/AComponent.cpp | ||
components/AComponent.hpp | ||
components/PositionableComponent.cpp | ||
components/PositionableComponent.hpp | ||
components/ADisplayableComponent.cpp | ||
components/ADisplayableComponent.hpp | ||
components/CollidableComponent.hpp | ||
components/CollidableComponent.cpp | ||
components/TextureComponent.hpp | ||
components/TextureComponent.cpp | ||
) | ||
target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_LIST_DIR}/../..) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
** EPITECH PROJECT, 2024 | ||
** AComponent.cpp | ||
** File description: | ||
** AComponent class | ||
*/ | ||
|
||
#include <iostream> | ||
#include "AComponent.hpp" | ||
|
||
using namespace arcade::games::common::components; | ||
|
||
AComponent::AComponent(shared::games::components::ComponentType type, shared::games::entity::IEntity &entity) : _parent( | ||
entity) { | ||
this->_type = type; | ||
} | ||
|
||
const shared::games::components::ComponentType AComponent::getType() const noexcept { | ||
return this->_type; | ||
} | ||
|
||
const shared::games::entity::IEntity &AComponent::getEntity() noexcept { | ||
return this->_parent; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
** EPITECH PROJECT, 2024 | ||
** AComponent.hpp | ||
** File description: | ||
** AComponent class | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include "shared/games/components/IComponent.hpp" | ||
|
||
namespace arcade::games::common::components { | ||
class AComponent; | ||
} | ||
|
||
class arcade::games::common::components::AComponent : public virtual shared::games::components::IComponent { | ||
public: | ||
~AComponent() override = default; | ||
|
||
/** | ||
* @brief Get the type of the component | ||
* | ||
* @return Type of the component | ||
*/ | ||
const shared::games::components::ComponentType getType() const noexcept override; | ||
|
||
/** | ||
* @brief Get the parent entity of the component | ||
* | ||
* @return Entity of the component | ||
*/ | ||
const shared::games::entity::IEntity &getEntity() noexcept override; | ||
|
||
protected: | ||
/** | ||
* @brief Create a component | ||
* | ||
* @param entity Entity parent of the component | ||
*/ | ||
explicit AComponent(shared::games::components::ComponentType type, shared::games::entity::IEntity &entity); | ||
|
||
shared::games::entity::IEntity &_parent; | ||
shared::games::components::ComponentType _type; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
** EPITECH PROJECT, 2024 | ||
** ADisplayableComponent.cpp | ||
** File description: | ||
** ADisplayableComponent class | ||
*/ | ||
|
||
#include "ADisplayableComponent.hpp" | ||
|
||
using namespace arcade::games::common::components; | ||
using namespace shared::games; | ||
|
||
ADisplayableComponent::ADisplayableComponent(entity::IEntity &entity, Vector2u size, unsigned int zindex) | ||
: PositionableComponent(entity), | ||
_size(size), _zindex(zindex) { | ||
} | ||
|
||
Vector2u &ADisplayableComponent::getSize() noexcept { | ||
return this->_size; | ||
} | ||
|
||
unsigned int &ADisplayableComponent::getZIndex() noexcept { | ||
return this->_zindex; | ||
} | ||
|
||
void ADisplayableComponent::onMousePress(std::shared_ptr<IGame> ctx) {} | ||
|
||
void ADisplayableComponent::onMouseHover(std::shared_ptr<IGame> ctx) {} | ||
|
||
void ADisplayableComponent::onMouseRelease(std::shared_ptr<IGame> ctx) {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
** EPITECH PROJECT, 2024 | ||
** ADisplayableComponent.hpp | ||
** File description: | ||
** ADisplayableComponent class | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include "shared/games/components/IDisplayableComponent.hpp" | ||
#include "PositionableComponent.hpp" | ||
|
||
namespace arcade::games::common::components { | ||
class ADisplayableComponent; | ||
} | ||
|
||
class arcade::games::common::components::ADisplayableComponent : public virtual shared::games::components::IDisplayableComponent, public PositionableComponent { | ||
public: | ||
~ADisplayableComponent() override = default; | ||
|
||
/** | ||
* @brief Get size of the entity (tiles) | ||
* | ||
*/ | ||
Vector2u &getSize() noexcept override; | ||
|
||
/** | ||
* @brief Get Z index that is usefull for display prioroty | ||
* | ||
*/ | ||
unsigned int &getZIndex() noexcept override; | ||
|
||
/** | ||
* @brief On click event handler for the entity | ||
* @param ctx Context of the game | ||
*/ | ||
void onMousePress(std::shared_ptr<shared::games::IGame> ctx) override; | ||
|
||
/** | ||
* @brief On release event handler for the entity | ||
* @param ctx Context of the game | ||
*/ | ||
void onMouseRelease(std::shared_ptr<shared::games::IGame> ctx) override; | ||
|
||
/** | ||
* @brief On hover event handler for the entity | ||
* @param ctx Context of the game | ||
*/ | ||
void onMouseHover(std::shared_ptr<shared::games::IGame> ctx) override; | ||
|
||
protected: | ||
/** | ||
* Create a displayable component | ||
* @param entity | ||
* @param size | ||
* @param zindex | ||
*/ | ||
explicit ADisplayableComponent(shared::games::entity::IEntity &entity, Vector2u size, unsigned int zindex); | ||
|
||
Vector2u _size; | ||
unsigned int _zindex; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* | ||
** EPITECH PROJECT, 2024 | ||
** CollidableComponent.cpp | ||
** File description: | ||
** CollidableComponent class | ||
*/ | ||
|
||
#include "CollidableComponent.hpp" | ||
#include <iostream> | ||
|
||
using namespace arcade::games::common::components; | ||
|
||
CollidableComponent::CollidableComponent(shared::games::entity::IEntity &entity, onCollideFunction function) : PositionableComponent(entity), _collideFunction(function) { | ||
this->_type = shared::games::components::COLLIDABLE; | ||
} | ||
|
||
void CollidableComponent::onCollide(std::shared_ptr<shared::games::IGame> ctx, | ||
std::shared_ptr<ICollidableComponent> target) { | ||
if (this->_collideFunction) | ||
this->_collideFunction(ctx, target); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
** EPITECH PROJECT, 2024 | ||
** CollidableComponent.hpp | ||
** File description: | ||
** CollidableComponent class | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include "shared/games/components/ICollidableComponent.hpp" | ||
#include "PositionableComponent.hpp" | ||
|
||
namespace arcade::games::common::components { | ||
class CollidableComponent; | ||
} | ||
|
||
class arcade::games::common::components::CollidableComponent : public virtual shared::games::components::ICollidableComponent, public PositionableComponent { | ||
public: | ||
typedef void (*onCollideFunction)(std::shared_ptr<shared::games::IGame> ctx, std::shared_ptr<ICollidableComponent> target); | ||
|
||
~CollidableComponent() override = default; | ||
|
||
/** | ||
* @brief Create a position component | ||
* @param entity | ||
*/ | ||
explicit CollidableComponent(shared::games::entity::IEntity &entity, onCollideFunction function); | ||
|
||
/** | ||
* @brief On collide event handler for the component | ||
* @param ctx Context of the game | ||
* @param target Target entity | ||
*/ | ||
void onCollide(std::shared_ptr<shared::games::IGame> ctx, std::shared_ptr<ICollidableComponent> target) override; | ||
|
||
protected: | ||
onCollideFunction _collideFunction; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
** EPITECH PROJECT, 2024 | ||
** PositionableComponent.cpp | ||
** File description: | ||
** PositionableComponent class | ||
*/ | ||
|
||
#include "PositionableComponent.hpp" | ||
|
||
using namespace arcade::games::common::components; | ||
using namespace shared::games::components; | ||
|
||
PositionableComponent::PositionableComponent(shared::games::entity::IEntity &entity) : AComponent(POSITIONABLE, entity), | ||
_position(0, 0), _size(1, 1) { | ||
} | ||
|
||
shared::types::Vector2i &PositionableComponent::getPosition() noexcept { | ||
return this->_position; | ||
} | ||
|
||
shared::types::Vector2u &PositionableComponent::getSize() noexcept { | ||
return this->_size; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
** EPITECH PROJECT, 2024 | ||
** PositionableComponent.hpp | ||
** File description: | ||
** PositionableComponent class | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include "shared/games/components/IPositionableComponent.hpp" | ||
#include "AComponent.hpp" | ||
|
||
namespace arcade::games::common::components { | ||
class PositionableComponent; | ||
} | ||
|
||
class arcade::games::common::components::PositionableComponent | ||
: public AComponent, public virtual shared::games::components::IPositionableComponent { | ||
public: | ||
~PositionableComponent() override = default; | ||
|
||
/** | ||
* @brief Create a position component | ||
* @param entity | ||
*/ | ||
explicit PositionableComponent(shared::games::entity::IEntity &entity); | ||
|
||
/** | ||
* @brief Get position of the entity (tiles) | ||
* | ||
*/ | ||
shared::types::Vector2i &getPosition() noexcept override; | ||
|
||
/** | ||
* @brief Get size of the entity (tiles) | ||
* | ||
*/ | ||
shared::types::Vector2u &getSize() noexcept override; | ||
|
||
protected: | ||
shared::types::Vector2i _position; | ||
shared::types::Vector2u _size; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* | ||
** EPITECH PROJECT, 2024 | ||
** TextureComponent.cpp | ||
** File description: | ||
** TextureComponent class | ||
*/ | ||
|
||
#include "TextureComponent.hpp" | ||
|
||
using namespace arcade::games::common::components; | ||
|
||
TextureComponent::TextureComponent(shared::games::entity::IEntity &entity, | ||
Vector2u size, unsigned int zindex, | ||
shared::games::components::TextureProps &props) | ||
: ADisplayableComponent(entity, size, zindex), | ||
_textureProps(props) { | ||
this->_type = shared::games::components::TEXTURE; | ||
} | ||
|
||
shared::games::components::TextureProps &TextureComponent::getTextureProps() noexcept { | ||
return this->_textureProps; | ||
} |
Oops, something went wrong.