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::geraMapa() {
14 const double alturaChao
= 400;
15 mapa
= new Mapa(800, 600, player
, gravityManager
);
16 mapa
->novaLinha(0,alturaChao
,mapa
->xmax(),alturaChao
);
17 mapa
->novaLinha(0,mapa
->ymax(),mapa
->xmax(),mapa
->ymax());
18 mapa
->novaLinha(30,350,100,350);
19 mapa
->novaLinha(200,320,250,320);
20 mapa
->novaLinha(400,275,450,275);
21 mapa
->novaLinha(200,200,250,200);
22 mapa
->novaLinha(30,100,100,100);
28 glClearColor( 1, 1, 1, 0 );
30 //Initialize modelview matrix
31 glMatrixMode( GL_MODELVIEW
);
36 glEnable(GL_LINE_SMOOTH
);
38 glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
39 glHint(GL_LINE_SMOOTH_HINT
, GL_NICEST
);
41 //If there was any errors
42 if( glGetError() != GL_NO_ERROR
)
47 //If everything initialized
53 gravityManager
= new GravityManager
;
56 if( SDL_Init( SDL_INIT_EVERYTHING
) < 0 )
62 if( SDL_SetVideoMode( SCREEN_WIDTH
, SCREEN_HEIGHT
, SCREEN_BPP
, SDL_OPENGL
) == NULL
)
74 SDL_WM_SetCaption( "Prototipo Jogo", NULL
);
78 glClear( GL_COLOR_BUFFER_BIT
);
81 if (player
->getX() <= SCREEN_WIDTH
/2)
83 else if (player
->getX() >= mapa
->xmax() - SCREEN_WIDTH
/2)
84 x
= mapa
->xmax() - SCREEN_WIDTH
;
86 x
= player
->getX() - SCREEN_WIDTH
/2;
88 if (player
->getY() <= 2*SCREEN_HEIGHT
/3)
90 else if (player
->getY() >= mapa
->ymax() - SCREEN_HEIGHT
/3)
91 y
= mapa
->ymax() - SCREEN_HEIGHT
;
93 y
= player
->getY() - 2*SCREEN_HEIGHT
/3;
98 glMatrixMode( GL_PROJECTION
);
100 glOrtho( x
, x
+SCREEN_WIDTH
, y
+SCREEN_HEIGHT
, y
, -1, 1 );
101 SDL_GL_SwapBuffers();
104 void Game::mainLoop() {
106 luaEnv
.registerScripts();
107 luaEnv
.loadScripts();
110 player
= new Player(this);
120 gravityManager
->update();
126 if (fps
.get_ticks() < 1000 / FRAMES_PER_SECOND
) {
127 SDL_Delay( ( 1000 / FRAMES_PER_SECOND
) - fps
.get_ticks() );