-
Notifications
You must be signed in to change notification settings - Fork 0
/
GameEngine.cpp
126 lines (109 loc) · 3.11 KB
/
GameEngine.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#include "GameEngine.hpp"
GameEngine::GameEngine() : _winX(1024), _winY(768)
{
mode = "home";
nb = 0;
pos = 0;
stat = 0;
}
GameEngine::~GameEngine()
{
if (mode == "play")
{
delete _wall;
for (size_t i = 0; i < _players.size(); ++i)
delete _players[i];
if (_cam != NULL)
delete _cam;
}
}
bool GameEngine::initialize()
{
tab[0] = &GameEngine::createModeSetting;
tab[1] = &GameEngine::createPlayerSetting;
tab[2] = &GameEngine::createMapModeSetting;
tab[3] = &GameEngine::createPredefinedSetting;
tab[4] = &GameEngine::createCustomSetting;
tab[5] = &GameEngine::createPause;
if (!_context.start(_winX, _winY, "Bomberman"))
return false;
std::cout << "WINDOW CREATED" << std::endl;
glEnable(GL_DEPTH_TEST);
std::cout << "GLENABLE IS GOOD" << std::endl;
if (!_shader.load("./LibBomberman_linux_x64/shaders/basic.fp", GL_FRAGMENT_SHADER))
throw ErrorException("Error : shader load basic.fp failed in GameEnigne.cpp");
if (!_shader.load("./LibBomberman_linux_x64/shaders/basic.vp", GL_VERTEX_SHADER))
throw ErrorException("Error : shader load basic.vp failed in GameEnigne.cpp");
if (!_shader.build())
throw ErrorException("Error : shader build failed in GameEnigne.cpp");
std::cout << "SHADER LOAD + SHADER BUILD IS GOOD" << std::endl;
_cam = new Camera(glm::vec3(0, 0, 3), glm::vec3(0, 0, 0));
_projection = _cam->setPerspective(_winX, _winY);
_transformation = _cam->setLookAt();
// The shader always needs to be bound before setUniform method calls
_shader.bind();
_shader.setUniform("view", _transformation);
_shader.setUniform("projection", _projection);
createSound();
createHomeMenu();
return true;
}
bool GameEngine::update()
{
_context.updateClock(_clock);
_context.updateInputs(_input);
if (mode == "over")
return (OverMode());
if (mode == "home" || mode == "setting")
return (HomeMode());
if (mode == "pause")
return (PauseMode());
if (mode == "save")
return (SaveMode());
if (mode == "custom")
return(CustomMode());
if (mode == "play")
return (PlayMode());
if (mode == "load")
return (loadMode());
if (mode == "score")
return (ScoreMode());
return false;
}
bool GameEngine::loadSetting()
{
return ((this->*tab[stat])());
}
void GameEngine::clearVector()
{
_objects.clear();
}
void GameEngine::draw()
{
if (mode == "play")
{
// Clear the screen
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// To use a shader (so it can draw the geometry), it must bind
// Only one shader can be active at the same time
_shader.bind();
// We draw all objects which compose the scene
if (_width < 25 && _height < 25)
drawFullMap();
else if (_splitScreen)
drawSplitScreen();
else
drawFullScreen();
// We update the screen so it displays what is on screen
_context.flush();
}
else
{
glViewport(0, 0, _winX, _winY);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
_shader.bind();
for (size_t i = 0; i < _objects.size(); ++i)
_objects[i]->draw(_shader, _clock);
_context.flush();
}
}