Game Data
Now that we have a basic structure for our game laid out, we need to think about what kind of data exists in Snake.
The Building Blocks#
To do so, let's list out the objects in the game:
- The Snake
- The Food
That's about it! luckily we won't have too much data to deal with.
Now, let's dive a little deeper and think about the attributes each of these items has.
The Snake#
- Position for each tail piece
- Length of tail
- Direction the snake is traveling
The Food#
- Position
Data to Code#
Defining Structures#
With these attributes identified, we can go ahead and translate this data into code that our game can run off of.
In C there are things called structs, which are basically just packages of data that we can interact with to bundle data together. We'll use structs to represent our Snake and our Food.
Go ahead and put the following code above
void setup()
This Content is Locked
Enter your GCA kit's access code to continue