Skip to content

Commit

Permalink
Merge branch 'Menu'
Browse files Browse the repository at this point in the history
# Conflicts:
#	Menu/Menu.cpp
  • Loading branch information
PetrusBzh committed Jun 14, 2020
2 parents 40d05a1 + 1c341aa commit 53e0b1e
Show file tree
Hide file tree
Showing 10 changed files with 118 additions and 40 deletions.
86 changes: 57 additions & 29 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 <exception>

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

int main(void) {
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");

std::shared_ptr<GameScene> testScene = std::make_shared<GameScene>(c, "gameScene");
std::shared_ptr<Menu> menu = std::make_shared<Menu>(c, "menuScene");
std::shared_ptr<Settings> set = std::make_shared<Settings>(c, "settingsScene");
std::shared_ptr<ChoosePlayers> chooseP = std::make_shared<ChoosePlayers>(c, "chooseplayersScene");
std::shared_ptr<SelectSkin> selectSkin = std::make_shared<SelectSkin>(c, "skinScene");
std::shared_ptr<SelectSkins> selectSkins = std::make_shared<SelectSkins>(c, "skinsScene");
std::shared_ptr<Introduction> intro = std::make_shared<Introduction>(c, "introScene");
std::shared_ptr<PauseMenu> pause = std::make_shared<PauseMenu>(c, "pauseScene");
std::shared_ptr<PauseSettings> pauseSettings = std::make_shared<PauseSettings>(c, "pauseSettingsScene");
std::shared_ptr<EndScene> endScene = std::make_shared<EndScene>(c, "endScene");

std::shared_ptr<IrrlichtController> c;
std::shared_ptr<Menu> menu;
std::shared_ptr<Settings> set;
std::shared_ptr<ChoosePlayers> chooseP;
std::shared_ptr<SelectSkin> selectSkin;
std::shared_ptr<SelectSkins> selectSkins;
std::shared_ptr<Introduction> intro;
std::shared_ptr<PauseMenu> pause;
std::shared_ptr<PauseSettings> pauseSettings;
std::shared_ptr<EndScene> endScene;
std::shared_ptr<GameScene> testScene;
try {
c = std::make_shared<IrrlichtController>();
c->Init(irr::video::E_DRIVER_TYPE::EDT_OPENGL, WIDTH, HEIGHT);
c->_device->setWindowCaption(L"Indie Studio");
}
catch (std::exception &e) {
std::cerr << e.what() << std::endl;
return (84);
}
SceneManager m(c);
m.AddScene(testScene);
m.AddScene(menu);
m.AddScene(set);
m.AddScene(chooseP);
m.AddScene(intro);
m.AddScene(pause);
m.AddScene(pauseSettings);
m.AddScene(selectSkin);
m.AddScene(selectSkins);
m.AddScene(endScene);
m.LoadScene("introScene");
while (c->isRunning())
m.Update();

c->SaveConfig();
try {
menu = std::make_shared<Menu>(c, "menuScene");
set = std::make_shared<Settings>(c, "settingsScene");
chooseP = std::make_shared<ChoosePlayers>(c, "chooseplayersScene");
selectSkin = std::make_shared<SelectSkin>(c, "skinScene");
selectSkins = std::make_shared<SelectSkins>(c, "skinsScene");
intro = std::make_shared<Introduction>(c, "introScene");
pause = std::make_shared<PauseMenu>(c, "pauseScene");
pauseSettings = std::make_shared<PauseSettings>(c, "pauseSettingsScene");
endScene = std::make_shared<EndScene>(c, "endScene");
testScene = std::make_shared<GameScene>(c, "gameScene");
m.AddScene(menu);
m.AddScene(set);
m.AddScene(chooseP);
m.AddScene(intro);
m.AddScene(pause);
m.AddScene(pauseSettings);
m.AddScene(selectSkin);
m.AddScene(selectSkins);
m.AddScene(endScene);
m.AddScene(testScene);
}
catch (std::exception &e) {
std::cerr << e.what() << std::endl;
return (84);
}
try {
m.LoadScene("introScene");
while (c->isRunning())
m.Update();
c->SaveConfig();
}
catch (std::exception &e) {
std::cerr << e.what() << std::endl;
return (84);
}
return 0;
}
22 changes: 13 additions & 9 deletions Button/Button.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,22 @@
//

#include "Button.hpp"
#include "Error.hpp"

Button::Button(IrrlichtDevice *device, vector2d<int> size, vector2d<int> pos, ButtonType type, std::string path1, std::string path2)
{
this->_driver = device->getVideoDriver();
this->_env = device->getGUIEnvironment();
this->_textureButton = this->_driver->getTexture(path1.c_str());
this->_textureButtonOver = this->_driver->getTexture(path2.c_str());
this->_button = this->_env->addButton(rect<s32>(pos.X, pos.Y, pos.X + size.X, pos.Y + size.Y), 0, type);
this->_button->setImage(this->_textureButton);
this->_button->setPressedImage(this->_textureButtonOver);
this->_states = 0;
this->_lastStates = 0;
this->_driver = device->getVideoDriver();
this->_env = device->getGUIEnvironment();
if ((this->_textureButton = this->_driver->getTexture(path1.c_str())) == 0)
throw ButtonError("Loading texture button");
if ((this->_textureButtonOver = this->_driver->getTexture(path2.c_str())) == 0)
throw ButtonError("Loading texture button over");
if ((this->_button = this->_env->addButton(rect<s32>(pos.X, pos.Y, pos.X + size.X, pos.Y + size.Y), 0, type)) == 0)
throw ButtonError("Add button");
this->_button->setImage(this->_textureButton);
this->_button->setPressedImage(this->_textureButtonOver);
this->_states = 0;
this->_lastStates = 0;
}

Button::Button(IrrlichtDevice *device, vector2d<int> size, vector2d<int> pos, ButtonType type, std::string path1)
Expand Down
1 change: 1 addition & 0 deletions Button/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})

# define the external libraries to use
target_link_libraries(${PROJECT_NAME} event_receiver)
target_link_libraries(${PROJECT_NAME} exception)
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ target_link_libraries(${PROJECT_NAME} menu)
target_link_libraries(${PROJECT_NAME} settings)
target_link_libraries(${PROJECT_NAME} player)
target_link_libraries(${PROJECT_NAME} storage)
target_link_libraries(${PROJECT_NAME} exception)
target_link_libraries(${PROJECT_NAME} ai)

# define the external libraries to use
Expand Down
15 changes: 15 additions & 0 deletions Exception/Error.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,19 @@ const char *Error::what() const throw()
StorageError::StorageError(const std::string &msg = "") : Error(msg)
{

}

ButtonError::ButtonError(const std::string &msg = "") : Error(msg)
{

}

MusicError::MusicError(const std::string &msg = "") : Error(msg)
{

}

SoundError::SoundError(const std::string &msg = "") : Error(msg)
{

}
22 changes: 22 additions & 0 deletions Exception/Error.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,26 @@ class StorageError : public Error
virtual ~StorageError() throw(){}
};

class ButtonError : public Error
{
public:
ButtonError(const std::string &msg);
virtual ~ButtonError() throw(){}
};

class MusicError : public Error
{
public:
MusicError(const std::string &msg);
virtual ~MusicError() throw(){}
};

class SoundError : public Error
{
public:
SoundError(const std::string &msg);
virtual ~SoundError() throw(){}
};


#endif /* !EXCEPTION_HPP_ */
1 change: 1 addition & 0 deletions Menu/Menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

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

Menu::Menu(const std::shared_ptr<IrrlichtController> &ctrl, const std::string name) : AScene(ctrl, name)
{
Expand Down
2 changes: 2 additions & 0 deletions Music/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,6 @@ target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
# define the external libraries to use
target_link_libraries(${PROJECT_NAME} sfml-audio)
target_link_libraries(${PROJECT_NAME} controller)
target_link_libraries(${PROJECT_NAME} exception)


3 changes: 2 additions & 1 deletion Music/Music.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
//

#include "Music.hpp"
#include "Error.hpp"

Music::Music(SAppContext &context) : _context(context)
{
Expand All @@ -15,7 +16,7 @@ int Music::Play(std::string filepath)
return 0;
this->_music.stop();
if (!this->_music.openFromFile(filepath.c_str()))
return -1;
throw MusicError("Can't open music file");
this->_path_music = filepath;
this->_music.play();
this->_music.setVolume(this->_context.volume_music);
Expand Down
5 changes: 4 additions & 1 deletion Music/Sound.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@
//

#include "Sound.hpp"
#include "Error.hpp"

Sound::Sound(SAppContext &context, const std::string path) : _context(context)
{
this->_buffer.loadFromFile(path);
;
if (!this->_buffer.loadFromFile(path))
throw MusicError("Can't open sound file");
this->_sound.setBuffer(this->_buffer);
this->_sound.setVolume(_context.volume_sound);
}
Expand Down

0 comments on commit 53e0b1e

Please sign in to comment.