5 #include "controleteclado.h"
6 #include "shotmanager.h"
8 const int SCREEN_WIDTH
= 640;
9 const int SCREEN_HEIGHT
= 480;
10 const int SCREEN_BPP
= 32;
11 const int FRAMES_PER_SECOND
= 60;
13 void Game::loadMap(std::string mapname
) {
16 const double alturaChao
= 400;
17 mapa
= new Mapa(mapname
,this);
20 void Game::addPlatform(Platform
* plat
) {
21 gravityManager
->addPlatform(plat
);
24 void Game::removePlatforms() {
25 gravityManager
->removePlatforms();
31 glClearColor( 1, 1, 1, 0 );
33 //Initialize modelview matrix
34 glMatrixMode( GL_MODELVIEW
);
39 glEnable(GL_LINE_SMOOTH
);
41 glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
42 glHint(GL_LINE_SMOOTH_HINT
, GL_NICEST
);
44 //If there was any errors
45 if( glGetError() != GL_NO_ERROR
)
50 //If everything initialized
56 gravityManager
= new GravityManager
;
60 if( SDL_Init( SDL_INIT_EVERYTHING
) < 0 )
66 if( SDL_SetVideoMode( SCREEN_WIDTH
, SCREEN_HEIGHT
, SCREEN_BPP
, SDL_OPENGL
) == NULL
)
78 SDL_WM_SetCaption( "Prototipo Jogo", NULL
);
81 void Game::desenhaMira(Ponto aim
) {
83 glTranslatef(camera
.x
+aim
.x
,camera
.y
+aim
.y
,0);
89 glClear( GL_COLOR_BUFFER_BIT
);
92 if (player
->getX() <= SCREEN_WIDTH
/2)
94 else if (player
->getX() >= mapa
->xmax() - SCREEN_WIDTH
/2)
95 x
= mapa
->xmax() - SCREEN_WIDTH
;
97 x
= player
->getX() - SCREEN_WIDTH
/2;
99 if (player
->getY() <= 2*SCREEN_HEIGHT
/3)
101 else if (player
->getY() >= mapa
->ymax() - SCREEN_HEIGHT
/3)
102 y
= mapa
->ymax() - SCREEN_HEIGHT
;
104 y
= player
->getY() - 2*SCREEN_HEIGHT
/3;
109 shotManager
->desenha();
111 glMatrixMode( GL_PROJECTION
);
113 glOrtho( camera
.x
, camera
.x
+SCREEN_WIDTH
, camera
.y
+SCREEN_HEIGHT
, camera
.y
, -1, 1 );
114 SDL_GL_SwapBuffers();
117 void Game::reloadLua() {
119 weaponManager
->loadWeapons();
120 player
->equip(weaponManager
->getWeapon("Shotgun"));
123 void Game::setSpawn(Ponto spawn
) {
127 void Game::mainLoop() {
129 luaEnv
.registerScripts();
130 luaEnv
.loadScripts();
133 player
= new Player(this);
134 currentMap
= "map1.lua";
136 player
->setPosition(spawn
.x
,spawn
.y
);
137 ControleTeclado
c(*player
);
139 shotManager
= new ShotManager
;
140 weaponManager
= new WeaponManager
;
141 weaponManager
->loadWeapons();
142 player
->equip(weaponManager
->getWeapon("Shotgun"));
149 gravityManager
->update();
156 if (fps
.get_ticks() < 1000 / FRAMES_PER_SECOND
) {
157 SDL_Delay( ( 1000 / FRAMES_PER_SECOND
) - fps
.get_ticks() );