Crude LCD Game

I just posted this over at Savage Circuits, sorry of cross posting bother some you. I thought I'd share it here too. I 've playing with that Matrix Orbital display some more. This morning I was tinkering and my 6 year old asked me you the joystick (that was still on the breadboard from something else) didn't make the text on the LCD move. So instead of trying to explain I thought I'd "fix" it.
At first I got it reading the U/D and L/R on the joystick using RCTIME and then coded a small loop to move a character around on the LCD. That gave me the idea of a game so it evolved into this:
[video=youtube_share;O2-OOD-9OfY]
The speed increases as you (represented by the * ) pass the top of the screen. If the opponent ( B facing down ) collides with the you it pushes you back until you move. If you get pushed all the way to the bottom the speed resets.
Here's the code:
Paul
At first I got it reading the U/D and L/R on the joystick using RCTIME and then coded a small loop to move a character around on the LCD. That gave me the idea of a game so it evolved into this:
[video=youtube_share;O2-OOD-9OfY]

The speed increases as you (represented by the * ) pass the top of the screen. If the opponent ( B facing down ) collides with the you it pushes you back until you move. If you get pushed all the way to the bottom the speed resets.
Here's the code:
{LCD_Game.spin
Paul A. Willoughby, DVM
1/22/2012
}
CON
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000 '80MHz
_rxPin = 8 'using serial com
_txPin = 9
VAR
long ud, lr
byte player_row, player_col
byte opponent_row
byte opponent_col
byte delay
OBJ
LCD : "FullDuplexSerial"
rc1 : "RCTime"
rc2 : "RCTime"
RandGen : "RealRandom"
PUB Main
Init
repeat
opponent_row := ((RandGen.random >> 1) // 4) + 1
repeat opponent_col from 1 to 19
if opponent_col == (player_col-1) and opponent_row == player_row
player_col++
elseif opponent_col == player_col and opponent_row == player_row
player_col++
else
GetPlayerCol
GetPlayerRow
MoveTo(opponent_col, opponent_row)
LCD.STR(string("-B"))
MoveTo(player_col, player_row)
LCD.STR(string("*"))
waitcnt(clkfreq / delay + cnt)
Clear
if opponent_col == 1 and player_col == 20
delay := 5
if player_col ==1
delay++
PUB GetPlayerCol
if ud >120
player_col--
if ud <40
player_col++
if player_col >20
player_col := 20
if player_col < 1
player_col := 19
PUB GetPlayerRow
if lr > 120
player_row--
if lr < 40
player_row++
if player_row >4
player_row := 4
if player_row < 1
player_row := 1
PUB MoveTo (x, y)
LCD.tx($fe)
LCD.tx($47)
LCD.tx(x)
LCD.tx(y)
PUB Clear
LCD.tx($fe)
LCD.tx($58) 'clear screen
Pub Init
LCD.start(_rxPin, _txPin, 0, 19_200)
RandGen.start
waitcnt(clkfreq /2 + cnt)
Clear
rc1.start(4, 1, @lr)
rc2.start(2, 1, @ud)
player_row := 4
player_col := 20
delay := 5
Paul
Comments
http://www.amazon.com/Classic-Football-Handheld-Game-Mattel/dp/B00005BULI
http://www.beeslife.com/handheld/auto_race1.jpg
Paul