Main .ino file. this is not complete but there are no errors other than this problem
const int TxPin = 2;
const int LED = 13;
const int rightBUTTON = 7;
const int leftBUTTON = 6;
const int upBUTTON = 5;
const int downBUTTON = 4;
#include "map.h"
#include "ghost.h" //included file that contains class
#include <SoftwareSerial.h>
SoftwareSerial mySerial = SoftwareSerial(255, TxPin);
// button values
int Rval = 0;
int Lval = 0;
int Uval = 0;
int Dval = 0;
// counter
int i;
//player cordinates
int playerX = 0;
int playerY = 1;
int ghostDELAY = 0;
//LCD command corosponding to the courdenents
int playerLOCATION;
byte steeve[8] = {
B00000, //00000
B01110, // XXX
B01110, // XXX
B11111, //XXXXX
B10101, //X X X
B01110, // XXX
B01010, // X X
};
byte ghost[8] = {
B00000,//
B01110,// XXX
B10101,//X X X
B11111,//XXXXX
B11111,//XXXXX
B11111,//XXXXX
B01010,// X X
B00000,//
};
Cat Cat1; //creation of the new class
Cat1.Cat();
//Player VI
class Player{
public:
int y;
int x;
int LOCATION;
Player(){
y = 1;
x = 0;
LOCATION = MAP [x] [y];
}
void render(int z){
mySerial.write(z);
mySerial.write(1);
}
void run(){
}
void restart(){
x = 0;
y = 1;
LOCATION = MAP [playerY] [playerX];
mySerial.write(playerLOCATION);
mySerial.write(1);
}
};
//ghost AI
class Ghost{
private:
int x;
int y;
public:
int LOCATION;
Ghost(){
x = 15;
y = 0;
LOCATION = MAP[y] [x];
}
void render(int z){
mySerial.write(z);
mySerial.write(2);
}
void chase(){
if(ghostDELAY >= 500){
if(x > playerX){
mySerial.write(LOCATION);
mySerial.print(" ");
x--;
if (x == -1){
x = 15;
}
LOCATION = MAP [y] [x];
mySerial.write(LOCATION);
mySerial.write(2);
ghostDELAY = 0;
}else if(x < playerX){
mySerial.write(LOCATION);
mySerial.print(" ");
x++;
if (x == -1){
x = 15;
}
LOCATION = MAP [y] [x];
mySerial.write(LOCATION);
mySerial.write(2);
ghostDELAY = 0;
}
if(y > playerY){
mySerial.write(LOCATION);
mySerial.print(" ");
y--;
if (y == -1){
y = 1;
}
LOCATION = MAP [y] [x];
mySerial.write(LOCATION);
mySerial.write(2);
ghostDELAY = 0;
}else if(y < playerY){
mySerial.write(LOCATION);
mySerial.print(" ");
y++;
if (y == 2){
y = 0;
}
LOCATION = MAP [y] [x];
mySerial.write(LOCATION);
mySerial.write(2);
ghostDELAY = 0;
}
}
}
void restart(){
x = 15;
y = 0;
LOCATION = MAP[y] [x];
mySerial.write(LOCATION);
mySerial.write(2);
}
};
static Ghost ghost1;
void setup() {
pinMode(LED, OUTPUT);
pinMode(rightBUTTON, INPUT);
pinMode(leftBUTTON, INPUT);
pinMode(upBUTTON, INPUT);
pinMode(downBUTTON, INPUT);
pinMode(TxPin, OUTPUT);
digitalWrite(TxPin, HIGH);
mySerial.begin(9600);
delay(100);
mySerial.write(249);
for (i = 0; i < 8; i++) {
mySerial.write(steeve[i]);
}
mySerial.write(250);
for (i = 0; i < 8; i++) {
mySerial.write(ghost[i]);
}
mySerial.write(12); // Clear
mySerial.write(17); // Turn backlight on
mySerial.write(22);
delay(5); // Required delay
mySerial.print("Look What I Made"); // First line
delay(3000);
mySerial.write(12);
delay(5);
playerLOCATION = MAP [playerY] [playerX];
mySerial.write(playerLOCATION);
mySerial.write(1);
ghost1.render(ghost1.LOCATION);
delay(1000); // Wait 3 seconds
}
void loop() {
Rval = digitalRead(rightBUTTON);
Lval = digitalRead(leftBUTTON);
Uval = digitalRead(upBUTTON);
Dval = digitalRead(downBUTTON);
playerLOCATION = MAP [playerY] [playerX];
//command for right button
if (Rval == HIGH){
digitalWrite(LED, HIGH);
mySerial.write(playerLOCATION);
mySerial.print(" ");
playerX++;
if (playerX == 16){
playerX = 0;
}
playerLOCATION = MAP [playerY] [playerX];
mySerial.write(playerLOCATION);
mySerial.write(1);
ghostDELAY += 250;
delay(250);
}else if (Lval == HIGH){ //left button
digitalWrite(LED, HIGH);
mySerial.write(playerLOCATION);
mySerial.print(" ");
playerX--;
if (playerX == -1){
playerX = 15;
}
playerLOCATION = MAP [playerY] [playerX];
mySerial.write(playerLOCATION);
mySerial.write(1);
ghostDELAY += 250;
delay(250);
}else if (Dval == HIGH){ //up button
digitalWrite(LED, HIGH);
mySerial.write(playerLOCATION);
mySerial.print(" ");
playerY++;
if (playerY == 2){
playerY = 0;
}
playerLOCATION = MAP [playerY] [playerX];
mySerial.write(playerLOCATION);
mySerial.write(1);
ghostDELAY += 250;
delay(250);
}else if (Uval == HIGH){ //up button
digitalWrite(LED, HIGH);
mySerial.write(playerLOCATION);
mySerial.print(" ");
playerY--;
if (playerY == -1){
playerY = 1;
}
playerLOCATION = MAP [playerY] [playerX];
mySerial.write(playerLOCATION);
mySerial.write(1);
ghostDELAY += 250;
delay(250);
}else {
digitalWrite(LED, LOW);
}
ghostDELAY += 1;
ghost1.chase();
delay (1);
if (ghost1.LOCATION == playerLOCATION){
mySerial.write(12);
delay(5);
mySerial.print(" GAME ");
mySerial.print(" OVER ");
delay(3000);
mySerial.write(12);
delay(5);
mySerial.print(" RESTARTING.. ");
delay(1000);
mySerial.write(12);
delay(5);
// restart();
ghost1.restart();
delay(1000);
}
}
ghost.h file
class Cat{ // an error is returned when "extern" in placed before the class
private:
public:
int y; // if extern is placed any where before the varaible or the function it also returns an error
Cat(){
y = 0;
}
void Max(){
y = 2;
}
};
map.h file
int MAP [2] [16] = {
{128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143},
{148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163}
};