TRON 2.0
My first quick version of tron was extremely simple.
Here it is another more user friendly version, with improved computer I.A. and sound effects.
Download source code and d64 image disc: tron.rar
Source code.
::::::::::::::::::::::
:rem tron 2.0 :::
:rem by f.g.huerta :::
::::::::::::::::::::::
:: rem configure music
::::::::::: volume max
10 poke 36878,15
::::::::::::::::::::::
:rem music :::::::::::
:rem mm(2) -> instruments
:rem n%(3) -> melodie
20 dim mm(2):dim n%(3)
:rem init instruments
22 mm(0)=36874:mm(1)=36875:mm(2)=36876
:rem music pointers
24 mi=0:ni=0
::::::::::::::::::::::
:rem players :::::::::
:rem p(pn, data) -> data player array
:rem pn -> player id
:rem p(pn, 0)-> x pos
:rem p(pn, 1)-> y pos
:rem p(pn, 2)-> ix
:rem p(pn, 3)-> iy
:rem p(pn, 4)-> color
:rem p(pn, 5)-> status: 0->ok, 1->crashed
:rem p(pn, 6)-> num crashes
:rem p(pn, 7)-> last x pos
:rem p(pn, 8)-> last y pos
30 dim p(1,8)
:rem ms->screen memory
:rem mc->color memory
40 ms=7680: mc=38400
:rem v ->velocity
:rem s ->character sprite
:rem hc->head color
50 v=1:s=asc("*"): hc=0
::::::::::::::::::::::
:rem new game entry point
::::::::::::::::::::::
:rem reset scores
60 p(0,6)=0:p(1,6)=0
::::::::::::::::::::::
:rem new match entry point
::::::::::::::::::::::
:rem init melodie
70 for i=0 to 3:read n%(i):next i
:rem init players
75 for pn=0 to 1: for i=0 to 5
80 read p(pn,i)
90 next i: next pn
:rem clear screen
100 print chr$(147)
::::::::::::::::::::::
:::rem begin main loop
::::::::::::::::::::::
: rem match finished?
110 if p(0,5)+p(1,5) > 0 then 1510
: rem game finished?
120 if p(0,6)=9 or p(1,6)=9 then 1810
: rem read keyboard
130 get k$
: rem exit?
140 if k$="x" then goto 1810
:::::::::rem player ia
210 if k$="a" then p(0,2)=-v:p(0,3)=0
220 if k$="d" then p(0,2)=v :p(0,3)=0
230 if k$="w" then p(0,3)=-v:p(0,2)=0
240 if k$="s" then p(0,3)=v :p(0,2)=0
:::::::::::rem computer ia
: inminent crash? and little random factor
310 q=(p(1,1)+p(1,3))*22+p(1,0)+p(1,2)
320 if peek(ms+q)<>s and rnd(1)<.95 then goto 410
: change direction
330 d=v: if rnd(1)<.5 then d=-d
340 if p(1,2)<>0 then q=(p(1,1)+d)*22+p(1,0):goto 360
350 q=p(1,1)*22+p(1,0)+d
: direction blocked? change direction again
360 if peek(ms+q)=s then d=-d
: final decision
370 if p(1,2)<>0 then p(1,2)=0:p(1,3)=d: goto 410
380 p(1,2)=d:p(1,3)=0
:::::::::: rem phisics
410 for pn=0 to 1
:::: rem save old pos
420 p(pn,7)=p(pn,0):p(pn,8)=p(pn,1)
:::::::::::: rem move
430 p(pn,0)=p(pn,0)+p(pn,2): p(pn,1)=p(pn,1)+p(pn,3)
::::::::: rem fix pos
440 if p(pn,0)<0 then p(pn,0)=21
450 if p(pn,0)>21 then p(pn,0)=0
460 if p(pn,1)<0 then p(pn,1)=22
470 if p(pn,1)>22 then p(pn,1)=0
480 next pn
:::::rem check crashes
:rem draw?
510 if p(0,0)=p(1,0) and p(0,1)=p(1,1) then p(0,5)=1:p(1,5)=1:goto 1510
:rem player crashes?
520 for pn=0 to 1
:rem if crashes ->
:rem - update status
:rem - increment crashes
530 q=p(pn,1)*22+p(pn,0)
540 if peek(ms+q)=s then p(pn,5)=1: p(pn,6)=p(pn,6)+1
550 next
:::::::::::::rem paint
610 for pn=0 to 1
:::::::::::::rem tail
630 q=p(pn,8)*22+p(pn,7)
640 poke mc+q,p(pn,4)
:::::::::::::rem head
660 q=p(pn,1)*22+p(pn,0)
670 poke ms+q,s
680 poke mc+q,hc
690 next
:::::::rem paint score
720 q=2*22+2
730 poke mc+q,p(0,4)
740 poke ms+q,48+p(1,6)
750 q=2*22+19
760 poke mc+q,p(1,4)
770 poke ms+q,48+p(0,6)
: play music
780 gosub 1110
:::::rem end main loop
790 goto 110
::::::::::::::::::::::
::::: music ::::::::::
:rem prepare next note
1110 ni=ni+1:if ni>3 then ni=0:poke mm(mi),0:mi=mi+1
1120 if mi>2 then mi=0
:rem play a note :::::
1130 poke mm(mi),n%(ni)
1140 return
:::::::::::: music off
1210 poke mm(0),0
1220 poke mm(1),0
1230 poke mm(2),0
: reset music pointers
1240 mi=0:ni=0
1250 return
::::::::::::::::::::::
:::::::::rem end match
::::::::::::::::::::::
::::::::rem select msg
1510 if p(0,5)=1 then msg$="human crash!":q=p(0,1)*22+p(0,0):poke mc+q,2
1520 if p(1,5)=1 then msg$="computer crash!":q=p(1,1)*22+p(1,0):poke mc+q,2
1530 if p(0,5)+p(1,5)=2 then msg$="draw!"
:::::::::rem music off
1540 gosub 1210
::::::::rem earthquake
1550 for n=1 to 10:for m=10 to 14
1560 poke 36864,m:poke 36877,240-m
1570 next m: next n
1580 poke36877,0
:::::::::rem show info
1610 print msg$
1620 print "any key continue"
::rem flush key buffer
1630 get k$: if k$<>"" then 1630
::::::::::::::rem wait
1640 for i=1 to 1000: next
:rem read keyboard
1650 get k$: if k$="" then 1650
:::::::::::::rem exit?
1660 if k$="x" then 1810
::rem start new match
1670 restore
1680 goto 70
::::::::::::::::::::::
:::::: rem exit ::::::
::::::::::::::::::::::
: rem music off
1810 gosub 1210
: rem score screen
1815 print chr$(147)
1820 print "final score"
1830 print "----------------------"
1840 print "human : ";p(1,6)
1850 print "computer : ";p(0,6)
1860 if p(0,6)=p(1,6) then msg$="draw!":goto 1890
1870 if p(0,6)<p(1,6) then msg$="human wins!": goto 1890
1880 msg$="computer wins!"
1890 print:print msg$
:::::: new game? :::::
1900 print:print"play again (y/n)?"
: rem flush key buffer
1910 get k$: if k$<>"" then 1890
::::::::::::: rem wait
1920 for i=1 to 1000: next
1930 get k$: if k$="" then 1930
1940 if k$="y" then restore:goto 60
1950 print "bye."
1960 end
::::::::::::::::::::::
::::: rem data :::::::
::::::::::::::::::::::
: melody
2010 data 195,201,207,209
: initial players values
2020 data 9, 11, 0, -1, 7, 0
2030 data 11, 11, 0, -1, 5, 0
