257
« on: May 20, 2014, 09:18:58 pm »
Example code:
So you have this:
int levelStream[] = {
enemy(110, 0, image_LUT_enemy_ship_0_light, image_LUT_enemy_bullet_1_light, callback_LUT_0, LIGHT, 1),
enemy(220, 0, image_LUT_enemy_ship_0_shadow, image_LUT_enemy_bullet_1_light, callback_LUT_0, SHADOW, 1),
cmd_killed,
LVLSTR_END
};
and you (probably) access it like this:
levelStream[n]
If you did this:
int levelStreamAArray = {enemy(...),enemy(...),cmd_killed,LVLSTR_END};
int levelStreamA(int n) = levelStreamArray[n];
int (*levelStream)(int);
levelStream = &levelStreamA
and accessed like this:
levelStream(n)
then you could also do this with just a change to your levelStream pointer:
int levelStreamB(n) = switch (n%3)
case 0:
return enemy(110, 0, image_LUT_enemy_ship_0_light, image_LUT_enemy_bullet_1_light, callback_LUT_0, LIGHT, 1);
break;
case 1:
return enemy(220, 0, image_LUT_enemy_ship_0_shadow, image_LUT_enemy_bullet_1_light, callback_LUT_0, SHADOW, 1),
break;
case 2:
return cmd_killed;
break;
default: // Stops the compiler from yelling at you and is probably good in case of lobsters
return LVLSTR_END;
levelStream = &levelStreamB
You access it the same:
levelStream(n)
Make sure your functions don't grab the whole array/function at once, and you're great! (New idea: survive for X amount of time; you could just put a case at top that gives LVLSTR_END if the time is done)