Picaxe & Games

rolsen

Member
I read Jeremy Leach's post on the tube game with interest. It occurs to me that the picaxe (simpler the better) would lend itself to games like TicTacToe (0's & X's), 21 matches game (remove 1,2 or 3 from line of 21.Person left with last looses. Even novel board games (race type) or quagmire from 70's issue of EE magazine.Lots of LEDS, Sounds, random no. move generator etc. for interest. Great projects for beginners. I liked Clive S. Simon Says game. Post our finished game projects. Should be interesting & fun.
 

Michael 2727

Senior Member
I'm pretty sure this was working last time
I used it. (Let me know if it has any bugs.)
Edited since original post.

<code><pre><font size=2 face='Courier'>
There is a way to make the targets move
about using a 4017, but that's another story.
Code:
' Shooting Gallery game.
'
' The code as it stands will display the
' scores of 2 Players on 2 x 2 Digit 7-Seg
' displays.
' Using O/P 0 as the common display reset.   ( 08M Chip, Leg-7 )
' Using O/P 1 for Player 2 score clock out.  ( 08M Chip, Leg-6 )
' Using I/O 1 for Player 2 LDR, shared I/O.  ( 08M Chip, Leg-6 )
' Using O/P 2 for Player 1 score clock out.  ( 08M Chip, Leg-5 )
' Using Input 3 for Game Reset switch.       ( 08M Chip, Leg-4 )
' ( You can also use an LDR to reset the Game,      Chip Leg-4 )
' Using I/O 4 for the Player 2 LDR.              ( 08M Chip, Leg-3 )
' The b8 and b9 values set the MAX allowable
' hits total. Change this value as required.
' There are different sounds for each players
' &quot;Hit&quot; score and a tune to indicate the
' game has finished. A 2 note reset tune also.
' The brightest ADC / LDR value &quot; Hit &quot; wins the point.
' The Piezo Sounder also shares O/P 2 so -
' - the Player 1 Display goes crazy, just like a real pinball game, ~ ;o)
' I/O 1 is shared as an ADC-1 and P2 score clock out.
' Code was done for a Picaxe 08M using the &quot;tune&quot;
' function and the use of programmable pins e.g. I/O 1.
'
' Have fun, drive your M0M nuts.



symbol score = b10
main:
input 1                ' I/O 1 is reset to an input.         
high 0                 ' I/O 1 is shared as ADC-1 in and P2 score clock out.    
low 0  
readadc 1,b0
readadc 4,b2
inc w3
output 1
count 3,75,b1
if w3 &gt;= 778 then finish   ' Value = around 1 Min if no hits are registered.
if b1 = 0 then run         ' w3 value could be set for longer duration, games.
b8 =0
b9 =0
tune 0, 7,($6A,$40)',$20,$20,$40,$20,$20)                 ' Reset Notification tune.
goto main
run:
if b0 &gt; 55 and b0 &gt; b2 then label   ' Set to allow for ambient Light levels. ( The 55 value )
if b2 &gt; 55 then Other_Label         ' Set to allow for ambient Light levels. ( The 55 value )
'
' Set the A1 and A4  values to above 55 if using the &quot;Picaxe Simulator&quot;, and use Generic, briefly to reset game.
'
goto main                           ' Loops if not within Spec required. 
Label:
inc b8 'b8 = b8 + 1                         ' b8 keeps score of total hits of player 1.
pwm 2,44,1
pwm 2,222,1
pwm 2,22,12
pwm 2,125,7
if b8 &gt;= 25 then finish             ' Set score finish value, e.g. 25 hits. ' ( 1 to 99 )
goto main
Other_Label:
inc b9 'b9 = b9 + 1                         ' b9 keeps score of total hits of player 2.
pwm 2,44,1
pwm 2,222,1
pwm 2,22,6
pwm 2,125,5
pwm 2,22,6
pwm 2,125,5
if b9 &gt;= 25 then finish             ' Set score finish value, e.g. 25 hits. ' ( 1 to 99 )
goto main
Finish:                             
tune 0, 7,($4A,$47,$C2,$4C,$4A,$47,$C1,$4C,$4A,$47,$C0,$4C,$6A,$40) ' tune = Mission Impossible theme.
' Change the tune to whatever you wish, There are only 3 bytes of spare code space
' left so you will need a similar length tune if you replace the one above.
if b8 &gt; b9 then winner_1st_8
winner_1st_9:
high 0
low 0
if b9 = 0 then S
for score = 1 to b9
high 2
low 2
next score
pause 1500
if b8 = 0 then S
goto winner_2nd_8
'
winner_1st_8:
high 0
low 0
if b8 = 0 then S
for score = 1 to b8
high 1
low 1
next score
pause 1500
if b9 = 0 then S
goto winner_2nd_9
'
winner_2nd_8:
high 0
low 0
for score = 1 to b8
high 1
low 1
next score
pause 1500
goto S
'
winner_2nd_9:
high 0
low 0
for score = 1 to b9
high 2
low 2
next score
pause 2500
goto S

S:
count 3,200,b1
b8 =0                 ' Reset all variables
b9 =0                 ' Reset all variables
w3 =0                 ' Reset all variables
if b1 &gt;= 1 then main  ' Reset Button, to Start again.
goto S
'
'
' The last score displayed is the losers.
' The winners score is always the MAX hit count as set up -
' - in the programming, e.g. 1 to 99, unless a time-out occurs.
' The winners sore is cleared to &quot;00&quot; when displaying the loser score.
'
'By Michael Jeffery
'Aug 2006 Copyright.

 </font></pre></code> 

Edited by - Michael 2727 on 15/03/2007 05:52:26
 

rolsen

Member
Hi Michael. Looks great. Can't wait to give it a go. The 4017, LM3914 LED driver &amp; ULN2003 relay driver make great interface. ie Pinball game. What about a game of island hopping using sensor &quot;bases&quot; that link with Picaxe IR. Good one to do in the dark. Indoor or Outdoor. Maybe Stan could commence a new series of articles for &quot;Silicon Chip&quot; under
&quot;Let the Picaxe Games begin&quot; with sponsorship for best games prize.
 

Michael 2727

Senior Member
Obviously I had been tinkering with the
original code, was a couple of very strange
lines in there. Anyway it's fixed now, it
will run on the SIM but you won't hear the
&quot;hit&quot; sounds or get any LDR variation though.
It will run on a standard &quot;Schools Experimenter&quot;
PCB but you only get one players LDR and no
display unless they are both externally attached.
 
Top