I am relatively new to C and am trying to write a dungeon crawler for the arduboy.
I try to draw all walls (shown as rectangles) with a function, so i´ve created a “struct”.
struct wall {
int x;
int y;
byte w;
byte h;
};
All the walls for a level are stored in an array, which I enter into a function that draws the walls. I tried to orient myself as much as possible to examples. (that’s why i use a bool, void get´s me another error)
Wall Wallslvl_1 [4] {
{-10, -5, 140, 5}, // above
{130, -5, 5, 70}, // right
{-10, -5, 5, 70}, // left
{-10, 65, 140, 5} // below
};
// code before the loop
bool wallsLVL1 (struct wall [], byte howlong);
// in the loop
bool wL1;
wL1 = wallsLVL1 (Wallslvl_1, (sizeof (Wallslvl_1) / sizeof (Wallslvl_1 [0])));
The function:
bool wallsLVL1 (struct wall [], byte howlong) {
for (byte i = 0; i <howlong; i ++) {
arduboy.drawRect (Wall [i] .x + movex, Wall [i] .y + movey, Wall [i] .w, Wall [i] .h, WHITE);
}
}
I get the following errors for each “[”.
Error: expected primary-expression before ‘[’ token:
arduboy.drawRect (Wall [i] .x + movex, Wall [i] .y + movey, Wall [i] .w, Wall [i] .h, WHITE);
What did I overlook? Thank you for any help.