--- In [email protected], "Tamas Marki" <[EMAIL PROTECTED]> wrote:
> That's irrelevant now! Your problem is that you include headers in
> each other. That's not gonna work. Period.
> 
> -- 
> Tamas Marki


Is this better?

[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  class DrawBattle
    31  {
    32     public:
    33        DrawBattle() {}
    34        DrawBattle(Battle *ba);
    35        ~DrawBattle();
    36
    37        bool initialize();
    38        bool destroy();
    39
    40        void loadImage(int index, string filename);
    41        void drawStats();
    42        void drawLines();
    43
    44        SDL_Surface* drawString(int x, int y, string dsMessage);
    45        SDL_Surface* getScreen() { return screen; }
    46        SDL_Surface* getImage(int i) { return image[i]; }
    47        SDL_Surface** getStatus() { return status; }
    48        Uint32 getColorKey() { return colorkey; }
    49
    50     private:
    51        SDL_Surface *screen, *image[4], *status[4];
    52        SDL_Rect src[4], dest[4];
    53        Uint32 colorkey;
    54        TTF_Font *font;
    55        Ally party[4];
    56        Battle *b;
    57        
    58  };
    59
    60  #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

[EMAIL PROTECTED] ourrpg $ nl drawbattle.cpp
     1  #include "battle.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 main.cpp
     1  #include "battle.h"
     2
     3  int main()
     4  {
     5     Battle mybattle;
     6     
     7     if (!mybattle.initialize()) exit(1);
     8
     9     
    10  //   i = 0;
    11     /*Draw the allies*/
    12  /*   mybattle.loadImage(i++, "ffight.gif");
    13     mybattle.loadImage(i++, "tfight.gif");
    14     mybattle.loadImage(i++, "wmfight.gif");
    15     mybattle.loadImage(i, "bmfight.gif");
    16
    17     mybattle.drawScreen();*/
    18
    19     SDL_Delay(5000);
    20
    21     mybattle.destroy();
    22
    23     return 0;
    24  }

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

Either way, it gives the exact same errors:

[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.h:30: error: redefinition of 'class DrawBattle'
drawbattle.h:7: error: previous definition of 'class DrawBattle'
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