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
);
32 glEnable(GL_DEPTH_TEST
);
33 glDepthFunc(GL_LEQUAL
);
37 glEnable(GL_LINE_SMOOTH
);
39 glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
40 glHint(GL_LINE_SMOOTH_HINT
, GL_NICEST
);
42 //If there was any errors
43 if( glGetError() != GL_NO_ERROR
)
48 //If everything initialized
52 Game::Game(ConfigManager
*cfg
) {
53 gravityManager
= new GravityManager
;
58 if( SDL_Init( SDL_INIT_EVERYTHING
) < 0 )
64 if( SDL_SetVideoMode( config
->screen
["width"], config
->screen
["height"], config
->screen
["bpp"], SDL_OPENGL
| SDL_RESIZABLE
) == NULL
)
76 SDL_WM_SetCaption( "Prototipo Jogo", NULL
);
79 void Game::desenhaMira(Ponto aim
) {
81 glTranslatef(camera
.x
+aim
.x
,camera
.y
+aim
.y
,0);
87 glClear( GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
);
89 int width
= config
->screen
["width"];
90 int height
= config
->screen
["height"];
92 if (player
->getX() <= width
/2)
94 else if (player
->getX() >= mapa
->xmax() - width
/2)
95 x
= mapa
->xmax() - width
;
97 x
= player
->getX() - width
/2;
99 if (player
->getY() <= 2*height
/3)
101 else if (player
->getY() >= mapa
->ymax() - height
/3)
102 y
= mapa
->ymax() - height
;
104 y
= player
->getY() - 2*height
/3;
109 shotManager
->desenha();
111 glMatrixMode( GL_PROJECTION
);
113 glOrtho( camera
.x
, camera
.x
+width
, camera
.y
+height
, camera
.y
, -2, 2 );
114 SDL_GL_SwapBuffers();
117 void Game::reloadLua() {
119 resize(config
->screen
["width"], config
->screen
["height"]);
120 loadMap(config
->maps
.front());
121 weaponManager
->loadWeapons();
122 shotManager
->clearShots();
123 player
->equip(weaponManager
->getWeapon("Shotgun"));
126 void Game::setSpawn(Ponto spawn
) {
130 void Game::resize(GLsizei x
, GLsizei y
) {
131 config
->screen
["width"] = x
;
132 config
->screen
["height"] = y
;
133 SDL_SetVideoMode(x
, y
, config
->screen
["bpp"], SDL_OPENGL
| SDL_RESIZABLE
);
134 glViewport(0, 0, x
, y
);
137 void Game::mainLoop() {
140 loadMap(config
->maps
.front());
142 player
= new Player(this, spawn
, config
->player
["speed"]);
145 c
= new ControleTeclado(*player
);
147 c
= new ControleWii(*player
);
149 shotManager
= new ShotManager
;
150 weaponManager
= new WeaponManager(this);
151 collisionManager
= new CollisionManager
;
152 weaponManager
->loadWeapons();
153 player
->equip(weaponManager
->getWeapon("Shotgun"));
155 collisionManager
->subscribe(player
);
158 int ifps
= config
->screen
["fps"];
164 gravityManager
->update();
165 collisionManager
->update();
172 rate
= ((double)fps
.get_ticks())/ifps
;
173 if (fps
.get_ticks() < 1000 / ifps
) {
174 SDL_Delay( ( 1000 / ifps
) - fps
.get_ticks() );