//Jonathan Holmes (crait)
//December 7th, 2016
//A simple Pong clone
#include <Arduboy2.h>
Arduboy2 arduboy;
//Variables declared here
int gamestate = 0;
int ballx = 62;
int bally = 0;
int ballsize = 4;
int ballright = 1;
int balldown = 1;
void setup() {
arduboy.begin();
//Seed the random number generator
arduboy.initRandomSeed();
//Set the game to 60 frames per second
arduboy.setFrameRate(60);
arduboy.clear();
}
void loop() {
//Prevent the Arduboy from running too fast
if(!arduboy.nextFrame()) {
return;
}
arduboy.clear();
arduboy.pollButtons();
//Game code here
switch( gamestate ) {
case 0:
//Title screen
arduboy.setCursor(0, 0);
arduboy.print("Title Screen");
//Change the gamestate
if (arduboy.justPressed(A_BUTTON)) {
gamestate = 1;
}
break;
case 1:
//Gameplay screen
arduboy.setCursor(0, 0);
arduboy.print("Gameplay");
//Draw the ball
arduboy.fillRect(ballx, bally, ballsize, ballsize, WHITE);
//Move the ball right
if(ballright == 1) {
ballx = ballx + 1;
}
//Move the ball left
if(ballright == -1) {
ballx = ballx - 1;
}
//Reflect the ball off of the left side of the screen
if(ballx == 0) {
ballright = 1;
}
//Reflect the ball off of the right side of the screen
if(ballx + ballsize == 127) {
ballright = -1;
}
//Move the ball down
if(balldown == 1) {
bally = bally + 1;
}
//Move the ball up
if(balldown == -1) {
bally = bally - 1;
}
//Reflect the ball off of the top of the screen
if(bally == 0) {
balldown = 1;
}
//Reflect the ball off of the bottom of the screen
if(bally + ballsize == 63) {
balldown = -1;
}
//Change the gamestate
if (arduboy.justPressed(A_BUTTON)) {
gamestate = 2;
}
break;
case 2:
//Win screen
arduboy.setCursor(0, 0);
arduboy.print("Win Screen");
//Change the gamestate
if (arduboy.justPressed(A_BUTTON)) {
gamestate = 3;
}
break;
case 3:
//Game over screen
arduboy.setCursor(0, 0);
arduboy.print("Game Over Screen");
//Change the gamestate
if (arduboy.justPressed(A_BUTTON)) {
gamestate = 0;
}
break;
}
arduboy.display();
}