Skip to content

Commit

Permalink
merge: Merge pull request #45 from G-Epitech/nibbler
Browse files Browse the repository at this point in the history
Nibbler
  • Loading branch information
Yann-Masson authored Apr 7, 2024
2 parents ecce8fd + b49ed31 commit 6bc0278
Show file tree
Hide file tree
Showing 75 changed files with 2,133 additions and 323 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ lib
*.gcno
*.gcda
*.o
*.txt
scores.txt
1 change: 1 addition & 0 deletions assets/nibbler/apple.ascii
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
O
Binary file added assets/nibbler/apple.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/nibbler/death.wav
Binary file not shown.
Binary file added assets/nibbler/down.wav
Binary file not shown.
Binary file added assets/nibbler/eat.wav
Binary file not shown.
Binary file added assets/nibbler/effects.wav
Binary file not shown.
1 change: 1 addition & 0 deletions assets/nibbler/head.ascii
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@@@@
Binary file added assets/nibbler/head.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/nibbler/left.wav
Binary file not shown.
19 changes: 19 additions & 0 deletions assets/nibbler/levels/1.ascii
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
###################
# * * * * #
# ### # ### # ### #
#*# #*# #*# #*#
# ### # # # # ### #
# #*# #*# #
# ##### # # ##### #
#*# * * #*#
# # #####*##### # #
# * * #
# ##### ### ##### #
# * ### * #
# ### # ### # ### #
# # # # * # # # #
#*###*#*###*#*###*#
# # ### # #
#*##### ### #####*#
# #
###################
19 changes: 19 additions & 0 deletions assets/nibbler/levels/2.ascii
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
###################
#* #* # # * #
# # # # # # # # # #
# *# * # * # #
# #### # # ## ## #
# # * # # ## ## ##
#* # # * # #
# #### * #### * # #
# ### ## #### #
# # * * # * #
# ## # ## ## ## ###
#**# # # * # * #
## # # # ## ### #
# *## ## * #
# ##### ## ## # ###
# * * # * # *#
# ##### # # ## ## #
# * * #
###################
Binary file added assets/nibbler/right.wav
Binary file not shown.
3 changes: 3 additions & 0 deletions assets/nibbler/tail.ascii
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
║═
~~~~
╝╚╗╔
Binary file added assets/nibbler/tail.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/nibbler/up.wav
Binary file not shown.
1 change: 1 addition & 0 deletions assets/nibbler/wall.ascii
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#
Binary file added assets/nibbler/wall.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
54 changes: 41 additions & 13 deletions core/src/Core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,43 @@ void Core::_initGame()
if (this->_gameProviders.empty())
throw ArcadeError("No game provider available");
this->_gameProvider = this->_getGameProvider(0);
std::cout << "No game provider selected, using default provider" << std::endl;
std::cerr << "No game provider selected, using default provider" << std::endl;
}
this->_game = this->_gameProvider->createInstance();
this->_sceneStage = RESUME;
try {
this->_game = this->_gameProvider->createInstance();
this->_sceneStage = RESUME;
} catch (std::exception &e) {
std::cerr << e.what() << std::endl;
this->_sceneStage = MENU;
}
}

void Core::_initSecureWindow()
{
IWindow::WindowInitProps windowInitProps {
Vector2u(20, 20),
IWindow::WINDOWED,
60,
"Secured Window",
""
};

this->_handleWindowClose();
if (!this->_graphicsProvider) {
if (this->_graphicsProviders.empty())
throw ArcadeError("No graphic provider available");
this->_graphicsProvider = this->_getGraphicsProvider(0);
std::cerr << "No graphic provider selected, using default provider" << std::endl;
}
this->_window = this->_graphicsProvider->createWindow(windowInitProps);
}

void Core::_initWindow()
{
if (!this->_game)
this->_initGame();
if (!this->_game)
return this->_initSecureWindow();
auto gameManifest = this->_game->getManifest();
IWindow::WindowInitProps windowInitProps {
this->_game->getSize(),
Expand All @@ -79,7 +106,7 @@ void Core::_initWindow()
if (this->_graphicsProviders.empty())
throw ArcadeError("No graphic provider available");
this->_graphicsProvider = this->_getGraphicsProvider(0);
std::cout << "No graphic provider selected, using default provider" << std::endl;
std::cerr << "No graphic provider selected, using default provider" << std::endl;
}
this->_window = this->_graphicsProvider->createWindow(windowInitProps);
this->_sceneStage = PLAY;
Expand Down Expand Up @@ -285,7 +312,7 @@ void Core::_preventWindowEvents(std::vector<events::EventPtr> events)
void Core::_changeGraphicProvider(const unsigned char &index)
{
if (index > this->_graphicsProviders.size() - 1) {
std::cout << "Invalid graphic provider index" << std::endl;
std::cerr << "Invalid graphic provider index" << std::endl;
return;
}
auto newProvider = this->_getGraphicsProvider(index);
Expand All @@ -298,7 +325,7 @@ void Core::_changeGraphicProvider(const unsigned char &index)
void Core::_changeGameProvider(const unsigned char &index)
{
if (index > this->_gameProviders.size() - 1) {
std::cout << "Invalid game provider index" << std::endl;
std::cerr << "Invalid game provider index" << std::endl;
return;
}
auto newProvider = this->_getGameProvider(index);
Expand Down Expand Up @@ -393,6 +420,7 @@ void Core::_handleWindowClose()
this->_stopAllGraphicsSounds();
this->_window->close();
this->_menu.updateScore(this->_game);
this->_sceneStage = MENU;
}
}

Expand Down Expand Up @@ -549,7 +577,7 @@ void Core::run()
return;
this->_initGame();
this->_initWindow();
while (this->_window->isOpen()) {
while (this->_sceneStage != EXIT) {
auto currentTime = std::chrono::high_resolution_clock::now();
auto deltaTime = std::chrono::duration_cast<std::chrono::milliseconds>(currentTime - previousTime);
previousTime = currentTime;
Expand All @@ -559,15 +587,15 @@ void Core::run()
this->_menu.run();
previousTime = std::chrono::high_resolution_clock::now();
}
if (this->_sceneStage == EXIT)
return;
if (this->_sceneStage == NEWGAME)
this->_initGame();
if (this->_sceneStage == RESUME)
this->_initWindow();
this->_game->compute(deltaTime);
this->_gameEntities = this->_game->getEntities();
this->_handleEvents();
this->_renderEntities();
if (this->_sceneStage == PLAY) {
this->_game->compute(deltaTime);
this->_gameEntities = this->_game->getEntities();
this->_handleEvents();
this->_renderEntities();
}
}
}
6 changes: 6 additions & 0 deletions core/src/Core.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ class Core {
*/
void _initWindow();

/**
* @brief Initialize the secure window
*
*/
void _initSecureWindow();

/**
* @brief Initialize the game
*
Expand Down
3 changes: 2 additions & 1 deletion core/src/menu/Menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -692,10 +692,11 @@ void Menu::_writeScore()

void Menu::updateScore(std::shared_ptr<IGame> game)
{
if (!game)
return;
this->_score.game = game->getManifest().name;
this->_score.score = game->getScore();

std::cout << "Player Score: " << this->_score.score << std::endl;
for (auto &score : this->_scores) {
auto playerName = this->_score.player.empty() ? "Guest" : this->_score.player;
auto scoreName = score.player.empty() ? "Guest" : score.player;
Expand Down
1 change: 1 addition & 0 deletions games/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
add_subdirectory(snake)
add_subdirectory(nibbler)
24 changes: 24 additions & 0 deletions games/nibbler/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
project(nibbler)
add_library(${PROJECT_NAME} SHARED
export.cpp
src/NibblerGameProvider.cpp
src/NibblerGame.cpp
src/entities/nibbler/Nibbler.cpp
src/entities/nibbler/Nibbler.hpp
src/entities/nibbler/TailEntity.cpp
src/entities/nibbler/TailEntity.hpp
src/entities/nibbler/HeadEntity.cpp
src/entities/nibbler/HeadEntity.hpp
src/entities/nibbler/components/HeadKeyboardComponent.cpp
src/entities/nibbler/components/HeadKeyboardComponent.hpp
src/entities/wall/WallEntity.cpp
src/entities/wall/WallEntity.hpp
src/entities/background/BackgroundEntity.cpp
src/entities/background/BackgroundEntity.hpp
src/entities/apple/AppleEntity.cpp
src/entities/apple/AppleEntity.hpp
)
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/../common PRIVATE)
target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_LIST_DIR}/src)
target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_LIST_DIR}/../..)
target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_LIST_DIR}/..)
22 changes: 22 additions & 0 deletions games/nibbler/export.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
** EPITECH PROJECT, 2024
** arcade-shared
** File description:
** export
*/

#include "NibblerGameProvider.hpp"
#include "shared/types/Libraries.hpp"

using namespace shared::games;
using namespace shared::types;

extern "C" {
LibraryType SHARED_LIBRARY_TYPE_GETTER_NAME(void) {
return LibraryType::GAME;
}

IGameProvider *SHARED_GAME_PROVIDER_GETTER_NAME(void) {
return new arcade::games::nibbler::NibblerGameProvider();
}
}
Loading

0 comments on commit 6bc0278

Please sign in to comment.