5 #include "controlewii.h"
6 #include "shotmanager.h"
7 #include "weaponitem.h"
10 void Game::loadMap(std::string mapname
) {
13 mapa
= new Mapa(mapname
,this);
16 void Game::addPlatform(Platform
* plat
) {
17 gravityManager
->addPlatform(plat
);
20 void Game::removePlatforms() {
21 gravityManager
->removePlatforms();
26 glClearColor( 1, 1, 1, 0 );
28 //Initialize modelview matrix
29 glMatrixMode( GL_MODELVIEW
);
33 glEnable(GL_DEPTH_TEST
);
34 glDepthFunc(GL_LEQUAL
);
38 glEnable(GL_LINE_SMOOTH
);
40 glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
41 glHint(GL_LINE_SMOOTH_HINT
, GL_NICEST
);
43 //If there was any errors
44 if( glGetError() != GL_NO_ERROR
)
49 //If everything initialized
53 Game::Game(ConfigManager
*cfg
) {
54 gravityManager
= new GravityManager
;
59 if( SDL_Init( SDL_INIT_EVERYTHING
) < 0 )
65 if( SDL_SetVideoMode( config
->integer
["width"], config
->integer
["height"], config
->integer
["bpp"], SDL_OPENGL
| SDL_RESIZABLE
) == NULL
)
77 SDL_WM_SetCaption( "Big Stick", NULL
);
80 void Game::desenhaMira(Ponto aim
) {
82 glTranslatef(aim
.x
,aim
.y
,0);
88 glClear( GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
);
90 int width
= config
->integer
["width"];
91 int height
= config
->integer
["height"];
93 if (player
->getX() <= width
/2)
95 else if (player
->getX() >= mapa
->xmax() - width
/2)
96 x
= mapa
->xmax() - width
;
98 x
= player
->getX() - width
/2;
100 if (player
->getY() <= 2*height
/3)
102 else if (player
->getY() >= mapa
->ymax() - height
/3)
103 y
= mapa
->ymax() - height
;
105 y
= player
->getY() - 2*height
/3;
110 shotManager
->desenha();
111 enemyManager
->desenha();
113 double vida
= std::max(0.0,player
->hp
/double(config
->integer
["hp"]));
116 glTranslatef(camera
.x
,camera
.y
,0);
118 glBegin(GL_LINE_LOOP
);
121 glVertex3f(50,500,0);
122 glVertex3f(10,500,0);
126 glVertex3f(10+1,10+1,0);
127 glVertex3f(50-1,10+1,0);
128 glVertex3f(50-1,std::max(vida
*(500-1)-1,10.0),0);
129 glVertex3f(10+1,std::max(vida
*(500-1)-1,10.0),0);
134 glMatrixMode( GL_PROJECTION
);
136 glOrtho( camera
.x
, camera
.x
+width
, camera
.y
+height
, camera
.y
, -2, 2 );
137 SDL_GL_SwapBuffers();
140 void Game::reloadLua() {
142 resize(config
->integer
["width"], config
->integer
["height"]);
143 loadMap(config
->currentMap());
144 weaponManager
->loadWeapons();
145 shotManager
->clearShots();
146 player
->equip(weaponManager
->getWeapon("Shotgun"));
149 void Game::setSpawn(Ponto spawn
) {
153 void Game::resize(GLsizei x
, GLsizei y
) {
154 config
->integer
["width"] = x
;
155 config
->integer
["height"] = y
;
156 SDL_SetVideoMode(x
, y
, config
->integer
["bpp"], SDL_OPENGL
| SDL_RESIZABLE
);
157 glViewport(0, 0, x
, y
);
160 WeaponItem
* Game::dropWeapon(std::string name
) {
161 return weaponManager
->getItem(name
);
164 void Game::spawnEnemy(std::string name
, Ponto position
) {
165 Enemy
* enemy
= enemyManager
->createEnemy(name
);
166 enemy
->setPosition(position
.x
,position
.y
);
169 void Game::previousMap() {
170 enemyManager
->loadEnemies();
171 shotManager
->clearShots();
172 loadMap(config
->previousMap());
173 player
->setPosition(spawn
.x
, spawn
.y
);
176 void Game::reloadMap(bool respawn
) {
177 enemyManager
->loadEnemies();
178 shotManager
->clearShots();
179 loadMap(config
->currentMap());
181 player
->setPosition(spawn
.x
, spawn
.y
);
184 void Game::nextMap() {
185 enemyManager
->loadEnemies();
186 shotManager
->clearShots();
187 loadMap(config
->nextMap());
188 player
->setPosition(spawn
.x
, spawn
.y
);
191 void Game::mainLoop() {
193 shotManager
= new ShotManager
;
194 weaponManager
= new WeaponManager(this);
195 collisionManager
= new CollisionManager
;
196 weaponManager
->loadWeapons();
197 enemyManager
= new EnemyManager(this);
198 enemyManager
->loadEnemies();
199 loadMap(config
->currentMap());
201 player
= new Player(this, spawn
, config
->ponto
["speed"]);
203 c
= new ControleWii(*player
);
204 player
->equip(weaponManager
->getWeapon("Shotgun"));
206 collisionManager
->subscribe(player
);
207 std::list
<WeaponItem
*>::iterator itW
;
208 for (itW
= mapa
->items
.begin(); itW
!= mapa
->items
.end(); itW
++) {
209 collisionManager
->subscribe(*itW
);
210 gravityManager
->subscribe(*itW
);
216 int ifps
= config
->integer
["fps"];
219 if (!enemyManager
->hasEnemies())
224 enemyManager
->think();
227 collisionManager
->update();
228 gravityManager
->update();
231 enemyManager
->animate();
236 enemyManager
->move();
240 rate
= ((double)fps
.get_ticks())/ifps
;
243 if (fps
.get_ticks() < 1000 / ifps
) {
244 SDL_Delay( ( 1000 / ifps
) - fps
.get_ticks() );