[pandngdc] [commit] r352 - trunk/src

  • From: nicholas.samuel@xxxxxxxxx
  • To: pandngdc@xxxxxxxxxxxxx
  • Date: Sat, 27 Jun 2009 21:32:57 +0930

Author: enetheru
Date: Sat Jun 27 21:32:56 2009
New Revision: 352

Log:
moved alot of constructers to use initialisation lists, 
renamed Step() to Next() in grid class,
added animation.cpp to Makefile.am,
started postulating on a linked list class for PVN_Objects,
worked further on the new player class, adding a state class and nutting out 
some details on how it might be constructed,
added examples in testing game state

Modified:
   trunk/src/Makefile.am
   trunk/src/environment.cpp
   trunk/src/grid.cpp
   trunk/src/grid.h
   trunk/src/healthbar.cpp
   trunk/src/newobject.cpp
   trunk/src/newobject.h
   trunk/src/newplayer.cpp
   trunk/src/newplayer.h
   trunk/src/testing.cpp
   trunk/src/testing.h

Modified: trunk/src/Makefile.am
==============================================================================
--- trunk/src/Makefile.am       Sat Jun 27 21:25:48 2009        (r351)
+++ trunk/src/Makefile.am       Sat Jun 27 21:32:56 2009        (r352)
@@ -15,4 +15,5 @@
        newplayer.cpp \
        environment.cpp \
        healthbar.cpp \
-       grid.cpp
+       grid.cpp \
+       animation.cpp

Modified: trunk/src/environment.cpp
==============================================================================
--- trunk/src/environment.cpp   Sat Jun 27 21:25:48 2009        (r351)
+++ trunk/src/environment.cpp   Sat Jun 27 21:32:56 2009        (r352)
@@ -1,8 +1,8 @@
 #include "environment.h"
 
-PVN_Environment::PVN_Environment()
+PVN_Environment::PVN_Environment() :
+       foreground(NULL)
 {
-       foreground = NULL;
        return;
 }
 

Modified: trunk/src/grid.cpp
==============================================================================
--- trunk/src/grid.cpp  Sat Jun 27 21:25:48 2009        (r351)
+++ trunk/src/grid.cpp  Sat Jun 27 21:32:56 2009        (r352)
@@ -1,16 +1,13 @@
 #include "common.h"
 #include "grid.h"
 
-PVN_Grid::PVN_Grid()
+PVN_Grid::PVN_Grid() :
+       index(1), hdiv(4), vdiv(4)
 {
-       SetImage(SDL_CreateRGBSurface(SDL_SWSURFACE,512,512,32,0,0,0,1));
        SetFrame(new SDL_Rect);
        SetPosition(new SDL_Rect);
+       SetImage(SDL_CreateRGBSurface(SDL_SWSURFACE,512,512,32,0,0,0,1));
        GetFrame()->x = GetFrame()->y = 0;
-       GetFrame()->w = GetFrame()->h = 128;
-       index = 1;
-       end = 16;
-       hdiv = vdiv = 4;
        return;
 }
 
@@ -19,22 +16,9 @@
        return;
 }
 
-void PVN_Grid::SetEnd(int arg_value)
-{
-       if( arg_value > hdiv * vdiv ) end = hdiv * vdiv;
-       else if( arg_value <= 1 ) end = 2;
-       else end = arg_value;
-       return;
-}
-
-int PVN_Grid::GetEnd()
-{
-       return end;
-}
-
 void PVN_Grid::SetIndex(int arg_value)
 {
-       if( arg_value > end ) index = end;
+       if( arg_value > hdiv * vdiv ) index = hdiv * vdiv;
        else if( arg_value < 1 ) index = 1;
        else index = arg_value;
        return;
@@ -77,11 +61,18 @@
 }
        
 
-int PVN_Grid::Step()
+int PVN_Grid::Next()
 {
        index++;
-       if( index > end) index = 1;
+       if( index > hdiv * vdiv) index = 1;
        GetFrame()->x = (index-1) % hdiv * (GetImage()->w / hdiv);
        GetFrame()->y = (index-1) / vdiv * (GetImage()->h / vdiv);
        return index;
 }
+
+void PVN_Grid::SetImage(SDL_Surface *arg_surface)
+{
+       PVN_Object::SetImage(arg_surface);
+       Reset();
+       return;
+}

Modified: trunk/src/grid.h
==============================================================================
--- trunk/src/grid.h    Sat Jun 27 21:25:48 2009        (r351)
+++ trunk/src/grid.h    Sat Jun 27 21:32:56 2009        (r352)
@@ -6,15 +6,16 @@
 class PVN_Grid : public PVN_Object
 {
        private:
-               int end, index, hdiv, vdiv;
+               int index, hdiv, vdiv;
        public:
                PVN_Grid();
                ~PVN_Grid();
-               void SetEnd(int);                       int GetEnd();
                void SetIndex(int);             int GetIndex();
                void SetHDiv(int);              int GetHDiv();
                void SetVDiv(int);              int GetVDiv();
                void Reset();
-               int Step();
+               int Next();
+               int Prev();
+               void SetImage(SDL_Surface *);
 };
 #endif /*PVN_GRID_H*/

Modified: trunk/src/healthbar.cpp
==============================================================================
--- trunk/src/healthbar.cpp     Sat Jun 27 21:25:48 2009        (r351)
+++ trunk/src/healthbar.cpp     Sat Jun 27 21:32:56 2009        (r352)
@@ -1,6 +1,7 @@
 #include "healthbar.h"
 
-PVN_HealthBar::PVN_HealthBar()
+PVN_HealthBar::PVN_HealthBar() :
+       max(100), current(100), newposition(NULL)
 {
        SetImage(SDL_CreateRGBSurface(SDL_SWSURFACE,64,64,32,0,0,0,0));
        SetFrame(new SDL_Rect);
@@ -11,8 +12,6 @@
        GetFrame()->w = GetImage()->w;
        GetFrame()->h = GetImage()->h;
        SetPosition2i(0,0);
-       max = 100;
-       current = 100;
        return;
 }
 

Modified: trunk/src/newobject.cpp
==============================================================================
--- trunk/src/newobject.cpp     Sat Jun 27 21:25:48 2009        (r351)
+++ trunk/src/newobject.cpp     Sat Jun 27 21:32:56 2009        (r352)
@@ -1,10 +1,9 @@
 #include "newobject.h"
 
-PVN_Object::PVN_Object()
+PVN_Object::PVN_Object() :
+       image(NULL), frame(NULL), position(NULL)
 {
-       image = NULL;
-       frame = NULL;
-       position = NULL;
+       SetImage(SDL_CreateRGBSurface(SDL_SWSURFACE,64,64,32,0,0,0,1));
        return;
 }
 
@@ -20,27 +19,28 @@
 {
        SDL_FreeSurface(image);
        image = arg_surface;
+       return;
 }
 
 void PVN_Object::SetFrame(SDL_Rect *arg_rect)
 {
        delete frame;
        frame = arg_rect;
+       return;
 }
 
 void PVN_Object::SetPosition(SDL_Rect *arg_rect)
 {
        delete position;
        position = arg_rect;
+       return;
 }
 
 void PVN_Object::SetPosition2i(int arg_x, int arg_y)
 {
-       if(position != NULL)
-       {
-               position->x = arg_x;
-               position->y = arg_y;
-       }
+       if(position == NULL) position = new SDL_Rect;
+       position->x = arg_x;
+       position->y = arg_y;
        return;
 }
 

Modified: trunk/src/newobject.h
==============================================================================
--- trunk/src/newobject.h       Sat Jun 27 21:25:48 2009        (r351)
+++ trunk/src/newobject.h       Sat Jun 27 21:32:56 2009        (r352)
@@ -22,4 +22,15 @@
                void Blit(SDL_Surface *);       
 };
 
+/*
+class PVN_ObjectList
+{
+       PVN_ObjectList();
+       ~PVN_ObjectList();
+       PVN_Object *object;
+       PVN_ObjectList *nextobject, *lastobject;
+       AddObject(PVN_Object *);
+       PVN_Object *NextObject();
+};
+*/
 #endif /*PVN_NEWOBJECT_H*/

Modified: trunk/src/newplayer.cpp
==============================================================================
--- trunk/src/newplayer.cpp     Sat Jun 27 21:25:48 2009        (r351)
+++ trunk/src/newplayer.cpp     Sat Jun 27 21:32:56 2009        (r352)
@@ -1,9 +1,12 @@
 #include "common.h"
 #include "newplayer.h"
 
-PVN_Player::PVN_Player()
+PVN_Player::PVN_Player() :
+       health(0), attackpower(0),
+       currentstate(NULL), states(NULL)
 {
-       health = jumpheight = runspeed = attackpower = 0;
+/* load all the states into memory */
+/* set the current state to idle at start */
        return;
 }
 
@@ -18,18 +21,6 @@
        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;
@@ -41,16 +32,6 @@
        return health;
 }
 
-int PVN_Player::GetJumpHeight()
-{
-       return jumpheight;
-}
-
-int PVN_Player::GetRunSpeed()
-{
-       return runspeed;
-}
-
 int PVN_Player::GetAttackPower()
 {
        return attackpower;

Modified: trunk/src/newplayer.h
==============================================================================
--- trunk/src/newplayer.h       Sat Jun 27 21:25:48 2009        (r351)
+++ trunk/src/newplayer.h       Sat Jun 27 21:32:56 2009        (r352)
@@ -2,21 +2,35 @@
 #define PVN_NEWPLAYER_H
 
 #include "newobject.h"
+#include "animation.h"
+
+class PVN_PlayerState;
 
 class PVN_Player : public PVN_Object
 {
        private:
-               int health, jumpheight, runspeed, attackpower;
+               int health, attackpower;
+               PVN_PlayerState **states;
+               PVN_PlayerState *currentstate;
        public:
                PVN_Player();
                ~PVN_Player();
                void SetHealth(int);
-               void SetJumpHeight(int);
-               void SetRunSpeed(int);
                void SetAttackPower(int);
                int GetHealth();
-               int GetJumpHeight();
-               int GetRunSpeed();
                int GetAttackPower();
+               void Update();
+};
+
+
+class PVN_PlayerState
+{
+       string name;
+       PVN_Animation *anim;
+//     movement vectors per frame[]
+//     colission data
+//     sound effects
+//     conditions(player);     
 };
+       
 #endif /*PVN_NEWPLAYER_H*/

Modified: trunk/src/testing.cpp
==============================================================================
--- trunk/src/testing.cpp       Sat Jun 27 21:25:48 2009        (r351)
+++ trunk/src/testing.cpp       Sat Jun 27 21:32:56 2009        (r352)
@@ -23,6 +23,15 @@
        healthbar2->SetCurrent(100);
        healthbar2->GetPosition()->x = 300;
        healthbar2->ReCalcLeft();
+
+       testanim = new PVN_Animation;
+       testanim->SetImage(Image_Load("../data/images/blankAnimationBlue.png"));
+       testanim->SetPosition2i(400,300);
+       testanim->SetFPS(1);
+
+       newplayer = new PVN_Player;
+       newplayer->SetPosition(new SDL_Rect);
+       newplayer->SetPosition2i(400,300);
 }
 
 PVN_test::~PVN_test()
@@ -32,6 +41,8 @@
        delete healthbar1;
        delete healthbar2;
        delete environment1;
+       delete testanim;
+       delete newplayer;
        return;
 }
 
@@ -184,6 +195,8 @@
        player1->Draw(game->screen_surface);
        player2->Draw(game->screen_surface);
        healthbar1->Blit(game->screen_surface);
-       healthbar2->Blit(game->screen_surface);
+       healthbar2->Blit(game->screen_surface); 
+       testanim->Blit(game->screen_surface);
+       newplayer->Blit(game->screen_surface);
        environment1->BlitForeground(game->screen_surface);
 }

Modified: trunk/src/testing.h
==============================================================================
--- trunk/src/testing.h Sat Jun 27 21:25:48 2009        (r351)
+++ trunk/src/testing.h Sat Jun 27 21:32:56 2009        (r352)
@@ -11,6 +11,7 @@
 #include "player.h"
 #include "state_template.h"
 #include "grid.h"
+#include "animation.h"
 
 class PVN_test: public PVN_state
 {
@@ -18,6 +19,8 @@
                Player *player1, *player2;
                PVN_HealthBar *healthbar1, *healthbar2;
                PVN_Environment *environment1;
+               PVN_Animation *testanim;
+               PVN_Object *newplayer;
 
                bool keys_held[323];
                bool clean;

Other related posts:

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