Lógica de movimentação (e continua o erro no construtor do Controle...)
[Projeto-PCG.git] / game.cpp
blobd40507fd25d17fd16a5c14e1c3b2143411bc4560
1 #include "game.h"
2 #include "geometry.h"
3 #include "plataformas.h"
4 #include "luaenv.h"
5 #include "timer.h"
6 #include "player.h"
7 #include "controle.h"
9 const int SCREEN_WIDTH = 640;
10 const int SCREEN_HEIGHT = 480;
11 const int SCREEN_BPP = 32;
12 const int FRAMES_PER_SECOND = 60;
15 const double alturachao = 400.0;
17 Linha chao(0.0,alturachao,SCREEN_WIDTH,alturachao);
18 std::vector<Linha> mapa;
19 Player jogador(SCREEN_WIDTH/2, SCREEN_HEIGHT/2);
21 bool init_GL()
23 //Set clear color
24 glClearColor( 1, 1, 1, 0 );
26 //Set projection
27 glMatrixMode( GL_PROJECTION );
28 glLoadIdentity();
29 glOrtho( 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, -1, 1 );
31 //Initialize modelview matrix
32 glMatrixMode( GL_MODELVIEW );
33 glLoadIdentity();
35 //If there was any errors
36 if( glGetError() != GL_NO_ERROR )
38 return false;
41 //If everything initialized
42 return true;
45 Game::Game()
48 //Initialize SDL
49 if( SDL_Init( SDL_INIT_EVERYTHING ) < 0 )
51 //erro
54 //Create Window
55 if( SDL_SetVideoMode( SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_OPENGL ) == NULL )
57 //erro
60 //Initialize OpenGL
61 if( init_GL() == false )
63 //erro
66 //Set caption
67 SDL_WM_SetCaption( "Prototipo Jogo", NULL );
71 void Game::show(Player jogador) {
72 glClear( GL_COLOR_BUFFER_BIT );
73 jogador.desenha();
74 std::vector<Linha>::iterator it;
75 for (it = mapa.begin(); it != mapa.end(); it++)
76 it->desenha();
77 glPushMatrix();
78 glTranslatef(300,300,0);
79 drawCircle(20,30);
80 glPopMatrix();
81 SDL_GL_SwapBuffers();
84 void Game::update(){
89 void Game::mainLoop() {
90 luaRun luaEnv;
91 luaEnv.registerScripts();
92 luaEnv.loadScripts();
93 mapa = geraMapa(20);
94 mapa.push_back(chao);
95 Timer fps;
96 Controle c(Player(0, 0));
97 bool quit = false;
98 while (!quit) {
99 fps.start();
100 c.eventLoop();
101 quit = c.getQuit();
102 show(c.getJogador());
103 if (fps.get_ticks() < 1000 / FRAMES_PER_SECOND ) {
104 SDL_Delay( ( 1000 / FRAMES_PER_SECOND ) - fps.get_ticks() );