' 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
' "Hit" score and a tune to indicate the
' game has finished. A 2 note reset tune also.
' The brightest ADC / LDR value " Hit " 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 "tune"
' 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 >= 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 > 55 and b0 > b2 then label ' Set to allow for ambient Light levels. ( The 55 value )
if b2 > 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 "Picaxe Simulator", 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 >= 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 >= 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 > 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 >= 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 "00" 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