Creating a Template
Let's have a quick pitstop before creating our second game. By making a template that sets up everything we need to make a game we can save ourselves a lot of trouble and going back to Lessons 1 through 3 to remember how to do things like adding libraries and how to set up random numbers.
Below is some code that will function as a good starting point for any game.
//Name of Game
//by MyName
#include <Arduboy2.h>
Arduboy2 arduboy;
void setup() {
// put your setup code here, to run once:
arduboy.begin();
arduboy.initRandomSeed(); //Set Up Random Number Generator
arduboy.setFrameRate(60); //Set Game Frame Rate
arduboy.clear();
}
void loop() {
// put your main code here, to run repeatedly:
//Prevent the Arduboy from running too fast
if (!arduboy.nextFrame()) {
return;
}
arduboy.clear();
arduboy.display();
}
Save this code as "HandheldGameTemplate" or something similar that you like.
Now you can open this file every time you want to start a new game and save some time. As you learn more things (like how to set up sound) you can change your template.