[pandngdc] [commit] r348 - trunk/src

  • From: nicholas.samuel@xxxxxxxxx
  • To: pandngdc@xxxxxxxxxxxxx
  • Date: Thu, 25 Jun 2009 07:51:59 +0930

Author: enetheru
Date: Thu Jun 25 07:51:57 2009
New Revision: 348

Log:
alot of whitespace fixups in menu and testing, re-created a base class for use, 
added environment class for backgrounds, added healthbar class. all of thin 
work is still in the testing screen until it matures past the point that the 
gurrent game is.

Added:
   trunk/src/environment.cpp
   trunk/src/environment.h
   trunk/src/healthbar.cpp
   trunk/src/healthbar.h
   trunk/src/newobject.cpp
   trunk/src/newobject.h
   trunk/src/newplayer.cpp
   trunk/src/newplayer.h
Modified:
   trunk/src/Makefile.am
   trunk/src/menu.cpp
   trunk/src/testing.cpp
   trunk/src/testing.h
   trunk/src/util.cpp

Modified: trunk/src/Makefile.am
==============================================================================
--- trunk/src/Makefile.am       Sun Jun  7 13:48:46 2009        (r347)
+++ trunk/src/Makefile.am       Thu Jun 25 07:51:57 2009        (r348)
@@ -1,12 +1,17 @@
 bin_PROGRAMS = pvn
-pvn_SOURCES = main.cpp \
-                         game.cpp \
-                         menu.cpp \
-                         credits.cpp \
-                         fight.cpp \
-                         vector2f.cpp \
-                         object.cpp \
-                         util.cpp \
-              testing.cpp \
-                         settings.cpp \
-                         player.cpp 
+pvn_SOURCES = \
+       main.cpp \
+       game.cpp \
+       menu.cpp \
+       credits.cpp \
+       fight.cpp \
+       vector2f.cpp \
+       object.cpp \
+       util.cpp \
+       testing.cpp \
+       settings.cpp \
+       player.cpp \
+       newobject.cpp \
+       newplayer.cpp \
+       environment.cpp \
+       healthbar.cpp

Added: trunk/src/environment.cpp
==============================================================================
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ trunk/src/environment.cpp   Thu Jun 25 07:51:57 2009        (r348)
@@ -0,0 +1,91 @@
+#include "environment.h"
+
+PVN_Environment::PVN_Environment()
+{
+       foreground = NULL;
+       return;
+}
+
+PVN_Environment::~PVN_Environment()
+{
+       SDL_FreeSurface(foreground);
+       return;
+}
+
+void PVN_Environment::SetGravity(float arg_gravity)
+{
+       gravity = arg_gravity;
+       return;
+}
+
+void PVN_Environment::SetFloor(int arg_floor)
+{
+       floor = arg_floor;
+       return;
+}
+
+void PVN_Environment::SetLeftWall(int arg_leftwall)
+{
+       leftwall = arg_leftwall;
+       return;
+}
+
+void PVN_Environment::SetRightWall(int arg_rightwall)
+{
+       rightwall = arg_rightwall;
+       return;
+}
+
+void PVN_Environment::SetForeground(SDL_Surface *arg_image)
+{
+       foreground = arg_image;
+       return;
+}
+
+void PVN_Environment::SetBackground(SDL_Surface *arg_image)
+{
+       SetImage(arg_image);
+       return;
+}
+
+float PVN_Environment::GetGravity()
+{
+       return gravity;
+}
+
+int PVN_Environment::GetFloor()
+{
+       return floor;
+}
+
+int PVN_Environment::GetLeftWall()
+{
+       return leftwall;
+}
+
+int PVN_Environment::GetRightWall()
+{
+       return rightwall;
+}
+
+SDL_Surface *PVN_Environment::GetBackground()
+{
+       return GetImage();
+}
+
+SDL_Surface *PVN_Environment::GetForeground()
+{
+       return foreground;
+}
+
+void PVN_Environment::BlitForeground(SDL_Surface *arg_destination)
+{
+       SDL_BlitSurface(GetForeground(), GetFrame(), arg_destination, 
GetPosition());
+       return;
+}
+
+void PVN_Environment::BlitBackground(SDL_Surface *arg_destination)
+{
+       Blit(arg_destination);
+       return;
+}

Added: trunk/src/environment.h
==============================================================================
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ trunk/src/environment.h     Thu Jun 25 07:51:57 2009        (r348)
@@ -0,0 +1,32 @@
+#ifndef PVN_ENVIRONMENT_H
+#define PVN_ENVIRONMENT_H
+
+#include "common.h"
+#include "newobject.h"
+
+class PVN_Environment : public PVN_Object
+{
+       private:
+               SDL_Surface *foreground;
+               float gravity;
+               int floor, leftwall, rightwall;
+       public:
+       PVN_Environment();
+       ~PVN_Environment();
+       void SetGravity(float);
+       void SetFloor(int);
+       void SetLeftWall(int);
+       void SetRightWall(int);
+       void SetForeground(SDL_Surface *);
+       void SetBackground(SDL_Surface *);
+       float GetGravity();
+       int GetFloor();
+       int GetLeftWall();
+       int GetRightWall();
+       SDL_Surface *GetForeground();
+       SDL_Surface *GetBackground();
+       void BlitBackground(SDL_Surface *);
+       void BlitForeground(SDL_Surface *);
+};
+
+#endif /*PVN_ENVIRONMENT_H*/

Added: trunk/src/healthbar.cpp
==============================================================================
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ trunk/src/healthbar.cpp     Thu Jun 25 07:51:57 2009        (r348)
@@ -0,0 +1,74 @@
+#include "healthbar.h"
+
+PVN_HealthBar::PVN_HealthBar()
+{
+       max = 100;
+       current = 100;
+       return;
+}
+
+PVN_HealthBar::~PVN_HealthBar()
+{
+       return;
+}
+
+void PVN_HealthBar::SetMax(int arg_max)
+{
+       max = arg_max;
+       return;
+}
+
+void PVN_HealthBar::SetCurrent(int arg_current)
+{
+       current = arg_current;
+       return;
+}
+
+int PVN_HealthBar::GetMax()
+{
+       return max;
+}
+
+int PVN_HealthBar::GetCurrent()
+{
+       return current;
+}
+
+void PVN_HealthBar::Init()
+{
+       if( GetFrame() == NULL )
+       {
+               SetFrame(new SDL_Rect);
+               GetFrame()->x = GetFrame()->y = 0;
+               GetFrame()->w = GetImage()->w;
+               GetFrame()->h = GetImage()->h;
+       }
+       if( GetPosition() == NULL )
+       {
+               SetPosition(new SDL_Rect);
+               GetPosition()->x = GetPosition()->y = 0;
+               GetPosition()->w = GetImage()->w;
+               GetPosition()->h = GetImage()->h;
+       }       
+       return;
+}
+
+void PVN_HealthBar::Add(int arg_value)
+{
+       current += arg_value;
+       return;
+}
+
+void PVN_HealthBar::ReCalc()
+{
+       if(current > 0 && current < max)
+       {
+               float percent = (float)current / (float)max;
+               GetFrame()->w = (int)((float)GetImage()->w * percent);
+       }
+       else if( current <=0 ) GetFrame()->w = 0;
+       else GetFrame()->w = GetImage()->w;
+               
+       return;
+}
+       

Added: trunk/src/healthbar.h
==============================================================================
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ trunk/src/healthbar.h       Thu Jun 25 07:51:57 2009        (r348)
@@ -0,0 +1,23 @@
+#ifndef PVN_HEALTHBAR_H
+#define PVN_HEALTHBAR_H
+
+#include "common.h"
+#include "newobject.h"
+
+class PVN_HealthBar : public PVN_Object
+{
+       private:
+               int max, current;
+       public:
+               PVN_HealthBar();
+               ~PVN_HealthBar();
+               void SetMax(int);
+               void SetCurrent(int);
+               int GetMax();
+               int GetCurrent();
+               void Init();
+               void Add(int);
+               void ReCalc();
+};
+
+#endif /*PVN_HEALTHBAR_H*/

Modified: trunk/src/menu.cpp
==============================================================================
--- trunk/src/menu.cpp  Sun Jun  7 13:48:46 2009        (r347)
+++ trunk/src/menu.cpp  Thu Jun 25 07:51:57 2009        (r348)
@@ -189,7 +189,7 @@
                        {
                                case SDLK_ESCAPE:
                                        return NULL;
-                        case SDLK_KP_ENTER:
+                               case SDLK_KP_ENTER:
                                case SDLK_RETURN:
                                        switch (menu_state)
                                        {
@@ -231,10 +231,9 @@
                                        break;
                                case SDLK_UP:
                                        if( menu_state > 0 )
-                               {
+                                       {
                                                Mix_PlayChannel(1, 
menu_effect[3], 0);
-                               }
-
+                                       }
                                        switch( menu_state )
                                        {
                                                case FIGHT_SELECTED:
@@ -288,9 +287,9 @@
                                                redraw_required = true;
                                        }
                                        break;
-                        case SDLK_t:
+                               case SDLK_t:
                                case SDLK_F11:
-                                       //arg_game->State_Change(PVN_TEST);
+                                       return new PVN_test(game);
                                        break;
                                case SDLK_F12:
                                        redraw_required = true;

Added: trunk/src/newobject.cpp
==============================================================================
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ trunk/src/newobject.cpp     Thu Jun 25 07:51:57 2009        (r348)
@@ -0,0 +1,53 @@
+#include "newobject.h"
+
+PVN_Object::PVN_Object()
+{
+       image = NULL;
+       frame = NULL;
+       position = NULL;
+       return;
+}
+
+PVN_Object::~PVN_Object()
+{
+       SDL_FreeSurface(image); image = NULL;
+       delete frame; frame = NULL;
+       delete position; position = NULL;
+       return;
+}
+
+void PVN_Object::SetImage(SDL_Surface *arg_surface)
+{
+       image = arg_surface;
+}
+
+void PVN_Object::SetFrame(SDL_Rect *arg_rect)
+{
+       frame = arg_rect;
+}
+
+void PVN_Object::SetPosition(SDL_Rect *arg_rect)
+{
+       position = arg_rect;
+}
+
+SDL_Surface *PVN_Object::GetImage()
+{
+       return image;
+}
+
+SDL_Rect *PVN_Object::GetFrame()
+{
+       return frame;
+}
+
+SDL_Rect *PVN_Object::GetPosition()
+{
+       return position;
+}
+
+void PVN_Object::Blit(SDL_Surface *arg_destination)
+{
+       SDL_BlitSurface(GetImage(), GetFrame(), arg_destination, GetPosition());
+       return;
+}

Added: trunk/src/newobject.h
==============================================================================
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ trunk/src/newobject.h       Thu Jun 25 07:51:57 2009        (r348)
@@ -0,0 +1,24 @@
+#ifndef PVN_NEWOBJECT_H
+#define PVN_NEWOBJECT_H
+
+#include "common.h"
+
+class PVN_Object
+{
+       private:
+               SDL_Surface *image;
+               SDL_Rect *frame, *position;
+       public:
+               PVN_Object();
+               PVN_Object(SDL_Surface *, SDL_Rect *, SDL_Rect *);
+               ~PVN_Object();
+               void SetImage(SDL_Surface *);
+               void SetFrame(SDL_Rect *);
+               void SetPosition(SDL_Rect *);
+               SDL_Surface *GetImage();
+               SDL_Rect *GetFrame();
+               SDL_Rect *GetPosition();
+               void Blit(SDL_Surface *);       
+};
+
+#endif /*PVN_NEWOBJECT_H*/

Added: trunk/src/newplayer.cpp
==============================================================================
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ trunk/src/newplayer.cpp     Thu Jun 25 07:51:57 2009        (r348)
@@ -0,0 +1,73 @@
+#include "common.h"
+#include "newplayer.h"
+
+PVN_Player::PVN_Player()
+{
+       health = jumpheight = runspeed = attackpower = 0;
+       return;
+}
+
+PVN_Player::PVN_Player(PVN_Object *arg_object,
+       int arg_health,
+       int arg_jumpheight,
+       int arg_runspeed,
+       int arg_attackpower)
+{
+       SetImage(arg_object->GetImage());
+       SetFrame(arg_object->GetFrame());
+       SetPosition(arg_object->GetPosition());
+       health = arg_health;
+       jumpheight = arg_jumpheight;
+       runspeed = arg_runspeed;
+       arg_attackpower = attackpower;
+       return;
+}
+
+PVN_Player::~PVN_Player()
+{
+       return;
+}
+
+void PVN_Player::SetHealth(int arg_health)
+{
+       health = arg_health;
+       return;
+}
+
+void PVN_Player::SetJumpHeight(int arg_jumpheight)
+{
+       jumpheight = arg_jumpheight;
+       return;
+}
+
+void PVN_Player::SetRunSpeed(int arg_runspeed)
+{
+       runspeed = arg_runspeed;
+       return;
+}
+
+void PVN_Player::SetAttackPower(int arg_attackpower)
+{
+       attackpower = arg_attackpower;
+       return;
+}
+
+int PVN_Player::GetHealth()
+{
+       return health;
+}
+
+int PVN_Player::GetJumpHeight()
+{
+       return jumpheight;
+}
+
+int PVN_Player::GetRunSpeed()
+{
+       return runspeed;
+}
+
+int PVN_Player::GetAttackPower()
+{
+       return attackpower;
+}

Added: trunk/src/newplayer.h
==============================================================================
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ trunk/src/newplayer.h       Thu Jun 25 07:51:57 2009        (r348)
@@ -0,0 +1,23 @@
+#ifndef PVN_NEWPLAYER_H
+#define PVN_NEWPLAYER_H
+
+#include "newobject.h"
+
+class PVN_Player : public PVN_Object
+{
+       private:
+               int health, jumpheight, runspeed, attackpower;
+       public:
+               PVN_Player();
+               PVN_Player(PVN_Object *, int, int, int, int);
+               ~PVN_Player();
+               void SetHealth(int);
+               void SetJumpHeight(int);
+               void SetRunSpeed(int);
+               void SetAttackPower(int);
+               int GetHealth();
+               int GetJumpHeight();
+               int GetRunSpeed();
+               int GetAttackPower();
+};
+#endif /*PVN_NEWPLAYER_H*/

Modified: trunk/src/testing.cpp
==============================================================================
--- trunk/src/testing.cpp       Sun Jun  7 13:48:46 2009        (r347)
+++ trunk/src/testing.cpp       Thu Jun 25 07:51:57 2009        (r348)
@@ -5,43 +5,35 @@
 PVN_test::PVN_test(PVN_game* game) : PVN_state(game)
 {
        for( int i = 0; i < 323; i++) keys_held[i] = false;
+       environment1 = new PVN_Environment;
+       environment1->SetBackground(Image_Load("../data/images/dunes.png"));
+       environment1->SetForeground(Image_Load("../data/images/palm.png"));
+       
        player1 = new Player(100,100,128,128,500,200);
-       player2 = new Player(600,100,128,128,500,200);
-
-       drect = new SDL_Rect;
-       drect->h = 0;
-       drect->w = 0;
-       drect->x = 0;
-       drect->y = 0;
-
-       srect = new SDL_Rect;
-       srect->h = 80;
-       srect->w = 360;
-       srect->x = 0;
-       srect->y = 0;
-
-       temp = Image_Load("../data/images/background.png");
-       background = SDL_DisplayFormatAlpha(temp);
+       healthbar1 = new PVN_HealthBar;
+       
healthbar1->SetImage(Image_Load("../data/images/tubereflectionssex.png"));
+       healthbar1->SetMax(100);
+       healthbar1->SetCurrent(100);
+       healthbar1->Init();
+       healthbar1->ReCalc();
 
-       temp = Image_Load("../data/images/tubereflectionssex.png");
-       healthbar_p1 = SDL_DisplayFormatAlpha(temp);
-
-       temp = Image_Load("../data/images/tubereflectionssex.png");
-       healthbar_p2 = SDL_DisplayFormatAlpha(temp);
+       player2 = new Player(600,100,128,128,500,200);
+       healthbar2 = new PVN_HealthBar;
+       
healthbar2->SetImage(Image_Load("../data/images/tubereflectionssex.png"));
+       healthbar2->SetMax(100);
+       healthbar2->SetCurrent(100);
+       healthbar2->Init();
+       healthbar2->GetPosition()->x = 300;
+       healthbar2->ReCalc();
 }
 
 PVN_test::~PVN_test()
 {
-       SDL_FreeSurface(background);
-       SDL_FreeSurface(healthbar_p1);
-       SDL_FreeSurface(healthbar_p2);
-
        delete player1;
        delete player2;
-
-       delete drect;
-       delete srect;
-
+       delete healthbar1;
+       delete healthbar2;
+       delete environment1;
        return;
 }
 
@@ -53,52 +45,52 @@
 {
        SDL_Event event;
 
-       while (SDL_PollEvent(&event))
+       while( SDL_PollEvent(&event) )
        {
-               if (event.type == SDL_KEYDOWN)
+               if( event.type == SDL_KEYDOWN )
                {
-                       switch (event.key.keysym.sym)
+                       switch( event.key.keysym.sym )
                        {
-                       case SDLK_ESCAPE: return new PVN_menu(game);
-                       /***********
-               * Player 1 *
-               ***********/
-               //movement
-               case SDLK_w:                    keys_held[SDLK_w]               
= true; break;
-               case SDLK_d:                    keys_held[SDLK_d]               
= true; break;
-               case SDLK_a:                    keys_held[SDLK_a]               
= true; break;
-               case SDLK_s:                    keys_held[SDLK_s]               
= true; break;
-                       //actions
-               case SDLK_LCTRL:        keys_held[SDLK_LCTRL]   = true; break;
-               case SDLK_LSHIFT: keys_held[SDLK_LSHIFT] = true; break;
-               /***********
-               * Player 2 *
-               ***********/
-               //movement
-                       case SDLK_UP:            keys_held[SDLK_UP]             
= true; break;
-                       case SDLK_DOWN:  keys_held[SDLK_DOWN]   = true; break;
-               case SDLK_LEFT:  keys_held[SDLK_LEFT]   = true; break;
-               case SDLK_RIGHT:        keys_held[SDLK_RIGHT] = true; break;
-                       //actions
-               case SDLK_RCTRL:        keys_held[SDLK_RCTRL]   = true; break;
-               case SDLK_RSHIFT: keys_held[SDLK_RSHIFT] = true; break;
-                       default:break;
+                               case SDLK_ESCAPE: return new PVN_menu(game);
+                               /***********
+                               * Player 1 *
+                               ***********/
+                               //movement
+                               case SDLK_w:      keys_held[SDLK_w]      = 
true; break;
+                               case SDLK_d:      keys_held[SDLK_d]      = 
true; break;
+                               case SDLK_a:      keys_held[SDLK_a]      = 
true; break;
+                               case SDLK_s:      keys_held[SDLK_s]      = 
true; break;
+                               //actions
+                               case SDLK_LCTRL:  keys_held[SDLK_LCTRL]  = 
true; break;
+                               case SDLK_LSHIFT: keys_held[SDLK_LSHIFT] = 
true; break;
+                               /***********
+                               * Player 2 *
+                               ***********/
+                               //movement
+                               case SDLK_UP:     keys_held[SDLK_UP]     = 
true; break;
+                               case SDLK_DOWN:   keys_held[SDLK_DOWN]   = 
true; break;
+                               case SDLK_LEFT:   keys_held[SDLK_LEFT]   = 
true; break;
+                               case SDLK_RIGHT:  keys_held[SDLK_RIGHT]  = 
true; break;
+                               //actions
+                               case SDLK_RCTRL:  keys_held[SDLK_RCTRL]  = 
true; break;
+                               case SDLK_RSHIFT: keys_held[SDLK_RSHIFT] = 
true; break;
+                               default:break;
                        }
                }
                else if(event.type == SDL_KEYUP)
                {
                        switch (event.key.keysym.sym)
                        {
-               case SDLK_w:             keys_held[SDLK_w]               = 
false; break;
-               case SDLK_d:             keys_held[SDLK_d]               = 
false; break;
-               case SDLK_a:             keys_held[SDLK_a]               = 
false; break;
-               case SDLK_s:             keys_held[SDLK_s]       = false; break;
-
-                       case SDLK_UP:           keys_held[SDLK_UP]              
= false; break;
-                       case SDLK_DOWN: keys_held[SDLK_DOWN]    = false; break;
-               case SDLK_LEFT: keys_held[SDLK_LEFT]    = false; break;
-               case SDLK_RIGHT: keys_held[SDLK_RIGHT] = false; break;
-                       default: break;
+                               case SDLK_w:      keys_held[SDLK_w]      = 
false; break;
+                               case SDLK_d:      keys_held[SDLK_d]      = 
false; break;
+                               case SDLK_a:      keys_held[SDLK_a]      = 
false; break;
+                               case SDLK_s:      keys_held[SDLK_s]      = 
false; break;
+
+                               case SDLK_UP:     keys_held[SDLK_UP]     = 
false; break;
+                               case SDLK_DOWN:   keys_held[SDLK_DOWN]   = 
false; break;
+                               case SDLK_LEFT:   keys_held[SDLK_LEFT]   = 
false; break;
+                               case SDLK_RIGHT:  keys_held[SDLK_RIGHT]  = 
false; break;
+                               default: break;
                        }
                }
        }
@@ -111,72 +103,78 @@
 
 void PVN_test::Logic()
 {
-       if (player1->dead == false)
+       if( player1->dead == false )
        {
-               if (keys_held[SDLK_d] == true) player1->RunRight();
-               if (keys_held[SDLK_a] == true) player1->RunLeft();
-               if (keys_held[SDLK_w] == true) player1->Jump();         
-
-               if ((keys_held[SDLK_d] == false) && (keys_held[SDLK_a] == 
false) && (keys_held[SDLK_w] == false)) player1->IdleItUp();
+               if( keys_held[SDLK_d] == true )player1->RunRight();
+               if( keys_held[SDLK_a] == true )player1->RunLeft();
+               if( keys_held[SDLK_w] == true )player1->Jump();         
+
+               if( (keys_held[SDLK_d] == false) &&
+                   (keys_held[SDLK_a] == false) &&
+                   (keys_held[SDLK_w] == false)
+                 )player1->IdleItUp();
        }
 
-       if (player2->dead == false)
+       if( player2->dead == false )
        {
-               if (keys_held[SDLK_RIGHT] == true) player2->RunRight();
-               if (keys_held[SDLK_LEFT] == true) player2->RunLeft();
-               if (keys_held[SDLK_UP] == true) player2->Jump();                
         
-
-               if ((keys_held[SDLK_RIGHT] == false) && (keys_held[SDLK_LEFT] 
== false) && (keys_held[SDLK_UP] == false)) player2->IdleItUp();
+               if( keys_held[SDLK_RIGHT] == true) player2->RunRight();
+               if( keys_held[SDLK_LEFT]  == true) player2->RunLeft();
+               if( keys_held[SDLK_UP]    == true) player2->Jump();
+//             if( keys_held[SDLK_DOWN]  == true)
+
+               if( (keys_held[SDLK_RIGHT] == false) &&
+                   (keys_held[SDLK_LEFT]  == false) &&
+                   (keys_held[SDLK_UP]    == false)
+                 )player2->IdleItUp();
        }
 
-       if (Check_Collision(player1->hitbox_body, player2->hitbox_body) == true 
&& player1->dead == false && player2->dead == false)
+       if( Check_Collision(player1->hitbox_body, player2->hitbox_body) == true 
&&
+           player1->dead == false &&
+           player2->dead == false )
        {
                if (hasHit == false)
                {
-                       if (abs((int)player1->yVel) > abs((int)player2->yVel)) 
player2->health -= 10;
-                       if (abs((int)player2->yVel) > abs((int)player1->yVel)) 
player1->health -= 10;
+                       if( abs((int)player1->yVel) > abs((int)player2->yVel) )
+                       {
+                               player2->health -= 10;
+                               healthbar2->Add(-10);
+                               healthbar2->ReCalc();
+                       }
+                               
+                       if( abs((int)player2->yVel) > abs((int)player1->yVel) )
+                       {
+                               player1->health -= 10;
+                               healthbar1->Add(-10);
+                               healthbar1->ReCalc();
+                       }
 
-                       if (player1->health <= 0) player1->Die();
-                       if (player2->health <= 0) player2->Die();
+                       if( player1->health <= 0 )player1->Die();
+                       if( player2->health <= 0 )player2->Die();
 
                        player1->yVel = -player1->yVel;
                        player2->yVel = -player2->yVel;
 
                        hasHit = true;
                }
-               if (player1->xPos < player2->xPos)
+               if( player1->xPos < player2->xPos )
                {
-                       if (keys_held[SDLK_a] == true) 
-                       {
-                               player1->RunLeft();
-                       } else {
-                               player1->xVel = -1;
-                       }
-                       if (keys_held[SDLK_RIGHT] == true) 
-                       {
-                               player2->RunRight();
-                       } else {
-                               player2->xVel = 1;
-                       }               
-               } else {
-                       if (keys_held[SDLK_d] == true) 
-                       {
-                               player1->RunRight();
-                       } else {
-                               player1->xVel = 1;
-                       }
-                       if (keys_held[SDLK_LEFT] == true) 
-                       {
-                               player2->RunLeft();
-                       } else {
-                               player2->xVel = -1;             
-                       }
-                       
+                       if( keys_held[SDLK_a] == true )player1->RunLeft();
+                       else player1->xVel = -1;
+
+                       if( keys_held[SDLK_RIGHT] == true )player2->RunRight();
+                       else player2->xVel = 1; 
+               }
+               else
+               {
+                       if( keys_held[SDLK_d] == true )player1->RunRight();
+                       else player1->xVel = 1;
+
+                       if( keys_held[SDLK_LEFT] == true )player2->RunLeft();
+                       else player2->xVel = -1;
                }
 
-       } else {
-               hasHit = false;
        }
+       else hasHit = false;
 
        player1->FrameMove(game);
        player2->FrameMove(game);
@@ -184,37 +182,10 @@
 
 void PVN_test::Draw()
 {
-       SDL_BlitSurface(
-                       background,
-                       NULL,
-                       game->screen_surface,
-                       NULL
-               );
-
-       drect->x = 20;
-       drect->y = 20;
-
-       srect->w = (player1->health * 3.2);
-
-       SDL_BlitSurface(
-                       healthbar_p1,
-                       srect,
-                       game->screen_surface,
-                       drect
-               );
-
-       drect->x = 780 - (player2->health * 3.2);
-       drect->y = 20;
-
-       srect->w = (player2->health * 3.2);
-
-       SDL_BlitSurface(
-                       healthbar_p2,
-                       srect,
-                       game->screen_surface,
-                       drect
-               );
-
+       environment1->BlitBackground(game->screen_surface);
        player1->Draw(game->screen_surface);
        player2->Draw(game->screen_surface);
+       healthbar1->Blit(game->screen_surface);
+       healthbar2->Blit(game->screen_surface);
+       environment1->BlitForeground(game->screen_surface);
 }

Modified: trunk/src/testing.h
==============================================================================
--- trunk/src/testing.h Sun Jun  7 13:48:46 2009        (r347)
+++ trunk/src/testing.h Thu Jun 25 07:51:57 2009        (r348)
@@ -4,20 +4,19 @@
 #include "common.h"
 #include "game.h"
 #include "object.h"
+#include "newobject.h"
+#include "newplayer.h"
+#include "environment.h"
+#include "healthbar.h"
 #include "player.h"
 #include "state_template.h"
 
 class PVN_test: public PVN_state
 {
        private:
-               SDL_Surface *temp, 
-                                                               *background,
-                                                               *healthbar_p1,
-                                                               *healthbar_p2;
-
-               SDL_Rect blit, *drect, *srect;
-
                Player *player1, *player2;
+               PVN_HealthBar *healthbar1, *healthbar2;
+               PVN_Environment *environment1;
 
                bool keys_held[323];
                bool clean;

Modified: trunk/src/util.cpp
==============================================================================
--- trunk/src/util.cpp  Sun Jun  7 13:48:46 2009        (r347)
+++ trunk/src/util.cpp  Thu Jun 25 07:51:57 2009        (r348)
@@ -3,7 +3,7 @@
 
 SDL_Surface* Image_Load(const string arg_path)
 {
-       SDL_Surface *temp, *surface = NULL;
+       SDL_Surface *temp = NULL, *surface = NULL;
 
        temp=IMG_Load(arg_path.c_str());
        if(temp != NULL)

Other related posts:

  • » [pandngdc] [commit] r348 - trunk/src - nicholas . samuel