Tile Sliding Game with uLCD-144-G2 and Analog Joystick
.
Overview
This project was a simple game using the uLCD-144-G2 128x128 LCD screen and a Sparkfun Analog Joystick which has select capabilities. The Game starts by prompting the user with a main menu that has multiple different selections. The first selection is to start the game, the second selection is a settings menu where the difficulty can be changed, and the third selection is a help menu which gives instructions about the game.
Gameplay
To navigate in the menus, the analog joystick can be flicked up or down to change the selection, and it can physically be pressed in to make a choice on the currently underlined selection.
The actual gameplay is a 3x3 tile sliding game where the user has to correctly order the tiles in numerical order, with a blank box being at the top left of the screen. They can swap any tile next to the empty tile by flicking on the joystick to indicate which tile needs to be switched. Since not every game is winnable, the user can click the joystick in at an time to end the game and go back to the main menu to possibly start a new game
There is an Easy Mode selection which is very simple and can be used for beginners or to demonstrate how the game is to be played.
Video Demo
Note: Because of the strong light given off by the LCD, it is tough to see that the boxes are numbered in the game (which is used to indicate the order).
Components Used
Wiring
mbed | uLCD | joystick |
---|---|---|
VU | +5V | |
p9 | TX | |
p10 | RX | |
p11 | RES | |
GND | GND | |
VOUT | VCC | |
p18 | HOR | |
p19 | VER | |
p20 | SEL | |
GND | GND |
Picture
Note: Extra wiring around the joystick was an attempt to keep it in place my moving the stick (it kept loosening and coming unplugged).
Snippet of Code
Example of Analog Joystick Interpretation
// Waits until a big enough change in joystick to select direction int getInput() { int direction = -1; while(direction < 0) { float v = vert.read(); float h = horz.read(); float s = sel.read(); wait(0.01); if(v < .2) direction = 0; else if(v > .8) direction = 2; else if(h < .2) direction = 3; else if(h > .8) direction = 1; else if(s < .01) direction = 5; } return direction; }
Program
Import programTileSlidingGame
A game created using the uLCD and an Analog Joystick.
Please log in to post comments.