For my game, I'm tying to make units which have x and y coordinates as well as health and other necessities. Then, in my main I will simply draw all of the units based on their x and y. I had planned to use structs, but it seemed a little old fashioned so I wanted to see what was recommended in cpp for this kind of thing.
I learned to program mostly in Basic, and what I used there was rather hodge-podge: separate arrays for every element of the unit.
Basically what I'm asking is, what is the most commonly used cpp thing used for this, or at least what would be recommended in my situation.
Simple C++ problem
I also would use structs to hold all necessary unit datas, combined with an array, probably...
while(!asleep) sheep++;
IrrExtensions:
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
IrrExtensions:
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
Hmm... so an array of structs? I tried this:
But its not compiling. What did I do wrong?
Code: Select all
typedef struct {
int lvl;
int x;
int y;
} unit;
unit myunits[2];
myunits[0].lvl=1;
no, the Irrlicht array class...
and maybe the struct with functions (or maybe a class instead of a struct)...
for further infos about the array class, have a look at the API !!!
and maybe the struct with functions (or maybe a class instead of a struct)...
Code: Select all
struct unitData{
int lvl;
int x;
int y;
movePosition(int x, int y){
// for example: move the unit to x,y
}
};
array<unitData> lstUnits;
void addUnit(int x, int y, int lvl){
unitData uNew;
uNew.x = x;
uNew.y = y;
uNew.lvl = lvl;
lstUnits.push_back(uNew);
}
while(!asleep) sheep++;
IrrExtensions:
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
IrrExtensions:
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
Re: Simple C++ problem
In C++ a struct is a class with default accessibility public. (If its not a POD, but you shouldnt be concerned about that). Conclusion: Using structs is ok.Ion Dune wrote:I had planned to use structs, but it seemed a little old fashioned so I wanted to see what was recommended in cpp for this kind of thing.