Hi all,
I have been struggling with this for hours....
I have defined a structure:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
|
struct unit {
ALLEGRO_BITMAP *pic;
char *name;
int strength, hp, initiative;} ground_unit[4];
ground_unit[1].name="Abrams";
ground_unit[1].strength=150;
ground_unit[1].hp=1000;
ground_unit[1].initiative=2;
ground_unit[2].name="Legionnaire";
ground_unit[2].strength=50;
ground_unit[2].hp=500;
ground_unit[2].initiative=5;
ground_unit[3].name="Flower";
ground_unit[3].strength=250;
ground_unit[3].hp=3000;
ground_unit[3].initiative=1;
|
two variables:
and trying to set up the following function....
1 2 3 4 5
|
void draw_all(int &l, int &m, struct unit ground_unit[4]){
al_draw_textf(font1, al_map_rgb(0,255,255), 220, 220,0, "Unit: %s", ground_unit[l].name);
al_draw_textf(font1, al_map_rgb(0,255,255), 420, 220,0, "Unit: %s", ground_unit[m].name);
}
|
I know that you may not be familiar with allegro, but my problem is purely in c/c++ and is about the two last lines.
So basically I want the function to draw "ground_unit[0].name" and "ground_unit[1].name". However I am completely lost, I have tried the following combinations:
1 2 3 4 5
|
void draw_all(int l, int m, struct unit ground_unit[4]){
al_draw_textf(font1, al_map_rgb(0,255,255), 220, 220,0, "Unit: %s", ground_unit[l].name);
al_draw_textf(font1, al_map_rgb(0,255,255), 420, 220,0, "Unit: %s", ground_unit[m].name);
}
|
1 2 3 4 5
|
void draw_all(struct unit ground_unit[4]){
al_draw_textf(font1, al_map_rgb(0,255,255), 220, 220,0, "Unit: %s", ground_unit[&l].name);
al_draw_textf(font1, al_map_rgb(0,255,255), 420, 220,0, "Unit: %s", ground_unit[&m].name);
}
|
1 2 3 4 5
|
void draw_all(int &l, int &m, struct unit ground_unit[4]){
al_draw_textf(font1, al_map_rgb(0,255,255), 220, 220,0, "Unit: %s", ground_unit[&l].name);
al_draw_textf(font1, al_map_rgb(0,255,255), 420, 220,0, "Unit: %s", ground_unit[&m].name);
}
|
1 2 3 4 5
|
void draw_all(int &l, int &m, struct unit ground_unit[4].name){
al_draw_textf(font1, al_map_rgb(0,255,255), 220, 220,0, "Unit: %s", ground_unit[l].name);
al_draw_textf(font1, al_map_rgb(0,255,255), 420, 220,0, "Unit: %s", ground_unit[m].name);
}
|
1 2 3 4 5
|
void draw_all(int &l, int &m, struct unit char ground_unit[4].name){
al_draw_textf(font1, al_map_rgb(0,255,255), 220, 220,0, "Unit: %s", ground_unit[l].name);
al_draw_textf(font1, al_map_rgb(0,255,255), 420, 220,0, "Unit: %s", ground_unit[m].name);
}
|
None are working....any insight would be very helpful....
For the first try I get:
1>c:\users\wboustany\desktop\project_allegro\pic display test\pic display test\main.cpp(23): error C2036: 'unit []' : unknown size
1>c:\users\wboustany\desktop\project_allegro\pic display test\pic display test\main.cpp(23): error C2027: use of undefined type 'unit'
1> c:\users\wboustany\desktop\project_allegro\pic display test\pic display test\main.cpp(19) : see declaration of 'unit'
1>c:\users\wboustany\desktop\project_allegro\pic display test\pic display test\main.cpp(23): error C2228: left of '.name' must have class/struct/union
1>c:\users\wboustany\desktop\project_allegro\pic display test\pic display test\main.cpp(24): error C2036: 'unit []' : unknown size
1>c:\users\wboustany\desktop\project_allegro\pic display test\pic display test\main.cpp(24): error C2027: use of undefined type 'unit'
1> c:\users\wboustany\desktop\project_allegro\pic display test\pic display test\main.cpp(19) : see declaration of 'unit'
1>c:\users\wboustany\desktop\project_allegro\pic display test\pic display test\main.cpp(24): error C2228: left of '.name' must have class/struct/union
Please help and thanks,
Wissam