From 308e2d9cc93a708a837d3daa7f774902a1c8cbf5 Mon Sep 17 00:00:00 2001 From: andreferreira Date: Thu, 17 Dec 2009 23:54:03 -0200 Subject: [PATCH] Barra de vida pro jogador --- controlewii.cpp | 5 ++--- game.cpp | 21 +++++++++++++++++++++ player.cpp | 2 +- player.h | 1 + 4 files changed, 25 insertions(+), 4 deletions(-) diff --git a/controlewii.cpp b/controlewii.cpp index 391a8b7..b4a0d97 100644 --- a/controlewii.cpp +++ b/controlewii.cpp @@ -15,6 +15,7 @@ ControleWii::ControleWii(Player &p) : Controle(p) { } void ControleWii::handleOther() { + jogador.addSpeed(closerToZero(-jogador.getSpeedX(),sign(jogador.getSpeedX())*-0.5),0); if (jogador.dead) return; jogador.crawl = false; Uint8 *keystates = SDL_GetKeyState( NULL ); @@ -32,9 +33,7 @@ void ControleWii::handleOther() { } if (keystates[SDLK_RIGHT]) { jogador.addSpeed(3, 0); - } - if (!keystates[SDLK_RIGHT] && !keystates[SDLK_LEFT]) - jogador.addSpeed(closerToZero(-jogador.getSpeedX(),sign(jogador.getSpeedX())*-0.5),0); + } if(SDL_GetMouseState(NULL, NULL) & SDL_BUTTON(1)) { //botao esquerdo do mouse pressionado jogador.fire(); } diff --git a/game.cpp b/game.cpp index 7236e15..22a6df6 100755 --- a/game.cpp +++ b/game.cpp @@ -109,6 +109,27 @@ void Game::show() { mapa->desenha(); shotManager->desenha(); enemyManager->desenha(); + + double vida = std::max(0.0,player->hp/double(MAXHP)); + + glPushMatrix(); + glTranslatef(camera.x,camera.y,0); + glColor3f(0,0,0); + glBegin(GL_LINE_LOOP); + glVertex3f(10,10,0); + glVertex3f(50,10,0); + glVertex3f(50,500,0); + glVertex3f(10,500,0); + glEnd(); + glColor3f(1,0,0); + glBegin(GL_POLYGON); + glVertex3f(10+1,10+1,0); + glVertex3f(50-1,10+1,0); + glVertex3f(50-1,std::max(vida*(500-1)-1,10.0),0); + glVertex3f(10+1,std::max(vida*(500-1)-1,10.0),0); + glEnd(); + glColor3f(0,0,0); + glPopMatrix(); glMatrixMode( GL_PROJECTION ); glLoadIdentity(); diff --git a/player.cpp b/player.cpp index 568a6df..ca37d26 100755 --- a/player.cpp +++ b/player.cpp @@ -2,7 +2,7 @@ #include "shot.h" Player::Player(Game* agame, Ponto pos, Ponto speed): Shooter(agame, pos, speed) { - hp = 100; + hp = MAXHP; } void Player::desenha() { diff --git a/player.h b/player.h index 6f87da9..7a30b37 100755 --- a/player.h +++ b/player.h @@ -1,5 +1,6 @@ #ifndef PLAYER_H #define PLAYER_H +#define MAXHP 100 #include "game.h" #include "shooter.h" -- 2.11.4.GIT