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(30,350,100,350);
18 mapa
->novaLinha(200,320,250,320);
19 mapa
->novaLinha(400,275,450,275);
20 mapa
->novaLinha(200,200,250,200);
21 mapa
->novaLinha(30,100,100,100);
27 glClearColor( 1, 1, 1, 0 );
30 glMatrixMode( GL_PROJECTION
);
32 glOrtho( 0, SCREEN_WIDTH
, SCREEN_HEIGHT
, 0, -1, 1 );
34 //Initialize modelview matrix
35 glMatrixMode( GL_MODELVIEW
);
40 glEnable(GL_LINE_SMOOTH
);
42 glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
43 glHint(GL_LINE_SMOOTH_HINT
, GL_NICEST
);
45 //If there was any errors
46 if( glGetError() != GL_NO_ERROR
)
51 //If everything initialized
57 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
);
82 glClear( GL_COLOR_BUFFER_BIT
);
85 if (player
->getX() <= SCREEN_WIDTH
/2)
87 else if (player
->getX() >= mapa
->xmax() - SCREEN_WIDTH
/2)
88 x
= mapa
->xmax() - SCREEN_WIDTH
;
90 x
= player
->getX() - SCREEN_WIDTH
/2;
92 if (player
->getY() <= 2*SCREEN_HEIGHT
/3)
94 else if (player
->getY() >= mapa
->ymax() - SCREEN_HEIGHT
/3)
95 y
= mapa
->ymax() - SCREEN_HEIGHT
;
97 y
= player
->getY() - 2*SCREEN_HEIGHT
/3;
102 glMatrixMode( GL_PROJECTION
);
104 glOrtho( x
, x
+SCREEN_WIDTH
, y
+SCREEN_HEIGHT
, y
, -1, 1 );
105 SDL_GL_SwapBuffers();
108 void Game::mainLoop() {
110 luaEnv
.registerScripts();
111 luaEnv
.loadScripts();
114 player
= new Player(this);
124 gravityManager
->update();
130 if (fps
.get_ticks() < 1000 / FRAMES_PER_SECOND
) {
131 SDL_Delay( ( 1000 / FRAMES_PER_SECOND
) - fps
.get_ticks() );