This is an old revision of the document!
After doing the pointer arithmetic one might want to make their sprite a reality. The first step is to
array = ( Sprite * )malloc(sizeof(Sprite) * size );
A pointer identifies and refers to a specific memory location. By de-referencing the pointer, we can access the value stored at that location. In this project, pointers will primarily be used to refer to and access each enemy struct (or any other struct) for which you’ve allocated memory for using “malloc”.
Forming arrays using pointers:
Sprite *array = NULL;
Where 'Sprite' is the name of the struct, '*' declares a pointer to the struct, 'array' is the name of the pointer variable that is being declared, and 'NULL' indicates that the pointer does not currently point to any memory location (to avoid using an uninitialized pointer).
Your sprite needs to be a struct and a struct is a way to group several different variables into one place. Here is a basic example of how a struct should look:
struct Sprite { bool Active; int X, Y; };
You can then use this struct to make your player and enemies. For a player it could look something like:
Sprite Player; Player.Active = true; Player.X = 320; Player.Y = 300;
But for an enemy that there are multiple of you will have to use a loop:
for( index=0; index<Size; index++ ) { (Enemy+index) -> Active = true; (Enemy+index) -> X = 200; (Enemy+index) -> Y = 100; }
This loop when combined with whatever Sprite attribute that has been defined is how you initialize your enemies.
The original Space Invaders was a game where the player character was positioned at the bottom of the screen and fought enemies at the top. The enemies were arrayed into several rows and columns, and they would shuffle left and right until they reached the screen's borders. When that would happen, the remaining enemies positioned themselves down one row, creeping toward the player. The enemies could also shoot at the player, in random order. The player, in their own defense, had shields to protect them from the enemies' advance. The shield had its own health value, and as the enemies would shoot at the player, the shields would eat up the damage to spare the player but deteriorate as time went on. Eventually, they would disappear entirely. The player could move left and right on rails and shoot back at the enemies. This is Space Invaders in a nutshell.
The objective is to create your own personal twist on Space Invaders. This could be introducing a new theme, or mechanics, while remaining true to the original. Enemy array formation / random attacks, player shooting, hit detection, and custom structs are a MUST.
It also would not hurt to consider having custom sprites, sounds, music, and / or a score for the player.
Vircon uses .wav files for sounds!
If you want to have music being played on a loop it is important to set it up and not come back to it. By that I mean say you have
select_sound( MusicBackground ); set_sound_loop( MusicBackground ); play_sound_in_channel( MusicBackground, 15 );
You only want to play that once as not doing so will cause the audio to play over it's self and cause issue. The best way to do this would to put a check for an audioflag value == 1 and have an audioflag variable = 1 after the audio has been activated.