5 #include "controleteclado.h"
6 #include "controlewii.h"
7 #include "shotmanager.h"
9 void Game::loadMap(std::string mapname
) {
12 mapa
= new Mapa(mapname
,this);
15 void Game::addPlatform(Platform
* plat
) {
16 gravityManager
->addPlatform(plat
);
19 void Game::removePlatforms() {
20 gravityManager
->removePlatforms();
25 glClearColor( 1, 1, 1, 0 );
27 //Initialize modelview matrix
28 glMatrixMode( GL_MODELVIEW
);
33 glEnable(GL_LINE_SMOOTH
);
35 glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
36 glHint(GL_LINE_SMOOTH_HINT
, GL_NICEST
);
38 //If there was any errors
39 if( glGetError() != GL_NO_ERROR
)
44 //If everything initialized
48 Game::Game(ConfigManager
*cfg
) {
49 gravityManager
= new GravityManager
;
54 if( SDL_Init( SDL_INIT_EVERYTHING
) < 0 )
60 if( SDL_SetVideoMode( config
->screen
["width"], config
->screen
["height"], config
->screen
["bpp"], SDL_OPENGL
) == NULL
)
72 SDL_WM_SetCaption( "Prototipo Jogo", NULL
);
75 void Game::desenhaMira(Ponto aim
) {
77 glTranslatef(camera
.x
+aim
.x
,camera
.y
+aim
.y
,0);
83 glClear( GL_COLOR_BUFFER_BIT
);
85 int width
= config
->screen
["width"];
86 int height
= config
->screen
["height"];
88 if (player
->getX() <= width
/2)
90 else if (player
->getX() >= mapa
->xmax() - width
/2)
91 x
= mapa
->xmax() - width
;
93 x
= player
->getX() - width
/2;
95 if (player
->getY() <= 2*height
/3)
97 else if (player
->getY() >= mapa
->ymax() - height
/3)
98 y
= mapa
->ymax() - height
;
100 y
= player
->getY() - 2*height
/3;
105 shotManager
->desenha();
107 glMatrixMode( GL_PROJECTION
);
109 glOrtho( camera
.x
, camera
.x
+width
, camera
.y
+height
, camera
.y
, -1, 1 );
110 SDL_GL_SwapBuffers();
113 void Game::reloadLua() {
115 loadMap(config
->maps
.front());
116 weaponManager
->loadWeapons();
117 shotManager
->clearShots();
118 player
->equip(weaponManager
->getWeapon("Shotgun"));
121 void Game::setSpawn(Ponto spawn
) {
125 void Game::mainLoop() {
128 loadMap(config
->maps
.front());
130 player
= new Player(this, spawn
, config
->player
["speed"]);
133 c
= new ControleTeclado(*player
);
135 c
= new ControleWii(*player
);
137 shotManager
= new ShotManager
;
138 weaponManager
= new WeaponManager(this);
139 collisionManager
= new CollisionManager
;
140 weaponManager
->loadWeapons();
141 player
->equip(weaponManager
->getWeapon("Shotgun"));
143 collisionManager
->subscribe(player
);
151 gravityManager
->update();
152 collisionManager
->update();
159 if (fps
.get_ticks() < 1000 / config
->screen
["fps"] ) {
160 SDL_Delay( ( 1000 / config
->screen
["fps"] ) - fps
.get_ticks() );