J
jaso
Hi,
I'm making this video game in C.
The game contains a player, enemies and bullets. These objects,
which are arrays of structures, are initialized, updated and drawn
in a game loop. Now I am unsure on where to declare these things.
I could declare them in main() like this
#define NUM_ENEMIES 10
#define NUM_BULLETS 20
int main(void)
{
struct *player player1;
struct enemy enemies[NUM_ENEMIES];
struct bullet bullets[NUM_BULLETS];
init_player(player1);
init_enemies(enemies, NUM_ENEMIES);
init_bullets(bullets, NUM_BULLETS);
while (1) {
update_...
draw_...
}
}
Or, I could declare them globally and make main() a little "cleaner"
by calling the functions with void parameters and let the functions
handle the objects and the count by themselves.
I don't know which one to choose, the second way seems a little
more modular, since I move the internal (should it be internal?)
stuff out of main.
But OTOH, I've read that local variables are better
than global. But again, if I put the handling functions in an other
file, and have static linkage, they won't be global, right?
I would be grateful if someone could give me some points on how
to do.
Thanks!
I'm making this video game in C.
The game contains a player, enemies and bullets. These objects,
which are arrays of structures, are initialized, updated and drawn
in a game loop. Now I am unsure on where to declare these things.
I could declare them in main() like this
#define NUM_ENEMIES 10
#define NUM_BULLETS 20
int main(void)
{
struct *player player1;
struct enemy enemies[NUM_ENEMIES];
struct bullet bullets[NUM_BULLETS];
init_player(player1);
init_enemies(enemies, NUM_ENEMIES);
init_bullets(bullets, NUM_BULLETS);
while (1) {
update_...
draw_...
}
}
Or, I could declare them globally and make main() a little "cleaner"
by calling the functions with void parameters and let the functions
handle the objects and the count by themselves.
I don't know which one to choose, the second way seems a little
more modular, since I move the internal (should it be internal?)
stuff out of main.
But OTOH, I've read that local variables are better
than global. But again, if I put the handling functions in an other
file, and have static linkage, they won't be global, right?
I would be grateful if someone could give me some points on how
to do.
Thanks!