In my project I have moved the majority of SDL code from the Battle
class to a new class called DrawBattle.  I'm trying to build it, but
DrawBattle refuses to recognize my Battle class.  I know that this isn't
finished, but I prefer to debug and rebuild as I go.  I have pasted the
code for only the relevant classes:

[EMAIL PROTECTED] ourrpg $ nl battle.h
     1  #ifndef __BATTLE_H__
     2  #define __BATTLE_H__
     3
     4  #include <SDL/SDL.h>
     5  #include "SDL/SDL_ttf.h"
     6  #include <string>
     7  #include "character.h"
     8  #include "ally.h"
     9  #include "drawbattle.h"
    10
    11  using namespace std;
    12
    13
    14  class Battle
    15  {
    16     public:
    17        Battle();
    18        ~Battle();
    19        Ally* getParty() { return party; }
    20        Ally* getParty(int i) { return &party[i]; }
    21
    22        bool initialize();
    23        bool destroy();
    24
    25     private:
    26        Ally party[4];
    27        DrawBattle db;
    28  };
    29
    30  #endif

[EMAIL PROTECTED] ourrpg $ nl battle.cpp
     1  #include <stdio.h>
     2  #include <stdlib.h>
     3  #include <SDL/SDL.h>
     4  #include <SDL/SDL_image.h>
     5  #include <SDL/SDL_gfxPrimitives.h>
     6  #include <stdlib.h>
     7  #include <string.h>
     8  #include "battle.h"
     9  #include "character.h"
    10
    11  int i;
    12   
    13
    14  Battle::Battle()
    15  {
    16
    17  //TEMP This block is temporary - don't forget to remove it
later   
    18     party[0] = Ally("Michael", 10, 7);
    19     party[1] = Ally("Amy", 8, 13);
    20     party[2] = Ally("Feli", 12, 15);
    21     party[3] = Ally("Jelli", 9, 4);
    22  }
    23
    24  Battle::~Battle()
    25  {
    26  }
    27
    28  bool Battle::initialize()
    29  {
    30     db = DrawBattle(this);
    31  }
    32
    33  bool Battle::destroy()
    34  {
    35  }
    36
    37
    38  int main()
    39  {
    40     Battle mybattle;
    41     
    42     if (!mybattle.initialize()) exit(1);
    43
    44     
    45  //   i = 0;
    46     /*Draw the allies*/
    47  /*   mybattle.loadImage(i++, "ffight.gif");
    48     mybattle.loadImage(i++, "tfight.gif");
    49     mybattle.loadImage(i++, "wmfight.gif");
    50     mybattle.loadImage(i, "bmfight.gif");
    51
    52     mybattle.drawScreen();*/
    53
    54     SDL_Delay(5000);
    55
    56     mybattle.destroy();
    57
    58     return 0;
    59  }

[EMAIL PROTECTED] ourrpg $ nl drawbattle.h
     1  #ifndef DRAWBATTLE_H
     2  #define DRAWBATTLE_H
     3
     4  #include "battle.h"
     5
     6  class DrawBattle
     7  {
     8     public:
     9        DrawBattle() {}
    10        DrawBattle(Battle *ba);
    11        ~DrawBattle();
    12
    13        bool initialize();
    14        bool destroy();
    15
    16        void loadImage(int index, string filename);
    17        void drawStats();
    18        void drawLines();
    19
    20        SDL_Surface* drawString(int x, int y, string dsMessage);
    21        SDL_Surface* getScreen() { return screen; }
    22        SDL_Surface* getImage(int i) { return image[i]; }
    23        SDL_Surface** getStatus() { return status; }
    24        Uint32 getColorKey() { return colorkey; }
    25
    26     private:
    27        SDL_Surface *screen, *image[4], *status[4];
    28        SDL_Rect src[4], dest[4];
    29        Uint32 colorkey;
    30        TTF_Font *font;
    31        Ally party[4];
    32        Battle *b;
    33        
    34  };
    35  #endif

[EMAIL PROTECTED] ourrpg $ nl drawbattle.cpp
     1  #include "drawbattle.h"
     2
     3  bool DrawBattle::initialize()
     4  {
     5     if (SDL_Init(SDL_INIT_VIDEO) != 0)
     6     {
     7        printf("Unable to initialize SDL:  %s\n", SDL_GetError());
     8        return false;
     9     }
    10     atexit(SDL_Quit);
    11     
    12     if( TTF_Init() == -1 ) 
    13     { 
    14        printf("Could not intialize the font:  %s\n",
SDL_GetError());
    15        return false;
    16     }
    17     font = TTF_OpenFont( "lazy.ttf", 18 );
    18
    19     if( font == NULL ) 
    20     {
    21        printf("Error loading font:  %s\n", SDL_GetError());
    22        return false;
    23     }
    24     SDL_WM_SetCaption( "OurRPG - Battle Screen", NULL );
    25     screen =  SDL_SetVideoMode(1000, 675, 16, SDL_DOUBLEBUF |
SDL_HWSURFACE);
    26     if (screen == NULL)
    27     {
    28        printf("Unable to set video mode:  %s\n", SDL_GetError());
    29        return false;
    30     }
    31
    32     for (int i = 0; i < 4; i++)
    33     {
    34        status[i] = NULL;
    35        party[i].setX(600);
    36        party[i].setY(i * 100);
    37
    38     }
    39
    40     return true;
    41  }
    42
    43  bool DrawBattle::destroy()
    44  {
    45     if (screen != NULL) SDL_FreeSurface(screen);
    46     if (font != NULL) TTF_CloseFont(font);
    47     for (int i = 0; i < 4; i++)
    48     {
    49        SDL_FreeSurface(image[i]);
    50        SDL_FreeSurface(status[i]);
    51     }
    52  }
    53  SDL_Surface* DrawBattle::drawString(int x, int y, string
dsMessage)
    54  {
    55     SDL_Surface *message;
    56     SDL_Color textColor = { 255, 255, 255 };
    57     message = TTF_RenderText_Solid( font, dsMessage.c_str(),
textColor );
    58     
    59     if( message == NULL ) 
    60     {
    61        printf("Error rendering text:  %s\n", SDL_GetError());
    62        return NULL; 
    63     }
    64
    65     SDL_Rect dest1, src1;
    66     src1.x = 0;
    67     src1.y = 0;
    68     src1.w = message->w;
    69     src1.h = message->h;
    70     dest1.x = x;
    71     dest1.y = y;
    72     dest1.w = message->w;
    73     dest1.h = message->h;
    74
    75     SDL_BlitSurface(message, &src1, screen, &dest1);
    76
    77     return message;
    78  }
    79  void DrawBattle::drawLines()
    80  {
    81     /*Draw the battle screen lines*/
    82     i = hlineColor(screen, 0, 1000, 0, 0xFFFFFFFF);
    83     i = vlineColor(screen, 0, 0, 400, 0xFFFFFFFF);
    84     i = hlineColor(screen, 0, 1000, 400, 0xFFFFFFFF);
    85     i = vlineColor(screen, 700, 0, 400, 0xFFFFFFFF);
    86     i = hlineColor(screen, 700, 1000, 0, 0xFFFFFFFF);
    87     i = hlineColor(screen, 700, 1000, 100, 0xFFFFFFFF);
    88     i = hlineColor(screen, 700, 1000, 200, 0xFFFFFFFF);
    89     i = hlineColor(screen, 700, 1000, 300, 0xFFFFFFFF);
    90     i = vlineColor(screen, 1000, 0, 400, 0xFFFFFFFF);
    91
    92     SDL_UpdateRect(screen, 0, 0, 0, 0);
    93  }
    94  void DrawBattle::drawStats()
    95  {
    96     char tmp[255];
    97     for (i = 0; i < 4; i++)
    98     {
    99        status[i] = drawString((party[i].getX() + 110),
(party[i].getY() + 10), party[i].getName());
   100        
   101        sprintf(tmp, "HP: %ld/%ld", party[i].getCurrentHP(),
party[i].getMaxHP());
   102        status[i] = drawString((party[i].getX() + 110),
(party[i].getY() + 50), tmp);
   103
   104        sprintf(tmp, "MP: %ld/%ld", party[i].getCurrentMP(),
party[i].getMaxMP());
   105        status[i] = drawString((party[i].getX() + 110),
(party[i].getY() + 70), tmp);
   106     }
   107
   108  }
   109  void DrawBattle::loadImage(int index, string filename)
   110  {
   111     image[index] = IMG_Load(filename.c_str());
   112     if (image[index] == NULL)
   113     {
   114        printf("Unable to load image %s:  %s\n", filename,
SDL_GetError());
   115     }
   116
   117     colorkey = SDL_MapRGB(image[index]->format, 0, 255, 0);
   118     SDL_SetColorKey(image[index], SDL_SRCCOLORKEY, colorkey);
   119
   120     src[index].x = 0;
   121     src[index].y = 0;
   122     src[index].w = image[index]->w;
   123     src[index].h = image[index]->h;
   124
   125     dest[index].x = 600;
   126     dest[index].y = index * 100;
   127     dest[index].w = image[index]->w;
   128     dest[index].h = image[index]->h;
   129  }
   130
   131  void DrawBattle::drawScreen()
   132  {
   133
   134     //Draw allies
   135     for (i = 0; i < 4; i++)
   136     {
   137        SDL_BlitSurface(image[i], &src[i], screen, &dest[i]);
   138     }
   139
   140     //Draw enemies
   141     
   142     drawStats();
   143
   144     /*Draw the battle screen lines*/
   145     drawLines();
   146     SDL_Flip(screen);
   147  }
   148
   149  DrawBattle::DrawBattle(Battle *ba)
   150  {
   151     b = ba;
   152  }
   153  DrawBattle::~DrawBattle()
   154  {
   155     delete b;
   156  }

[EMAIL PROTECTED] ourrpg $ nl Makefile
     1  CXX=g++
     2
     3  #CFLAGS= -W -Wall -pedantic `sdl-config --cflags`
     4  CFLAGS= `sdl-config --cflags`
     5  LIBS=`sdl-config --libs` -lSDL_image -lSDL_gfx -lSDL_ttf -lz
-lmysqlclient_r -lmysqlpp
     6
     7  OBJS = battle.o character.o ally.o drawbattle.o
     8
     9  INCS = battle.h character.h ally.h drawbattle.h
    10
    11  INCOPTS=-I/usr/local/include/mysql++/ -I/usr/include/mysql
-L/usr/local/lib
    12
    13  all: battle
    14
    15  battle: $(OBJS)
    16          $(CXX) -o $@ $(OBJS) $(LIBS) $(INCOPTS)
    17
    18  %.o : %.cpp $(INCS)
    19          $(CXX) $(CFLAGS) $(INCOPTS) -c $<
    20
    21  clean:
    22          -rm *.o *~ core* battle

[EMAIL PROTECTED] ourrpg $ make
g++ `sdl-config --cflags` -I/usr/local/include/mysql++/
-I/usr/include/mysql -L/usr/local/lib -c battle.cpp
drawbattle.h:10: error: expected `)' before '*' token
drawbattle.h:32: error: ISO C++ forbids declaration of 'Battle' with no
type
drawbattle.h:32: error: expected ';' before '*' token
battle.cpp: In member function 'bool Battle::initialize()':
battle.cpp:30: error: no matching function for call to
'DrawBattle::DrawBattle(Battle* const)'
drawbattle.h:9: note: candidates are: DrawBattle::DrawBattle()
drawbattle.h:7: note:                 DrawBattle::DrawBattle(const
DrawBattle&)
make: *** [battle.o] Error 1


Reply via email to