Game Render
At this point, our game is actually fully functional, there's just one problem - we can't see any of it! In order to visualize the data structures and their updates, we need to draw them onto the LED panel using FastLED.
Let's restrict all of our rendering logic to the
void renderGame() function we defined
earlier. This is good encapsulation practice in C.
Here's the basic outline for how the render function will operate:
void renderGame() { // Zero LED display memset(leds, 0, sizeof leds); // Ensures that our LEDs are all set to black by default // Render snake
// Render food
// Draw LEDs FastLED.show(); // FastLED library call to draw the LEDs}
You should add that code snippet above
void setup().
Translation of Matrix#
The indexing of the LED grid is not the same as the indexing of our game grid out of the box. Thus, if we try to map our game indexes to the pixel grid in a 1-1 manner, it won't really look like anything coherent.
To get the indexes of the game grid and the LED grid
to match up, we can define a new function
int translateMatrixIndex(int i). This
function will take in a game matrix index and
translate it to its corresponding LED matrix index.
It's not important to understand the details of
this translation, just that it is important to ensure
the indexes between the two matrices in row-column
format match up:
This Content is Locked
Enter your GCA kit's access code to continue