Table of Contents

msi1

The primary difference between the last and current project is that instead of using arrays, linked lists are to be employed instead. Essentially, all instances of arrays in msi0 must now be retired in favor of the singly linked list. This game will utilize new struct attributes and functions to achieve this goal. The end product should feature ZERO arrays, and, if done correctly, one or more linked lists (pending designer preference).

malloc

You start with nothing, then there is the great sneeze! Or in this case the malloc! At this point you should all know that malloc is memory allocation. In the Joe O classes you may be familiar with the term Newed Up? It's essentially that.

Sprite* Node
Node = (Sprite*)malloc(sizeof(Sprite));

Congratulations you now have a Node! You might also find it useful to have a List so List struct and malloc that in the same manner.

Also, remember that whenever you allocate memory(malloc) you are also responsible for freeing that memory at the end of your program. You can do this by using

free(Node);

pointer arithmetic

With Lists and Nodes, unlike Arrays since elements are not stored contiguously, you can't simply add the size of the element to the address to reach the next. While it is faster to do it that way, this project is about Lists and thus we will do it this way.

Using Lists requires Structs but not any Struct will do, these Structs require a fancy maneuver called next whose type will be a pointer of the same name as the Struct

struct Node {
  int data;
  Node* next;
};

Using the next property and assigning it to point at a new Node “once that's created” will in essence be your arithmetic. You can then use something akin to

Struct* current = NULL;
current = myList->start;
while( current != NULL ) {
  ...
  current = current->next;
}

This will get you through the entire length of your list if that were to be some objective of yours

node struct

To make your node struct, you need to take whatever you are making into a list, in this case your Sprite/Enemy/GameObject struct, and add a next pointer to it ie

struct Sprite {
   int X;
   int Y;
   bool Active;
};

will become

struct Sprite {
   int X;
   int Y;
   bool Active;
   Sprite *next;
};

list struct

Currently a list needs two things: A start and an End

struct List
{
   Sprite *start;
   Sprite *end;
}

If you would like to run through a list to get the values. A good idea would be to make a temp * and have it start and end at null. For example.

// Before the while loop.
temp = start;
while (temp != null)
{
// Do a thing

// After the thing
temp = temp * next
}

Always make sure that the end has a NULL or else it will loop forever!

singly-linked list

A singly linked list is a group of nodes that each have some way of finding the next node in the list.

space invaders

The original Space Invaders was a game where the player character was positioned at the bottom of the screen and moved solely along the x-axis. You would fight enemies who would be organized in rows and columns at the top, they would also move along the a-axis and move towards the player by one row when an alien made contact with the left and right “walls” respectively. The enemies could also shoot at the player at random. 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 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.

You could add something like multiple lives, dropped by enemies when killed, allowing players to continue on even after losing their first life. Or have enemies that can take multiple hits. Another option is movement or bullet speed upgrades, dropped by certain enemies.

It also would not hurt to consider having custom sprites, sounds, music, and/or a score for the player.

You can get a feel for how the game is meant to be played https://freeinvaders.org/