Introduction: GRAVITY BOI
This game is a basic project who wants to work on 16x2 LCD on a new level. 'GRAVITY BOI' is a game where the player has to toggle between the 'monsters' as they come near. As the game progresses the monsters will come at a faster rate. When the monster hits the player...BOOM....the game is over. To restart the game, the reset button on the Arduino board should be pressed. High Score won't get erased with this.
You can download the code attached below (in Step3) and enjoy competing with friends. You can also design a PCB especially for this to make this a handy project, as in the cover video.
I was fascinated to make this project by seeing this project on the internet: https://www.instructables.com/id/Arduino-LCD-Game/
Then I decided to make my version of this game.
Step 1: Assembling the LCD
The 16x2 LCD has a standard connection with Arduino UNO and Nano with respect to the pins. To find out more about what these pins of LCD actually do, you can visit Arduino's official website where the basic connections are explained: https://www.arduino.cc/en/Tutorial/HelloWorld
The following connections are as per the connection given in the above link, with some extra connections too.
- VDD pin of LCD to 5v pin of Arduino.
- VSS pin of LCD to GND pin of Arduino
- RS pin of LCD to D12 of Arduino
- R/W pin of LCD to GND of Arduino
- E (enable) pin of LCD to D11 of Arduino
- D4 pin of LCD to D6 of Arduino
- D5 pin of LCD to D5 of Arduino
- D6 pin of LCD to D4 of Arduino
- D7 pin of LCD to D3 of Arduino
- A pin to 5V supply
- K pin of LCD to a resistor of 1Kohm and then to ground.
- connect a preset/potentiometer with its extreme ends at 5v and GND, then connect middle leg to VEE(contrast pin). If contrast is not varying with this, a 220k ohm resistance has to be attached in series with the pot.
Apart from this, there is a requirement of an active low switch which has to be used to make the player jump. (See 2nd Pic). An active low switch is a type of configuration in which the switch is connected like the one shown in the first pic. The value of the resistor used is 10k ohms. Connect this junction between switch and resistor with PIN 2 of Arduino.
(Pic 3) I have designed a separate PCB to get rid of doing these connections again and again.
Step 2: The Code's Algorithm
The code is based on a logic that obstacles will come in a random order in 1st and 2nd row, with proper spacing between them, using the inbuilt Rand() function. Care has been taken to provide enough gap for the player to jump between these two rows. After the 1st obstacle reaches the end (extreme left of the LCD screen), the delay time decreases by 1ms. The digital pin 2 of Arduino is set as an interrupt pin, whenever the button is pressed, the player toggles its position between 1st & 2nd row. (Need to be taken care of bouncing characteristic when using a switch). When the coordinates of the player and the obstacle matches, the game get over. The 'GAME OVER' message flashes on the screen.
The score criteria in this code is set as the time till which the player stays in the gameplay (in seconds). You can change this criterion as no. of obstacles crossed, as per your wish, in the Arduino IDE. Apart from this, another integer keeps track of highest score obtained in gameplay till the Arduino is powered on.
To restart the game press the Reset button on the Arduino board. The high score won't get lost with this.
I m looking forward to make this game more interesting. If anyone can re-develop the code to make it better, please share your version below in the comments.
Participated in the