Fairly improved. Now you can generate enemys as many as your memory permmiting. That is to say, I implemented the circular doubly linked list and malloc/free. Say goodbye to Enemy[ENEMY_MAX_NUM] and hallo to _list *next; _list *prev;.
In this version, I hadn't implemented qsort for linked list, so task's priority and sprite's z order sorting is broken at the moment. Additionaly, since my malloc/free code is so native one that the game can be slower than before. I should improve it, by the caching technique? by the Slab allocater, the magazines, and vmem??? ;-). Lastly, the continue function is broken. you can't do " continue " in the game.
" Hitcircle " has been implemented. Now missile's and lockon-laser's collision detection does not depend on enemy's coord, but does depend on hitcircle's coord. And each of enemys has their own hitcircle. So " for (i = 0;i < Enemy_Num;i++){}; for (i = 0;i < Enemy2_Num;i++){}; ... " was altered " for (i = 0;i < Hitcircle_Num;i++){}; " .
From this, the enemy came to be able to have hitcircle complexly, and we come to be able to create a big enemy. The big enemy has a big body with a various complecated figure, so we express it to put hitcircles in several places of his body. I implemented warship " Musashi " as a example of the big enemy. She has three hitcircles in a line along her hull.
Before I describe the tasking technique, I address some fundamental questions concerning the programming of the shoot-em-up game. IMHO, usually we use following procedures in programming it.
Tasking
So if I can move enemys and missiles as like the following,
For this purpose, I used the pointer to a function. And I declared a variable, _Task Task[TASK_MAX_NUM] to input it. Then in game_loop().
Animated spaceship
In my understanding, it is difficult to program the animated spaceship and so on with usual methods such as " static int i; i++; if (i > 10) i = 0; " on game loop, because we encounter difficulties when we want to animate spaceship independently on each other. Usually, we overcome this problem to add a new variable like " int anime_count; " to the structure of spaceship. But it is not a sufficient solution because when we want to add a " nitro engine " time-limited power-up item to the game, we have to add a new one, i.e. " int nitro_count; " , besides it. This configuration leads codes to get spaghettied. In " Tasking " method, we can easily handle commands such as " execute Nitro_Effect() function for 10 frames " , " in last count, execute another code." and so on. Task_Add(Nitro_Effect, player1, 10). Please appreciate splendid sprite animations of spaceship, missile and item.
Multipled Tasking
When we use the keyboard to rotate player's spaceship, it is natural to write like this.
#define ROTATE_SPEED (5)
if (key_left == true) Player.angle += ROTATE_SPEED;
if (key_right == true) Player.angle -= ROTATE_SPEED;
I should point out that, in that way, we can't rotate it quickly or slowly. We have to do it quickly when the enemy is approaching from six o'clock, and slowly when we snipe accuracy the enemy on a few degrees difference. To solve the problem, I used multipled tasking.
#define PLAYER_ROTATE_TIME (5)
#define ROTATE_SPEED (1)
Task_Add(Player_Rotate, player, NULL, PLAYER_ROTATE_TIME);
and after 1 frame...
Task_Add(Player_Rotate, player, NULL, PLAYER_ROTATE_TIME);
and after 1 frame...
Task_Add(Player_Rotate, player, NULL, PLAYER_ROTATE_TIME);
and after 1 frame...
Task_Add(Player_Rotate, player, NULL, PLAYER_ROTATE_TIME);
and after 1 frame...
Task_Add(Player_Rotate, player, NULL, PLAYER_ROTATE_TIME);
we come to be able to rotate it quickly to press left or right key longly, and slowly to do it shortly.