OK. New code and error messages:
[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
10 using namespace std;
11
12 class DrawBattle;
13 class Battle
14 {
15 public:
16 Battle();
17 ~Battle();
18 Ally* getParty() { return party; }
19 Ally* getParty(int i) { return &party[i]; }
20
21 bool initialize();
22 bool destroy();
23
24 private:
25 Ally party[4];
26 DrawBattle db;
27 };
28
29 class DrawBattle
30 {
31 public:
32 DrawBattle() {}
33 DrawBattle(Battle *ba);
34 ~DrawBattle();
35
36 bool initialize();
37 bool destroy();
38
39 void loadImage(int index, string filename);
40 void drawStats();
41 void drawLines();
42
43 SDL_Surface* drawString(int x, int y, string dsMessage);
44 SDL_Surface* getScreen() { return screen; }
45 SDL_Surface* getImage(int i) { return image[i]; }
46 SDL_Surface** getStatus() { return status; }
47 Uint32 getColorKey() { return colorkey; }
48
49 private:
50 SDL_Surface *screen, *image[4], *status[4];
51 SDL_Rect src[4], dest[4];
52 Uint32 colorkey;
53 TTF_Font *font;
54 Ally party[4];
55 Battle *b;
56
57 };
58
59 #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 $ make
g++ `sdl-config --cflags` -I/usr/local/include/mysql++/
-I/usr/include/mysql -L/usr/local/lib -c battle.cpp
battle.h:26: error: field 'db' has incomplete type
battle.cpp: In member function 'bool Battle::initialize()':
battle.cpp:30: error: 'db' was not declared in this scope
make: *** [battle.o] Error 1
Why does db have an incomplete type, and why was db "not declared in
this scope"?