/*
ARDUINO BOY
Christian Hadiwijaya / 2306161952
This is a simple game console that can run 3 games: Tetris, Snake, and "Pacman".
The games are controlled using 4 buttons: Up, Down, Left, and Right.
The games are displayed on a 20x4 LCD screen.
CONTROLS:
MENU:
- Up and Down for selecting the game
- Right for confirming the game
TETRIS:
- Left and Right for moving the block
- Up for rotating the block
- Down for speeding up the block
SNAKE:
- Up, Down, Left, and Right for moving the snake
PACMAN:
- Up, Down, Left, and Right for moving the pacman
*/
#include "deviceSetup.h"
#include "tetris.h"
#include "snake.h"
#include "pacman.h"
byte gameTitle[4][8] = {
{B00000,
B00000,
B11111,
B10001,
B10101,
B11101,
B00000,
B00000},
{B00000,
B00000,
B11110,
B01001,
B01001,
B11110,
B00000,
B00000},
{B00000,
B00000,
B11110,
B00001,
B11110,
B00001,
B11110,
B00000},
{B00000,
B00000,
B11111,
B10101,
B10101,
B10101,
B00000,
B00000}};
byte tetrisIcon[] = {
B11000,
B11000,
B11000,
B11111,
B11111,
B11000,
B11000,
B11000};
byte snakeIcon[] = {
B10000,
B11000,
B01110,
B00011,
B00011,
B00000,
B00100,
B00000};
byte cursor[]{
B00000,
B00000,
B10001,
B10001,
B01010,
B00100,
B00000,
B00000};
int selectedGame = 0;
bool gameSelected = false;
void setup() {
pinMode(buttonLeft, INPUT);
pinMode(buttonRight, INPUT);
pinMode(buttonDown, INPUT);
pinMode(buttonUp, INPUT);
Serial.begin(9600);
lcd.begin(20, 4);
lcd.backlight();
randomSeed(analogRead(1));
printTitle();
}
void loop() {
int downState = digitalRead(buttonDown);
int upState = digitalRead(buttonUp);
int confirmState = digitalRead(buttonRight);
if (downState == HIGH) {
selectedGame++;
if (selectedGame > 2) {
selectedGame = 0;
}
lcd.clear();
printTitle();
}
if (upState == HIGH) {
selectedGame--;
if (selectedGame < 0) {
selectedGame = 2;
}
lcd.clear();
printTitle();
}
if (confirmState == HIGH) {
if (selectedGame == 0) {
tetrisSetup();
tetrisLoop();
} else if (selectedGame == 1) {
snakeSetup();
snakeLoop();
} else if (selectedGame == 2) {
pacmanSetup();
pacmanLoop();
}
lcd.clear();
printTitle();
}
lcd.setCursor(10 - (selectedGame * 3), 1);
lcd.write(6);
delay(100);
}
void printTitle() {
for (int i = 0; i < 4; i++) {
lcd.createChar(i, gameTitle[i]);
lcd.setCursor(15, i);
lcd.write(i);
}
lcd.createChar(4, tetrisIcon);
lcd.createChar(5, snakeIcon);
lcd.createChar(6, cursor);
lcd.createChar(7, pacmanIcon[1]);
lcd.setCursor(10, 2);
lcd.write(4);
lcd.setCursor(7, 2);
lcd.write(5);
lcd.setCursor(4, 2);
lcd.write(7);
}