nyeecola
Ok, thanks for the help, you guys are awesome. Can I ask one more question?
I have 3 structures like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32 | typedef struct
{
double x;
double y;
v2 velocity;
texture_t image;
int w;
int h;
} player_h;
typedef struct
{
double x;
double y;
v2 velocity;
texture_t image;
int w;
int h;
behavior_t behavior;
skill_t skills[5]; // array of skills
int skills_count; // how many skills does he have
} enemy_t;
typedef struct
{
double x;
double y;
v2 velocity;
texture_t image;
int w;
int h;
} particle_t;
|
So, it seems like there's a lot of duplicated data above. How would you guys go about "fixing" that? Or should I just leave it as is and not care about this?
And, on the enemy_t structure, is that a dumb way of handling enemies with different skills/skill counts?
There is, in my opinion, nothing wrong with duplicated code. The main thing to Think about here, is to not overcomplicate things to make it "pretty". It will just bite you in the ass.
You could ofcource do nested structs, like they all contain x and y and velocity and so on. But nested structs is more annoying to work on, and you work on them alot. You use them way less.
BUT, this is, as I see it still OOP. Your structs is obviosly designed as object. This is fine if you handle 100 object, or 1000 or (some number), but if you will handle a big number of "objects", it will be slow.
I would think about how data is USED. Most likely you will make a function that updates ALL objects x and y.
Then I would do:
typedef struct
{
double x; (by the way, why doubles?)
double y;
}Position;
Position position[NUMBER_OF_OBEJCTS_IN_GAME];
Then the same for w+h. Then an array for textures, and so on. Thts way you will get a much more efficient engine, with less cache misses.