5 #include "controleteclado.h"
6 #include "controlewii.h"
7 #include "shotmanager.h"
8 #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
->screen
["width"], config
->screen
["height"], config
->screen
["bpp"], SDL_OPENGL
| SDL_RESIZABLE
) == NULL
)
77 SDL_WM_SetCaption( "Prototipo Jogo", 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
->screen
["width"];
91 int height
= config
->screen
["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();
112 glMatrixMode( GL_PROJECTION
);
114 glOrtho( camera
.x
, camera
.x
+width
, camera
.y
+height
, camera
.y
, -2, 2 );
115 SDL_GL_SwapBuffers();
118 void Game::reloadLua() {
120 resize(config
->screen
["width"], config
->screen
["height"]);
121 loadMap(config
->maps
.front());
122 weaponManager
->loadWeapons();
123 shotManager
->clearShots();
124 player
->equip(weaponManager
->getWeapon("Shotgun"));
127 void Game::setSpawn(Ponto spawn
) {
131 void Game::resize(GLsizei x
, GLsizei y
) {
132 config
->screen
["width"] = x
;
133 config
->screen
["height"] = y
;
134 SDL_SetVideoMode(x
, y
, config
->screen
["bpp"], SDL_OPENGL
| SDL_RESIZABLE
);
135 glViewport(0, 0, x
, y
);
138 WeaponItem
* Game::dropWeapon(std::string name
) {
139 return weaponManager
->getItem(name
);
142 void Game::mainLoop() {
144 shotManager
= new ShotManager
;
145 weaponManager
= new WeaponManager(this);
146 collisionManager
= new CollisionManager
;
147 weaponManager
->loadWeapons();
148 loadMap(config
->maps
.front());
150 player
= new Player(this, spawn
, config
->player
["speed"]);
153 c
= new ControleTeclado(*player
);
155 c
= new ControleWii(*player
);
156 player
->equip(weaponManager
->getWeapon("Shotgun"));
158 collisionManager
->subscribe(player
);
159 std::list
<WeaponItem
*>::iterator itW
;
160 for (itW
= mapa
->items
.begin(); itW
!= mapa
->items
.end(); itW
++) {
161 collisionManager
->subscribe(*itW
);
162 gravityManager
->subscribe(*itW
);
168 int ifps
= config
->screen
["fps"];
174 gravityManager
->update();
175 collisionManager
->update();
185 rate
= ((double)fps
.get_ticks())/ifps
;
188 if (fps
.get_ticks() < 1000 / ifps
) {
189 SDL_Delay( ( 1000 / ifps
) - fps
.get_ticks() );