Skip to content

Commit

Permalink
ADD - Initial work on AssetSelector
Browse files Browse the repository at this point in the history
  • Loading branch information
deadbaed committed Jun 14, 2020
1 parent 743e155 commit 5eb0da2
Show file tree
Hide file tree
Showing 37 changed files with 275 additions and 156 deletions.
3 changes: 2 additions & 1 deletion Ai/AI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

#include "AI.hpp"
#include "AssetSelector.hpp"

AI::AI(const std::shared_ptr<IrrlichtController> &ctrl, const std::string name): GameObject(ctrl, irr::core::vector3df(5, 5, 5), name)
{
Expand All @@ -22,7 +23,7 @@ AI::AI(const std::shared_ptr<IrrlichtController> &ctrl, const std::string name):

void AI::Init()
{
_node = _ctrl->_scene_mgr->addAnimatedMeshSceneNode(_ctrl->_scene_mgr->getMesh(WHITE_PATH));
_node = _ctrl->_scene_mgr->addAnimatedMeshSceneNode(_ctrl->_scene_mgr->getMesh(AssetSelector(WHITE_PATH).c_str()));

if (_node) {
_node->setMaterialFlag(irr::video::EMF_LIGHTING, false);
Expand Down
8 changes: 4 additions & 4 deletions Ai/AI.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@
#define DEAD_END 250

/* Path for models */
#define WHITE_PATH "../assets/players/white.b3d"
#define BLUE_PATH "../assets/players/blue.b3d"
#define GREEN_PATH "../assets/players/green.b3d"
#define BLACK_PATH "../assets/players/black.b3d"
#define WHITE_PATH "players/white.b3d"
#define BLUE_PATH "players/blue.b3d"
#define GREEN_PATH "players/green.b3d"
#define BLACK_PATH "players/black.b3d"

/* Key configuration */
#define LEFT_KEY "ZQSDE"
Expand Down
1 change: 1 addition & 0 deletions Ai/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
# define the external libraries to use
target_link_libraries(${PROJECT_NAME} game_object)
target_link_libraries(${PROJECT_NAME} player)
target_link_libraries(${PROJECT_NAME} asset_selector)

4 changes: 4 additions & 0 deletions Application/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "SelectSkin.hpp"
#include "SelectSkins.hpp"
#include "EndScene.hpp"
#include "AssetSelector.hpp"

/* Win32: Remove the console application */
//#ifdef _IRR_WINDOWS_
Expand All @@ -26,6 +27,9 @@
//#endif

int main(void) {

std::cout << AssetSelector("test/folder/file.png") << std::endl;

std::shared_ptr<IrrlichtController> c = std::make_shared<IrrlichtController>();
c->Init(irr::video::E_DRIVER_TYPE::EDT_OPENGL, WIDTH, HEIGHT);
c->_device->setWindowCaption(L"Indie Studio");
Expand Down
40 changes: 40 additions & 0 deletions AssetSelector/AssetSelector.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
** EPITECH PROJECT, 2020
** bomberman
** File description:
** Created by phil on 6/14/20
*/

#include <iostream>
#include "AssetSelector.hpp"

fs::path AssetSelector(const std::string &asset) {
fs::path AssetPath;

#if defined(ASSET_SELECTOR_RELEASE) && defined(__linux__)
if (fs::current_path() == std::getenv("HOME"))
AssetPath = "/usr/share/IndieStudio/";
else
std::cerr << "not in installed mode (with package)" << std::endl;
#endif

#if defined(ASSET_SELECTOR_RELEASE) && defined(_WIN32)
std::cout << "win32 implementation will go here" << std::endl;
#endif

if (AssetPath.empty()) {
AssetPath = fs::current_path();
std::cout << "current path: " << AssetPath << std::endl;
fs::path tmp = AssetPath;
tmp /= "assets";
if (!fs::exists(tmp)) {
std::cout << tmp << "does not exist" << std::endl;
AssetPath = AssetPath.parent_path();
}
}

std::cout << "current path: " << AssetPath << std::endl;
AssetPath /= asset;

return AssetPath;
}
18 changes: 18 additions & 0 deletions AssetSelector/AssetSelector.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
** EPITECH PROJECT, 2020
** bomberman
** File description:
** Created by phil on 6/14/20
*/

#ifndef BOMBERMAN_ASSETSELECTOR_HPP
#define BOMBERMAN_ASSETSELECTOR_HPP

#include <filesystem>
#include <string>

namespace fs = std::filesystem;

fs::path AssetSelector(const std::string &asset);

#endif //BOMBERMAN_ASSETSELECTOR_HPP
32 changes: 32 additions & 0 deletions AssetSelector/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
cmake_minimum_required(VERSION 3.11)

# project name
project(asset_selector)

# c++ standard
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED on)

# define macros to use in code depending on build type
IF (CMAKE_BUILD_TYPE STREQUAL Debug)
add_definitions(-DASSET_SELECTOR_DEBUG)
ENDIF (CMAKE_BUILD_TYPE STREQUAL Debug)

IF (CMAKE_BUILD_TYPE STREQUAL Release)
add_definitions(-DASSET_SELECTOR_RELEASE)
ENDIF (CMAKE_BUILD_TYPE STREQUAL Release)

# define sources
set(SRCS
AssetSelector.cpp
AssetSelector.hpp)

# define the binary output
add_library(${PROJECT_NAME} ${SRCS})

# expose the headers
target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})

# define the external libraries to use
target_link_libraries(${PROJECT_NAME} exception)

2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ add_subdirectory(Settings)
add_subdirectory(Storage)
add_subdirectory(Exception)
add_subdirectory(Ai)
add_subdirectory(AssetSelector)

# define sources to use
set(SRCS Application/main.cpp CPack/win32.rc)
Expand All @@ -62,6 +63,7 @@ target_link_libraries(${PROJECT_NAME} settings)
target_link_libraries(${PROJECT_NAME} player)
target_link_libraries(${PROJECT_NAME} storage)
target_link_libraries(${PROJECT_NAME} ai)
target_link_libraries(${PROJECT_NAME} asset_selector)

# define the external libraries to use
target_link_libraries(${PROJECT_NAME} ${Irrlicht_LIBRARIES})
Expand Down
1 change: 1 addition & 0 deletions GameScene/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ target_link_libraries(${PROJECT_NAME} game_object)
target_link_libraries(${PROJECT_NAME} player)
target_link_libraries(${PROJECT_NAME} map_generator)
target_link_libraries(${PROJECT_NAME} ai)
target_link_libraries(${PROJECT_NAME} asset_selector)
11 changes: 6 additions & 5 deletions GameScene/GameScene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "GameScene.hpp"
#include "Player.hpp"
#include "MapGenerator.hpp"
#include "AssetSelector.hpp"
#include <iostream>

GameScene::GameScene(const std::shared_ptr<IrrlichtController> &ctrl, const std::string name) : AScene(ctrl, name)
Expand Down Expand Up @@ -45,10 +46,10 @@ void GameScene::Init(void)
p2->SetPosition(irr::core::vector3df(20, 0, 0));
AddGameObject(p);
AddGameObject(p2);
this->_ctrl->_music->Play("../assets/audio/music_game.ogg");
this->_ctrl->_music->Play(AssetSelector(MUSIC_GAME));
std::shared_ptr<mapGenerator> map = std::make_shared<mapGenerator>(vector3df(0,0,0), 6, 11, 11);
map->generate(_ctrl, _obj_list, "../assets/floor.obj", 100);
map->generateWall(_ctrl, _obj_list, "../assets/wall_1.obj");
map->generateBorder(_ctrl, _obj_list, "../assets/wall_1.obj");
map->generateBlock(_ctrl, _obj_list, "../assets/wall_2.obj", 30);
map->generate(_ctrl, _obj_list, AssetSelector(FLOOR_ASSET), 100);
map->generateWall(_ctrl, _obj_list, AssetSelector(WALL1_ASSET));
map->generateBorder(_ctrl, _obj_list, AssetSelector(WALL1_ASSET));
map->generateBlock(_ctrl, _obj_list, AssetSelector(WALL2_ASSET), 30);
}
5 changes: 5 additions & 0 deletions GameScene/GameScene.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@

#include "AScene.hpp"

#define MUSIC_GAME "audio/music_game.ogg"
#define FLOOR_ASSET "floor.obj"
#define WALL1_ASSET "wall_1.obj"
#define WALL2_ASSET "wall_2.obj"

class GameScene : public AScene {
public:
GameScene(const std::shared_ptr<IrrlichtController> &ctrl, const std::string name);
Expand Down
9 changes: 5 additions & 4 deletions Menu/ChoosePlayers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,18 @@
//

#include "ChoosePlayers.hpp"
#include "AssetSelector.hpp"

ChoosePlayers::ChoosePlayers(const std::shared_ptr<IrrlichtController> &ctrl, const std::string name) : AScene(ctrl, name)
{
}

void ChoosePlayers::Init(void)
{
this->_buttonOnePlayer = std::make_unique<Button>(this->_ctrl->_device, vector2d<int>(640, HEIGHT - 100), vector2d<int>(0, 100), GUI_ID_ONE_PLAYER_BUTTON, ONE_PLAYER_GREY_C, ONE_PLAYER_C);
this->_buttonTwoPlayers = std::make_unique<Button>(this->_ctrl->_device, vector2d<int>(640, HEIGHT - 100), vector2d<int>(640, 100), GUI_ID_TWO_PLAYERS_BUTTON, TWO_PLAYERS_GREY_C, TWO_PLAYERS_C);
this->_buttonBack = std::make_unique<Button>(this->_ctrl->_device, vector2d<int>(1280, 100), vector2d<int>(0, 0), GUI_ID_BACK_BUTTON, BUTTON_BACK_GREY_C, BUTTON_BACK_C);
this->_buttonSound = std::make_unique<Sound>(this->_ctrl->_context, BUTTON_SOUND_C);
this->_buttonOnePlayer = std::make_unique<Button>(this->_ctrl->_device, vector2d<int>(640, HEIGHT - 100), vector2d<int>(0, 100), GUI_ID_ONE_PLAYER_BUTTON, AssetSelector(ONE_PLAYER_GREY_C), AssetSelector(ONE_PLAYER_C));
this->_buttonTwoPlayers = std::make_unique<Button>(this->_ctrl->_device, vector2d<int>(640, HEIGHT - 100), vector2d<int>(640, 100), GUI_ID_TWO_PLAYERS_BUTTON, AssetSelector(TWO_PLAYERS_GREY_C), AssetSelector(TWO_PLAYERS_C));
this->_buttonBack = std::make_unique<Button>(this->_ctrl->_device, vector2d<int>(1280, 100), vector2d<int>(0, 0), GUI_ID_BACK_BUTTON, AssetSelector(BUTTON_BACK_GREY_C), AssetSelector(BUTTON_BACK_C));
this->_buttonSound = std::make_unique<Sound>(this->_ctrl->_context, AssetSelector(BUTTON_SOUND_C));
}

void ChoosePlayers::Update(void)
Expand Down
14 changes: 7 additions & 7 deletions Menu/ChoosePlayers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
#include "GameScene.hpp"
#include "Sound.hpp"

#define ONE_PLAYER_C "../assets/menu/one_player.jpg"
#define ONE_PLAYER_GREY_C "../assets/menu/one_player_grey.jpg"
#define TWO_PLAYERS_C "../assets/menu/two_players.jpg"
#define TWO_PLAYERS_GREY_C "../assets/menu/two_players_grey.jpg"
#define BUTTON_BACK_C "../assets/settings/home_p.jpg"
#define BUTTON_BACK_GREY_C "../assets/menu/home_grey_p.jpg"
#define BUTTON_SOUND_C "../assets/audio/sound_button.wav"
#define ONE_PLAYER_C "menu/one_player.jpg"
#define ONE_PLAYER_GREY_C "menu/one_player_grey.jpg"
#define TWO_PLAYERS_C "menu/two_players.jpg"
#define TWO_PLAYERS_GREY_C "menu/two_players_grey.jpg"
#define BUTTON_BACK_C "settings/home_p.jpg"
#define BUTTON_BACK_GREY_C "menu/home_grey_p.jpg"
#define BUTTON_SOUND_C "audio/sound_button.wav"

class ChoosePlayers : public AScene {
public:
Expand Down
11 changes: 6 additions & 5 deletions Menu/EndScene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include "EndScene.hpp"
#include "Player.hpp"
#include "AssetSelector.hpp"

EndScene::EndScene(const std::shared_ptr<IrrlichtController> &ctrl, const std::string name) : AScene(ctrl, name)
{
Expand All @@ -12,7 +13,7 @@ EndScene::EndScene(const std::shared_ptr<IrrlichtController> &ctrl, const std::s

void EndScene::Init(void)
{
this->_background = this->_ctrl->_driver->getTexture(BACKGROUND_END);
this->_background = this->_ctrl->_driver->getTexture(AssetSelector(BACKGROUND_END).c_str());
_ctrl->_scene_mgr->addCameraSceneNode(0, vector3df(0, 0 , 0), vector3df(0, 0, 1));
irr::scene::ICameraSceneNode *camera = _ctrl->_scene_mgr->getActiveCamera();
std::shared_ptr<Player> p = std::make_shared<Player>(_ctrl, "p1", (Player::BomberType)_ctrl->_context.skin_player_one, Player::MENU);
Expand All @@ -27,10 +28,10 @@ void EndScene::Init(void)
p2->setPosition(irr::core::vector3df(1, -3, 9));
p->setPosition(irr::core::vector3df(-6, -3, 14));
}
this->_ctrl->_music->Play(MUSIC_END);
this->_restart = std::make_unique<Button>(this->_ctrl->_device, vector2d<int>(400, 100), vector2d<int>(WIDTH / 2 - 600, HEIGHT / 2 - 300), GUI_ID_RESUME_BUTTON_PAUSED, RESTART, RESTART_DARK);
this->_exit = std::make_unique<Button>(this->_ctrl->_device, vector2d<int>(400, 100), vector2d<int>(WIDTH / 2 + 200, HEIGHT / 2 - 300), GUI_ID_EXIT_BUTTON_PAUSED, EXIT_END, EXIT_END_DARK);
this->_buttonSound = std::make_unique<Sound>(this->_ctrl->_context, BUTTON_SOUND_END);
this->_ctrl->_music->Play(AssetSelector(MUSIC_END));
this->_restart = std::make_unique<Button>(this->_ctrl->_device, vector2d<int>(400, 100), vector2d<int>(WIDTH / 2 - 600, HEIGHT / 2 - 300), GUI_ID_RESUME_BUTTON_PAUSED, AssetSelector(RESTART), AssetSelector(RESTART_DARK));
this->_exit = std::make_unique<Button>(this->_ctrl->_device, vector2d<int>(400, 100), vector2d<int>(WIDTH / 2 + 200, HEIGHT / 2 - 300), GUI_ID_EXIT_BUTTON_PAUSED, AssetSelector(EXIT_END), AssetSelector(EXIT_END_DARK));
this->_buttonSound = std::make_unique<Sound>(this->_ctrl->_context, AssetSelector(BUTTON_SOUND_END));
}
void EndScene::Update(void)
{
Expand Down
14 changes: 7 additions & 7 deletions Menu/EndScene.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
#include "GameScene.hpp"
#include "Sound.hpp"

#define BACKGROUND_END "../assets/end/bgend.jpg"
#define MUSIC_END "../assets/audio/music_game.ogg"
#define RESTART "../assets/end/restart.png"
#define RESTART_DARK "../assets/end/restart_fonce.png"
#define EXIT_END "../assets/end/menu.png"
#define EXIT_END_DARK "../assets/end/menu_fonce.png"
#define BUTTON_SOUND_END "../assets/audio/sound_button.wav"
#define BACKGROUND_END "end/bgend.jpg"
#define MUSIC_END "audio/music_game.ogg"
#define RESTART "end/restart.png"
#define RESTART_DARK "end/restart_fonce.png"
#define EXIT_END "end/menu.png"
#define EXIT_END_DARK "end/menu_fonce.png"
#define BUTTON_SOUND_END "audio/sound_button.wav"


class EndScene : public AScene{
Expand Down
16 changes: 8 additions & 8 deletions Menu/Introduction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//

#include "Introduction.hpp"

#include "AssetSelector.hpp"
#include <iostream>

Introduction::Introduction(const std::shared_ptr<IrrlichtController> &ctrl, const std::string name) : AScene(ctrl, name)
Expand All @@ -14,13 +14,13 @@ Introduction::Introduction(const std::shared_ptr<IrrlichtController> &ctrl, cons
void Introduction::Init(void)
{
this->_select = 0;
this->_image_welcome = this->_ctrl->_driver->getTexture(WELCOME);
this->_image_space = this->_ctrl->_driver->getTexture(SPACE);
this->_image_welcome = this->_ctrl->_driver->getTexture(AssetSelector(WELCOME).c_str());
this->_image_space = this->_ctrl->_driver->getTexture(AssetSelector(SPACE).c_str());
this->_logo = 0;
this->_first_part = this->_ctrl->_driver->getTexture(FIRST_PART);
this->_second_part = this->_ctrl->_driver->getTexture(SECOND_PART);
this->_third_part = this->_ctrl->_driver->getTexture(THIRD_PART);
this->_fourth_part = this->_ctrl->_driver->getTexture(FOURTH_PART);
this->_first_part = this->_ctrl->_driver->getTexture(AssetSelector(FIRST_PART).c_str());
this->_second_part = this->_ctrl->_driver->getTexture(AssetSelector(SECOND_PART).c_str());
this->_third_part = this->_ctrl->_driver->getTexture(AssetSelector(THIRD_PART).c_str());
this->_fourth_part = this->_ctrl->_driver->getTexture(AssetSelector(FOURTH_PART).c_str());
this->start = std::chrono::steady_clock::now();
}

Expand All @@ -38,7 +38,7 @@ void Introduction::Update(void)
this->_logo = 3;
if (this->elapsed_seconds.count() > 5) {
this->_select = 1;
this->_ctrl->_music->Play("../assets/audio/music_intro.ogg");
this->_ctrl->_music->Play(AssetSelector(MENU_INTRO_MUSIC));
}
}
if (this->elapsed_seconds.count() > 1.5 && (this->_select == 1 || this->_select == 2)) {
Expand Down
13 changes: 7 additions & 6 deletions Menu/Introduction.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@
#include <ctime>
#include <chrono>

#define WELCOME "../assets/menu/back_intro_welcome.jpg"
#define SPACE "../assets/menu/back_intro_space.jpg"
#define FIRST_PART "../assets/menu/first_part.jpg"
#define SECOND_PART "../assets/menu/second_part.jpg"
#define THIRD_PART "../assets/menu/third_part.jpg"
#define FOURTH_PART "../assets/menu/fourth_part.jpg"
#define WELCOME "menu/back_intro_welcome.jpg"
#define SPACE "menu/back_intro_space.jpg"
#define FIRST_PART "menu/first_part.jpg"
#define SECOND_PART "menu/second_part.jpg"
#define THIRD_PART "menu/third_part.jpg"
#define FOURTH_PART "menu/fourth_part.jpg"
#define MENU_INTRO_MUSIC "audio/music_intro.ogg"

class Introduction : public AScene {
public:
Expand Down
11 changes: 6 additions & 5 deletions Menu/Menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
//

#include "Menu.hpp"
#include "AssetSelector.hpp"

Menu::Menu(const std::shared_ptr<IrrlichtController> &ctrl, const std::string name) : AScene(ctrl, name)
{
Expand All @@ -11,11 +12,11 @@ Menu::Menu(const std::shared_ptr<IrrlichtController> &ctrl, const std::string na

void Menu::Init(void)
{
this->_buttonSettings = std::make_unique<Button>(this->_ctrl->_device, vector2d<int>(427, HEIGHT), vector2d<int>(0, 0), GUI_ID_SETTINGS_BUTTON, BUTTON_SETTINGS_GREY_M, BUTTON_SETTINGS_M);
this->_buttonPlay = std::make_unique<Button>(this->_ctrl->_device, vector2d<int>(427, HEIGHT), vector2d<int>(427, 0), GUI_ID_PLAY_BUTTON, PLAY_GREY_M, PLAY_M);
this->_buttonExit = std::make_unique<Button>(this->_ctrl->_device, vector2d<int>(427, HEIGHT), vector2d<int>(854, 0), GUI_ID_EXIT_BUTTON, EXIT_GREY_M, EXIT_M);
this->_ctrl->_music->Play(MUSIC_M);
this->_buttonSound = std::make_unique<Sound>(this->_ctrl->_context, BUTTON_SOUND_M);
this->_buttonSettings = std::make_unique<Button>(this->_ctrl->_device, vector2d<int>(427, HEIGHT), vector2d<int>(0, 0), GUI_ID_SETTINGS_BUTTON, AssetSelector(BUTTON_SETTINGS_GREY_M), AssetSelector(BUTTON_SETTINGS_M));
this->_buttonPlay = std::make_unique<Button>(this->_ctrl->_device, vector2d<int>(427, HEIGHT), vector2d<int>(427, 0), GUI_ID_PLAY_BUTTON, AssetSelector(PLAY_GREY_M), AssetSelector(PLAY_M));
this->_buttonExit = std::make_unique<Button>(this->_ctrl->_device, vector2d<int>(427, HEIGHT), vector2d<int>(854, 0), GUI_ID_EXIT_BUTTON, AssetSelector(EXIT_GREY_M), AssetSelector(EXIT_M));
this->_ctrl->_music->Play(AssetSelector(MUSIC_M));
this->_buttonSound = std::make_unique<Sound>(this->_ctrl->_context, AssetSelector(BUTTON_SOUND_M));
}

void Menu::Update(void)
Expand Down
Loading

0 comments on commit 5eb0da2

Please sign in to comment.