5 #include "controleteclado.h"
7 const int SCREEN_WIDTH
= 640;
8 const int SCREEN_HEIGHT
= 480;
9 const int SCREEN_BPP
= 32;
10 const int FRAMES_PER_SECOND
= 60;
12 void Game::loadMap(std::string mapname
) {
15 const double alturaChao
= 400;
16 mapa
= new Mapa(mapname
,this);
19 void Game::addPlatform(Platform
* plat
) {
20 gravityManager
->addPlatform(plat
);
23 void Game::removePlatforms() {
24 gravityManager
->removePlatforms();
30 glClearColor( 1, 1, 1, 0 );
32 //Initialize modelview matrix
33 glMatrixMode( GL_MODELVIEW
);
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
55 gravityManager
= new GravityManager
;
59 if( SDL_Init( SDL_INIT_EVERYTHING
) < 0 )
65 if( SDL_SetVideoMode( SCREEN_WIDTH
, SCREEN_HEIGHT
, SCREEN_BPP
, SDL_OPENGL
) == NULL
)
77 SDL_WM_SetCaption( "Prototipo Jogo", NULL
);
80 void Game::desenhaMira(Ponto aim
) {
82 glTranslatef(camera
.x
+aim
.x
,camera
.y
+aim
.y
,0);
88 glClear( GL_COLOR_BUFFER_BIT
);
91 if (player
->getX() <= SCREEN_WIDTH
/2)
93 else if (player
->getX() >= mapa
->xmax() - SCREEN_WIDTH
/2)
94 x
= mapa
->xmax() - SCREEN_WIDTH
;
96 x
= player
->getX() - SCREEN_WIDTH
/2;
98 if (player
->getY() <= 2*SCREEN_HEIGHT
/3)
100 else if (player
->getY() >= mapa
->ymax() - SCREEN_HEIGHT
/3)
101 y
= mapa
->ymax() - SCREEN_HEIGHT
;
103 y
= player
->getY() - 2*SCREEN_HEIGHT
/3;
109 glMatrixMode( GL_PROJECTION
);
111 glOrtho( camera
.x
, camera
.x
+SCREEN_WIDTH
, camera
.y
+SCREEN_HEIGHT
, camera
.y
, -1, 1 );
112 SDL_GL_SwapBuffers();
115 void Game::reloadLua() {
117 weaponManager
->loadWeapons();
118 player
->equip(weaponManager
->getWeapon("Shotgun"));
121 void Game::setSpawn(Ponto spawn
) {
125 void Game::mainLoop() {
127 luaEnv
.registerScripts();
128 luaEnv
.loadScripts();
131 player
= new Player(this);
132 currentMap
= "map1.lua";
134 player
->setPosition(spawn
.x
,spawn
.y
);
135 ControleTeclado
c(*player
);
137 weaponManager
= new WeaponManager
;
138 weaponManager
->loadWeapons();
139 player
->equip(weaponManager
->getWeapon("Shotgun"));
146 gravityManager
->update();
152 if (fps
.get_ticks() < 1000 / FRAMES_PER_SECOND
) {
153 SDL_Delay( ( 1000 / FRAMES_PER_SECOND
) - fps
.get_ticks() );