#include <stdio.h>
#include <wiringPi.h>
#include <lcd.h>
#include <ncurses.h>
#include <stdlib.h>
// WIRINGPI PIN NUMEBRS
#define LCD_R5 25 //Register select pin
#define LCD_E 24 //Enable pin
#define LCD_D0 29 //Data pin D0
#define LCD_D1 28 //Data pin D1
#define LCD_D2 27 //Data pin D2
#define LCD_D3 26 //Data pin D3
#define LCD_D4 23 //Data pin D4
#define LCD_D5 22 //Data pin D5
#define LCD_D6 21 //Data pin D6
#define LCD_D7 14 //Data pin D7
int main()
{
// Variables
time_t t;
int posC;
int posR;
int teleC;
int teleR;
int destC;
int destR;
//char teleChar[8] = {
//0b01110,
//0b11011,
//0b11011,
//0b10101,
//0b10101,
//0b11111,
//0b11011,
//0b01110
//};
char userInput;
int lcd;
wiringPiSetup();
// Initialize screen for getch() function
initscr();
// Initialize pins
lcd = lcdInit (4, 20, 8, LCD_R5, LCD_E, LCD_D0, LCD_D1, LCD_D2, LCD_D3, LCD_D4, LCD_D5, LCD_D6, LCD_D7);
// Title Screen
lcdClear(lcd);
sleep(1);
lcdPosition(lcd, 1, 0);
lcdPuts(lcd, "LCD MINI-ROUGELIKE");
lcdPosition(lcd, 2, 1);
lcdPuts(lcd, "BY CABBAGE");
lcdPosition(lcd, 4, 2);
lcdPuts(lcd, "VERSION 0.1");
// Title Screen
sleep(2);
// Clear the title screen, and set @ at 0,0. Also set the coordinate variables at starting @ position.
lcdClear(lcd);
lcdPosition(lcd, 0, 0);
lcdPuts(lcd, "@");
posC = 0;
posR = 0;
//teleR = 3;
//teleC = 3;
//destC = 1;
//destR = 2;
// Initialize random function
srand((unsigned) time(&t));
// Sets up Teleport location and Destination.
teleC = (rand() % 19);
teleR = (rand() % 3);
destC = (rand() % 19);
destR = (rand() % 3);
// Teleporting is extremely broken!!!! Commenting all teleport code until I find a fix.
// Loop continues asking for user input until the program is terminated.
// Will eventually change to "health" or a similar system.
while(1){
lcdPosition(lcd, 2,2);
lcdPuts(lcd, "#");
lcdPosition(lcd, teleC, teleR);
lcdPuts(lcd, "0");
// Ask for user input, make it uppercase for convenience's sake.
userInput=toupper(getch());
switch (userInput)
{
// Both left and top borders are broken... not sure why.
// This code at least doesn't allow the user to go beyond the boundaries.
case 'W':
if (posR <= 0)
posR=posR;
else if (posR == teleR && posC == teleC){
lcdPosition(lcd, destC, destR);
lcdPuts(lcd, "@");
break;
}
else{
posR--;
lcdClear(lcd);
lcdPosition(lcd, posC, posR);
lcdPuts(lcd, "@");
break;
}
case 'A':
if (posC <= 0)
posC=posC;
else if (posR == teleR && posC == teleC){
lcdPosition(lcd, destC, destR);
lcdPuts(lcd, "@");
break;
}
else{
posC--;
lcdClear(lcd);
lcdPosition(lcd, posC, posR);
lcdPuts(lcd, "@");
break;
}
// Both right and bottom borders work, prevent the user from moving beyond borders,
// and keep the @ in place.
case 'D':
if (posC >= 19)
posC=posC;
else if (posR == teleR && posC == teleC){
lcdPosition(lcd, destC, destR);
lcdPuts(lcd, "@");
break;
}
else{
posC++;
lcdClear(lcd);
lcdPosition(lcd, posC, posR);
lcdPuts(lcd, "@");
break;
}
case 'S':
if (posR >= 3)
posR=posR;
else if (posR == teleR && posC == teleC){
lcdPosition(lcd, destC, destR);
lcdPuts(lcd, "@");
break;
}
else{
posR++;
lcdClear(lcd);
lcdPosition(lcd, posC, posR);
lcdPuts(lcd, "@");
break;
}
// Keys other than WASD are pressed... keep @ in place.
default:
posC = posC;
posR = posR;
}
}
}