Restruturando codigo
[Projeto-PCG.git] / game.cpp
blob72e248b74d4224e97792066491b2af97eea71524
1 #include "game.h"
2 #include "geometry.h"
3 #include "plataformas.h"
4 #include "luaenv.h"
5 #include "timer.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;
13 const double alturachao = 400.0;
15 Linha chao(0.0,alturachao,SCREEN_WIDTH,alturachao);
16 std::vector<Linha> mapa;
18 bool init_GL()
20 //Set clear color
21 glClearColor( 1, 1, 1, 0 );
23 //Set projection
24 glMatrixMode( GL_PROJECTION );
25 glLoadIdentity();
26 glOrtho( 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, -1, 1 );
28 //Initialize modelview matrix
29 glMatrixMode( GL_MODELVIEW );
30 glLoadIdentity();
32 //If there was any errors
33 if( glGetError() != GL_NO_ERROR )
35 return false;
38 //If everything initialized
39 return true;
42 Game::Game()
45 //Initialize SDL
46 if( SDL_Init( SDL_INIT_EVERYTHING ) < 0 )
48 //erro
51 //Create Window
52 if( SDL_SetVideoMode( SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_OPENGL ) == NULL )
54 //erro
57 //Initialize OpenGL
58 if( init_GL() == false )
60 //erro
63 //Set caption
64 SDL_WM_SetCaption( "Prototipo Jogo", NULL );
68 void Game::show() {
69 glClear( GL_COLOR_BUFFER_BIT );
70 std::vector<Linha>::iterator it;
71 for (it = mapa.begin(); it != mapa.end(); it++)
72 it->desenha();
73 glPushMatrix();
74 glTranslatef(300,300,0);
75 drawCircle(20,30);
76 glPopMatrix();
77 SDL_GL_SwapBuffers();
80 void Game::update(){
85 void Game::mainLoop() {
86 luaRun luaEnv;
87 luaEnv.registerScripts();
88 luaEnv.loadScripts();
89 mapa = geraMapa(20);
90 mapa.push_back(chao);
91 Timer fps;
92 SDL_Event event;
93 bool quit = false;
94 while (!quit) {
95 fps.start();
96 while( SDL_PollEvent( &event ) )
98 if( event.type == SDL_QUIT )
100 quit = true;
103 show();
104 if (fps.get_ticks() < 1000 / FRAMES_PER_SECOND ) {
105 SDL_Delay( ( 1000 / FRAMES_PER_SECOND ) - fps.get_ticks() );