PROGRAMMING

Episode 2 sees some re-writing.  Specifically creating the screen maze, changing a lot of variables to be arrayed variables.  Making Pac and Ghosts stick to the maze only.  Changing ghost movement to change direction when it hits the wall and to start to chase after Pac... (but that bit is literally not that noticable.


100 print "{clear}";
110 poke 53280,0:poke 53281,0
120 pa=65 :rem pac char
130 pd=0: rem pac dir 0 = up, 1=down, 2=left, 3=right
140 px=14: xx=0 :rem pac x pos
150 py=17: yy=0 :rem pac y pos
155 pc=7:sc=0:t=0
160 gh=64: rem ghost
170 dim gx(4),gy(4),ga(4),gb(4),gc(4),gp(4),pc(4),gd(4),ge(4),st(4)
175 rem Ghost x, y, xmov, ymov, ghostcol, ghostpremove,ghprecol
180 gosub 2000: rem set up ghosts
185 gosub 1100: rem set up chars
190 gosub 1000
200 rem mainloop
205 print "{home}";sy
210 k=peek(197)
220 if k= 13 then yy=-1
230 if k= 23then yy=1
240 if k= 47then xx=-1
250 if k= 44 then xx=1
260 sx=peek(1024+(40*(py+yy))+px+xx)
261 if sx<>59 and sx<>0 then 300
275 poke 1024+(40*py)+px,0
278 poke 55296+(40*py)+px,sc
280 px=px+xx:py=py+yy
290 poke 1024+(40*py)+px,pa
295 sc=peek(55296+(40*py)+px)
298 poke 55296+(40*py)+px,pc
300 xx=0:yy=0
310 gosub 2100 :rem moveghosts
400 goto 200
1000 rem screen is here
1010 print "{clear}";:for z=1024 to 2023
1020 read q:poke z,q:next
1030 for z=55296 to 56295
1040 read q:poke z,q:next
1050 return
1100 rem chars definition
1110 z=12288
1120 read q:if q=-1 then 1130
1125 pokez,q:?".";:z=z+1:goto 1120
1130 poke 53272,(peek(53272)and240)+12
1140 return
2000 gx(1)=12:gx(2)=13:gx(3)=14:gx(4)=15
2010 gy(1)=10:gy(2)=10:gy(3)=10:gy(4)=10
2020 gc(1)=2:gc(2)=5:gc(3)=3:gc(4)=4
2030 for z=1 to 4:st(z)=1:next
2050 return
2100 for z=1 to 4
2105 if st(z)=1 then 2162 
2110 poke 1024+(40*gy(z)+gx(z)),gp(z)
2115 poke 55296+(40*gy(z)+gx(z)),pc(z)
2150 sy=peek(1024+(40*(gy(z)+gd(z)))+gx(z)+ge(z))
2160 if sy=59 or sy=0 then 2210
2161 q=int(rnd(0)*2)+1:if q=1 then 2172
2162 w=int(rnd(0)*4)+1
2164 if w=1 then gd(z)=-1:ge(z)=0
2166 if w=2 then gd(z)=1:ge(z)=0
2168 if w=3 then ge(z)=-1:gd(z)=0
2170 if w=4 then ge(z)=1:gd(z)=0
2171 st(z)=0:goto 2180
2172 t=t+1:ift>15 then t=0
2173 poke 53280,t
2174 if gx(z)<px then gd(z)=1:ge(z)=0:goto 2180
2175 if gx(z)>px then gd(z)=-1:ge(z)=0:goto 2180
2176 if gy(z)<py then ge(z)=1:gd(z)=0:goto 2180
2177 if gy(z)>py then ge(z)=-1:gd(z)=0:goto 2180
2180 sy=peek(1024+(40*(gy(z)+gd(z)))+gx(z)+ge(z))
2190 if sy=59 or sy=0 then 2210
2200 goto 2162
2210 gx(z)=gx(z)+ge(z):gy(z)=gy(z)+gd(z)
2220 gp(z)=peek(1024+(40*gy(z)+gx(z)))
2224 pc(z)=peek(55296+(40*gy(z)+gx(z)))
2227 poke 1024+(40*gy(z)+gx(z)),gh
2228 poke 55296+(40*gy(z)+gx(z)),gc(z)
2230 next z
2240 return
9000 DATA 000,000,000,000,000,000,000,000
9010 DATA 056,108,198,198,254,198,198,000
9020 DATA 252,198,198,252,198,198,252,000
9030 DATA 060,102,192,192,192,102,060,000
9040 DATA 248,204,198,198,198,204,248,000
9050 DATA 254,192,192,252,192,192,254,000
9060 DATA 254,192,192,252,192,192,192,000
9070 DATA 062,096,192,206,198,102,062,000
9080 DATA 198,198,198,254,198,198,198,000
9090 DATA 126,024,024,024,024,024,126,000
9100 DATA 006,006,006,006,006,198,124,000
9110 DATA 198,204,216,240,248,220,206,000
9120 DATA 192,192,192,192,192,192,254,000
9130 DATA 198,238,254,254,214,198,198,000
9140 DATA 198,230,246,254,222,206,198,000
9150 DATA 124,198,198,198,198,198,124,000
9160 DATA 252,198,198,198,252,192,192,000
9170 DATA 124,198,198,198,222,204,122,000
9180 DATA 252,198,198,206,248,220,206,000
9190 DATA 120,204,192,124,006,198,124,000
9200 DATA 126,024,024,024,024,024,024,000
9210 DATA 198,198,198,198,198,198,124,000
9220 DATA 198,198,198,238,124,056,016,000
9230 DATA 198,198,214,254,254,238,198,000
9240 DATA 198,238,124,056,124,238,198,000
9250 DATA 102,102,102,060,024,024,024,000
9260 DATA 254,014,028,056,112,224,254,000
9270 DATA 000,000,255,000,000,255,000,000
9280 DATA 036,036,036,036,036,036,036,036
9290 DATA 000,000,192,048,008,200,036,036
9300 DATA 036,036,200,008,048,192,000,000
9310 DATA 036,036,019,016,012,003,000,000
9320 DATA 000,000,003,012,016,019,036,036
9330 DATA 000,000,255,000,000,240,008,008
9340 DATA 000,000,255,000,000,007,008,008
9350 DATA 008,008,008,008,008,008,008,008
9360 DATA 008,008,016,224,000,000,000,000
9370 DATA 008,008,004,003,000,000,000,000
9380 DATA 000,000,000,003,004,008,008,008
9390 DATA 000,000,000,224,016,008,008,008
9400 DATA 000,000,000,255,000,000,000,000
9410 DATA 000,255,000,000,000,000,255,000
9420 DATA 000,252,002,002,002,002,252,000
9430 DATA 036,035,032,032,032,032,035,036
9440 DATA 036,196,004,004,004,004,196,036
9450 DATA 000,063,064,064,064,064,063,000
9460 DATA 000,000,000,255,000,000,000,000
9470 DATA 255,255,255,255,255,255,255,255
9480 DATA 056,076,198,198,198,100,056,000
9490 DATA 024,056,024,024,024,024,126,000
9500 DATA 124,198,014,060,120,224,254,000
9510 DATA 126,012,024,060,006,198,124,000
9520 DATA 028,060,108,204,254,012,012,000
9530 DATA 252,192,252,006,006,198,124,000
9540 DATA 060,096,192,252,198,198,124,000
9550 DATA 254,198,012,024,048,048,048,000
9560 DATA 120,196,228,120,158,134,124,000
9570 DATA 124,198,198,126,006,012,120,000
9580 DATA 000,000,000,024,024,000,000,000
9590 DATA 000,000,000,016,000,000,000,000
9600 DATA 000,000,016,056,016,000,000,000
9610 DATA 000,000,056,056,056,000,000,000
9620 DATA 000,016,056,124,056,016,000,000
9630 DATA 000,056,124,124,124,056,000,000
9640 DATA 056,124,254,254,254,124,056,000
9650 DATA 060,126,248,240,248,126,060,000,-1
10000 rem screen data
10001 data 32,27,27,27,27,27,27,27,27,27,27,27,27,33,34,27,27,27,27,27,27,27,27
10005 data 27,27,27,27,29,0,0,0,0,0,0,0,0,0,0,0,0
10010 data 28,59,59,59,59,59,59,59,59,59,59,59,59,35,35,59,59,59,59,59,59,59,59
10015 data 59,59,59,59,28,0,0,0,0,0,0,0,0,0,0,0,0
10020 data 28,59,38,40,40,39,59,38,40,40,40,39,59,35,35,59,38,40,40,40,39,59,38
10025 data 40,40,39,59,28,0,0,0,0,0,0,0,0,0,0,0,0
10030 data 28,0,37,40,40,36,59,37,40,40,40,36,59,37,36,59,37,40,40,40,36,59,37
10035 data 40,40,36,0,28,0,0,0,0,0,0,0,0,0,0,0,0
10040 data 28,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59
10045 data 59,59,59,59,28,0,0,0,0,0,0,0,0,0,0,0,0
10050 data 28,59,38,40,40,39,59,38,39,59,38,40,40,40,40,40,40,39,59,38,39,59,38
10055 data 40,40,39,59,28,0,0,0,0,0,0,0,0,0,0,0,0
10060 data 28,59,37,40,40,36,59,35,35,59,37,40,40,39,38,40,40,36,59,35,35,59,37
10065 data 40,40,36,59,28,0,0,0,0,0,0,0,0,0,0,0,0
10070 data 28,59,59,59,59,59,59,35,35,59,59,59,59,35,35,59,59,59,59,35,35,59,59
10075 data 59,59,59,59,28,0,0,0,0,0,0,0,0,0,0,0,0
10080 data 31,27,27,27,27,29,59,35,37,40,40,39,59,35,35,59,38,40,40,36,35,59,32
10085 data 27,27,27,27,30,0,0,0,0,0,0,0,0,0,0,0,0
10090 data 0,0,0,0,0,28,59,35,38,40,40,36,0,37,36,0,37,40,40,39,35,59,28,0,0,0
10095 data 0,0,0,0,0,0,0,0,0,0,0,0,0,0
10100 data 27,27,27,27,27,30,59,35,35,0,0,0,0,0,0,0,0,0,0,35,35,59,31,27,27,27
10105 data 27,27,0,0,0,0,0,0,0,0,0,0,0,0
10110 data 47,0,0,0,0,0,59,37,36,0,38,40,40,46,46,40,40,39,0,37,36,59,0,0,0,0,0
10111 rem data 47,0,0,0,0,0,59,37,36,0,38,40,40,0,0,40,40,39,0,37,36,59,0,0,0,0,0
10115 data 47,0,0,0,0,0,0,0,0,0,0,0,0
10120 data 27,27,27,27,27,29,59,0,0,0,35,0,0,0,0,0,0,35,0,0,0,59,32,27,27,27,27
10125 data 27,0,0,0,0,0,0,0,0,0,0,0,0
10130 data 0,0,0,0,0,28,59,38,39,0,35,0,0,0,0,0,0,35,0,38,39,59,28,0,0,0,0,0,0
10135 data 0,0,0,0,0,0,0,0,0,0,0
10140 data 32,27,27,27,27,30,59,35,35,0,37,40,40,40,40,40,40,36,0,35,35,59,31
10145 data 27,27,27,27,29,0,0,0,0,0,0,0,0,0,0,0,0
10150 data 28,59,59,59,59,59,59,35,35,0,0,0,0,0,0,0,0,0,0,35,35,59,59,59,59,59
10155 data 59,28,0,0,0,0,0,0,0,0,0,0,0,0
10160 data 28,59,38,40,40,39,59,37,36,0,45,41,41,41,41,41,41,42,0,37,36,59,38
10165 data 40,40,39,59,28,0,0,0,0,0,0,0,0,0,0,0,0
10170 data 28,59,37,40,39,35,59,59,59,59,59,59,59,59,0,59,59,59,59,59,59,59,35
10175 data 38,40,36,59,28,0,0,0,0,0,0,0,0,0,0,0,0
10180 data 28,0,59,59,35,35,59,38,39,59,38,40,40,40,40,40,40,39,59,38,39,59,35
10185 data 35,59,59,0,28,0,0,0,0,0,0,0,0,0,0,0,0
10190 data 43,41,42,59,37,36,59,35,35,59,37,40,40,39,38,40,40,36,59,35,35,59,37
10195 data 36,59,45,41,44,0,0,0,0,0,0,0,0,0,0,0,0
10200 data 28,59,59,59,59,59,59,35,35,59,59,59,59,35,35,59,59,59,59,35,35,59,59
10205 data 59,59,59,59,28,0,0,0,0,0,0,0,0,0,0,0,0
10210 data 28,59,38,40,40,40,40,36,37,40,40,39,59,35,35,59,38,40,40,36,37,40,40
10215 data 40,40,39,59,28,0,0,0,0,0,0,0,0,0,0,0,0
10220 data 28,59,37,40,40,40,40,40,40,40,40,36,59,37,36,59,37,40,40,40,40,40,40
10225 data 40,40,36,59,28,0,0,0,0,0,0,0,0,0,0,0,0
10230 data 28,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59
10235 data 59,59,59,59,28,0,0,0,0,0,0,0,0,0,0,0,0
10240 data 31,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27
10242 data 27,27,27,27,30,0,0,0,0,0,0,0,0,0,0,0,0
10245 rem colour data
10250 data 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6
10255 data 6,6,6,6,6,6
10260 data 6,1,1,1,1,1,1,1,1,1,1,1,1,6,6,1,1,1,1,1,1,1,1,1,1,1,1,6,6,6,6,6,6,6
10265 data 6,6,6,6,6,6
10270 data 6,1,6,6,6,6,1,6,6,6,6,6,1,6,6,1,6,6,6,6,6,1,6,6,6,6,1,6,6,6,6,6,6,6
10275 data 6,6,6,6,6,6
10280 data 6,6,6,6,6,6,1,6,6,6,6,6,1,6,6,1,6,6,6,6,6,1,6,6,6,6,6,6,6,6,6,6,6,6
10285 data 6,6,6,6,6,6
10290 data 6,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,6,6,6,6,6,6,6
10295 data 6,6,6,6,6,6
10300 data 6,1,6,6,6,6,1,6,6,1,6,6,6,6,6,6,6,6,1,6,6,1,6,6,6,6,1,6,6,6,6,6,6,6
10305 data 6,6,6,6,6,6
10310 data 6,1,6,6,6,6,1,6,6,1,6,6,6,6,6,6,6,6,1,6,6,1,6,6,6,6,1,6,6,6,6,6,6,6
10315 data 6,6,6,6,6,6
10320 data 6,1,1,1,1,1,1,6,6,1,1,1,1,6,6,1,1,1,1,6,6,1,1,1,1,1,1,6,6,6,6,6,6,6
10325 data 6,6,6,6,6,6
10330 data 6,6,6,6,6,6,1,6,6,6,6,6,1,6,6,1,6,6,6,6,6,1,6,6,6,6,6,6,6,6,6,6,6,6
10335 data 6,6,6,6,6,6
10340 data 6,6,6,6,6,6,1,6,6,6,6,6,6,6,6,6,6,6,6,6,6,1,6,6,6,6,6,6,6,6,6,6,6,6
10345 data 6,6,6,6,6,6
10350 data 6,6,6,6,6,6,1,6,6,6,6,6,6,6,6,6,6,6,6,6,6,1,6,6,6,6,6,6,6,6,6,6,6,6
10355 data 6,6,6,6,6,6
10360 data 0,6,6,6,6,6,1,6,6,6,6,6,6,10,10,6,6,6,6,6,6,1,6,6,6,6,6,0,6,6,6,6,6
10365 data 6,6,6,6,6,6,6
10370 data 6,6,6,6,6,6,1,6,6,6,6,6,6,6,6,6,6,6,6,6,6,1,6,6,6,6,6,6,6,6,6,6,6,6
10375 data 6,6,6,6,6,6
10380 data 6,6,6,6,6,6,1,6,6,6,6,6,6,6,6,6,6,6,6,6,6,1,6,6,6,6,6,6,6,6,6,6,6,6
10385 data 6,6,6,6,6,6
10390 data 6,6,6,6,6,6,1,6,6,6,6,6,6,6,6,6,6,6,6,6,6,1,6,6,6,6,6,6,6,6,6,6,6,6
10395 data 6,6,6,6,6,6
10400 data 6,1,1,1,1,1,1,6,6,6,6,6,6,6,6,6,6,6,6,6,6,1,1,1,1,1,1,6,6,6,6,6,6,6
10405 data 6,6,6,6,6,6
10410 data 6,1,6,6,6,6,1,6,6,6,6,6,6,6,6,6,6,6,6,6,6,1,6,6,6,6,1,6,6,6,6,6,6,6
10415 data 6,6,6,6,6,6
10420 data 6,1,6,6,6,6,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,6,6,6,6,1,6,6,6,6,6,6,6
10425 data 6,6,6,6,6,6
10430 data 6,6,1,1,6,6,1,6,6,1,6,6,6,6,6,6,6,6,1,6,6,1,6,6,1,1,6,6,6,6,6,6,6,6
10435 data 6,6,6,6,6,6
10440 data 6,6,6,1,6,6,1,6,6,1,6,6,6,6,6,6,6,6,1,6,6,1,6,6,1,6,6,6,6,6,6,6,6,6
10445 data 6,6,6,6,6,6
10450 data 6,1,1,1,1,1,1,6,6,1,1,1,1,6,6,1,1,1,1,6,6,1,1,1,1,1,1,6,6,6,6,6,6,6
10455 data 6,6,6,6,6,6
10460 data 6,1,6,6,6,6,6,6,6,6,6,6,1,6,6,1,6,6,6,6,6,6,6,6,6,6,1,6,6,6,6,6,6,6
10465 data 6,6,6,6,6,6
10470 data 6,1,6,6,6,6,6,6,6,6,6,6,1,6,6,1,6,6,6,6,6,6,6,6,6,6,1,6,6,6,6,6,6,6
10475 data 6,6,6,6,6,6
10480 data 6,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,6,6,6,6,6,6,6
10485 data 6,6,6,6,6,6
10490 data 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6
10495 data 6,6,6,6,6,6