5 #include "controleteclado.h"
6 #include "shotmanager.h"
8 void Game::loadMap(std::string mapname
) {
11 mapa
= new Mapa(mapname
,this);
14 void Game::addPlatform(Platform
* plat
) {
15 gravityManager
->addPlatform(plat
);
18 void Game::removePlatforms() {
19 gravityManager
->removePlatforms();
24 glClearColor( 1, 1, 1, 0 );
26 //Initialize modelview matrix
27 glMatrixMode( GL_MODELVIEW
);
32 glEnable(GL_LINE_SMOOTH
);
34 glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
35 glHint(GL_LINE_SMOOTH_HINT
, GL_NICEST
);
37 //If there was any errors
38 if( glGetError() != GL_NO_ERROR
)
43 //If everything initialized
47 Game::Game(ConfigManager
*cfg
) {
48 gravityManager
= new GravityManager
;
53 if( SDL_Init( SDL_INIT_EVERYTHING
) < 0 )
59 if( SDL_SetVideoMode( config
->screen
["width"], config
->screen
["height"], config
->screen
["bpp"], SDL_OPENGL
) == NULL
)
71 SDL_WM_SetCaption( "Prototipo Jogo", NULL
);
74 void Game::desenhaMira(Ponto aim
) {
76 glTranslatef(camera
.x
+aim
.x
,camera
.y
+aim
.y
,0);
82 glClear( GL_COLOR_BUFFER_BIT
);
84 int width
= config
->screen
["width"];
85 int height
= config
->screen
["height"];
87 if (player
->getX() <= width
/2)
89 else if (player
->getX() >= mapa
->xmax() - width
/2)
90 x
= mapa
->xmax() - width
;
92 x
= player
->getX() - width
/2;
94 if (player
->getY() <= 2*height
/3)
96 else if (player
->getY() >= mapa
->ymax() - height
/3)
97 y
= mapa
->ymax() - height
;
99 y
= player
->getY() - 2*height
/3;
104 shotManager
->desenha();
106 glMatrixMode( GL_PROJECTION
);
108 glOrtho( camera
.x
, camera
.x
+width
, camera
.y
+height
, camera
.y
, -1, 1 );
109 SDL_GL_SwapBuffers();
112 void Game::reloadLua() {
114 loadMap(config
->maps
.front());
115 weaponManager
->loadWeapons();
116 player
->equip(weaponManager
->getWeapon("Shotgun"));
119 void Game::setSpawn(Ponto spawn
) {
123 void Game::mainLoop() {
126 loadMap(config
->maps
.front());
128 player
= new Player(this, spawn
, config
->player
["speed"]);
129 ControleTeclado
c(*player
);
131 shotManager
= new ShotManager
;
132 weaponManager
= new WeaponManager(this);
133 weaponManager
->loadWeapons();
134 player
->equip(weaponManager
->getWeapon("Shotgun"));
143 gravityManager
->update();
150 if (fps
.get_ticks() < 1000 / config
->screen
["fps"] ) {
151 SDL_Delay( ( 1000 / config
->screen
["fps"] ) - fps
.get_ticks() );