I was working on a game using 8051 controller but then shifted to Arduino and I must say, programming on it was incredibly easy. Major problem I was facing with 8051 was the useless time lag which Arduino removed via setCursor() function. For now the map is fixed, same and small but this is only the first version of the game. Next step will be to create randomly generated walls. Lets see how that comes out to be. Check the video ->
Here is the code.
Replace “LiquidCrystal.h” with <LiquidCrystal.h>
#include "LiquidCrystal.h" int pin=A5; int button=3; int row=0; int val=0; int i=0; char ship='*'; char loading[]=" Loading Map "; char map1[]=" | || FINISH "; char map2[]=" | | LINE "; // initialize the library with the numbers of the interface pins LiquidCrystal lcd(2, 4, 8, 9, 10, 11); void setup() { Serial.begin(9600); // set up the LCD's number of columns and rows: lcd.begin(16, 2); pinMode(pin,INPUT); pinMode(button,INPUT); // Print a message to the LCD. i=0; } void loop() { if(i<1) loadMap(i); // Load Map i++; // Counting Steps val=digitalRead(button); // Check Pushbutton Value if(val==1) { row=~row; //Change Rows } if(i<=34) play(i,row); else { gameOver(); } //check for breakpoints if ((i==9 && row==0) || (i==15 && row==-1) || (i==20 && row==0) || (i==28 && row==-1) ) { lcd.clear(); lcd.setCursor(4,0); lcd.print("UhhOO!!"); delay(2000); i=40; // Jump to gameOver } if(val==1 && i>35) i=0;// If in gameOver and Push button is pressed then restart the game delay(200); } void gameOver() { lcd.clear(); lcd.setCursor(6,0); lcd.print("GAME"); lcd.setCursor(6,1); lcd.print("OVER"); } void play(int i,int row) { lcd.setCursor(i, row); lcd.print(ship); lcd.scrollDisplayLeft(); } void loadMap(int i) { lcd.clear(); lcd.setCursor(0,0); lcd.print("Deewar Se Bacho"); delay(1200); lcd.setCursor(0,0); for(i=0;map1[i]!='\0';i++) lcd.print(map1[i]); lcd.setCursor(0,1); for(i=0;map2[i]!='\0';i++) lcd.print(map2[i]); i=1; //Map loaded now start the game and bring cursor to the begining }
Comments
You must log in to post a comment.