From 1ba897158bda0d6116271ec08fad5e0a5e6ada98 Mon Sep 17 00:00:00 2001 From: El Saico Date: Mon, 12 Oct 2009 22:10:39 -0300 Subject: [PATCH] Criada classe Controle. --- Makefile | 1 + controle.cpp | 23 +++++++++++++++++++++++ controle.h | 17 +++++++++++++++++ game.cpp | 19 +++++++++---------- player.cpp | 8 +++++++- player.h | 1 + 6 files changed, 58 insertions(+), 11 deletions(-) create mode 100644 controle.cpp create mode 100644 controle.h diff --git a/Makefile b/Makefile index 2e0dd98..cc67012 100644 --- a/Makefile +++ b/Makefile @@ -6,6 +6,7 @@ OBJS = \ player.o \ game.o \ timer.o \ + controle.o \ SRCS = $(OBJS,.o=.cpp) diff --git a/controle.cpp b/controle.cpp new file mode 100644 index 0000000..7268f50 --- /dev/null +++ b/controle.cpp @@ -0,0 +1,23 @@ +#include "controle.h" + +Controle::Controle(Player p) { + +} + +void Controle::eventLoop() { + while( SDL_PollEvent( &e ) ) + { + switch( e.type ) + { + case SDL_QUIT: + quit = true; + break; + //case SDL_KEYDOWN: + //switch (event.keysym.sym: + } + } +} + +bool Controle::getQuit() { + return quit; +} diff --git a/controle.h b/controle.h new file mode 100644 index 0000000..65f6277 --- /dev/null +++ b/controle.h @@ -0,0 +1,17 @@ +#ifndef CONTROLE_H +#define CONTROLE_H + +#include "player.h" + +class Controle { + private: + Player jogador; + SDL_Event e; + bool quit; + public: + Controle(Player p); + void eventLoop(); + bool getQuit(); +}; + +#endif diff --git a/game.cpp b/game.cpp index 72e248b..3cd9db7 100644 --- a/game.cpp +++ b/game.cpp @@ -3,6 +3,8 @@ #include "plataformas.h" #include "luaenv.h" #include "timer.h" +#include "player.h" +#include "controle.h" const int SCREEN_WIDTH = 640; const int SCREEN_HEIGHT = 480; @@ -14,6 +16,7 @@ const double alturachao = 400.0; Linha chao(0.0,alturachao,SCREEN_WIDTH,alturachao); std::vector mapa; +Player jogador(SCREEN_WIDTH/2, SCREEN_HEIGHT/2); bool init_GL() { @@ -41,7 +44,7 @@ bool init_GL() Game::Game() { - + //Initialize SDL if( SDL_Init( SDL_INIT_EVERYTHING ) < 0 ) { @@ -67,6 +70,7 @@ Game::Game() void Game::show() { glClear( GL_COLOR_BUFFER_BIT ); + jogador.desenha(); std::vector::iterator it; for (it = mapa.begin(); it != mapa.end(); it++) it->desenha(); @@ -78,7 +82,7 @@ void Game::show() { } void Game::update(){ - + } @@ -89,17 +93,12 @@ void Game::mainLoop() { mapa = geraMapa(20); mapa.push_back(chao); Timer fps; - SDL_Event event; + //Controle c(Player(0, 0)); bool quit = false; while (!quit) { fps.start(); - while( SDL_PollEvent( &event ) ) - { - if( event.type == SDL_QUIT ) - { - quit = true; - } - } + c.eventLoop(); + quit = c.getQuit(); show(); if (fps.get_ticks() < 1000 / FRAMES_PER_SECOND ) { SDL_Delay( ( 1000 / FRAMES_PER_SECOND ) - fps.get_ticks() ); diff --git a/player.cpp b/player.cpp index f2c7b79..693720a 100644 --- a/player.cpp +++ b/player.cpp @@ -1,5 +1,11 @@ #include "player.h" -#include "geometry.h" + +Player::Player(int x, int y) { + posicao.x = x; + posicao.y = y; + velocidade.x = 0; + velocidade.y = 0; +} void Player::desenha() { glPushMatrix(); diff --git a/player.h b/player.h index ea57a6e..a546e7e 100644 --- a/player.h +++ b/player.h @@ -8,6 +8,7 @@ class Player { Ponto posicao; Vetor velocidade; public: + Player(int x, int y); void desenha(); }; -- 2.11.4.GIT