'spr#100 player car 'spr#101..169 skymarks 'read data into x/y table sub load_tbl(x(),y()) for i=0 to ubound(x) read x(i),y(i) next i end sub 'acceleration relative to acceleration duration in second dim accd_x(3),accd_y(3) ' sec acc/s data 0, 3 data 0.3, 6 data 4, 4 data 10, 0 call load_tbl(accd_x(),accd_y()) 'cap acceleration according to speed dim accs_x(2), accs_y(2) ' speed acc/s data 0, 6 data 10, 3 data 12, 0 call load_tbl(accs_x(),accs_y()) 'air resistance according to speed, roughly quadratic dim drag_x(4), drag_y(4) ' speed drag/s data 0, 0.1 data 3, 0.2 data 6, 0.3 data 9, 0.4 data 12, 0.8 call load_tbl(drag_x(),drag_y()) 'steer relative to touch drag speed dim steer_x(4), steer_y(4) ' speed steer data -20, -0.85 data -10, -0.25 data 0, 0 data 10, 0.25 data 20, 0.85 call load_tbl(steer_x(),steer_y()) sub curve(x(),y(),f,v,r) n=ubound(x) w=clamp(v, x(0), x(n)) r=y(n) for i=0 to n-1 if w<=x(i+1) then r=lerp(y(i), y(i+1), ease(f, 0, (w-x(i))/(x(i+1)-x(i)))) exit end if next i end sub 'last frame touch position ltx=0 :lty=0 'keep a list to 4 last drag speed dim dragx(3),dragy(3) 'next idx steeri=0 'current horizontal/vertical steer drag dragh=0 :dragv=0 'race progress racey=0 'center the track trackx=(shown.w-28*8)/2 'race zero is place down on the device tracky=(shown.h-36*8)/2+30*8 'center the car carx=(28*8)/2+trackx 'at the zero of the race cary=tracky 'car speed in pixel per frames speed=0 'acc duration in second, max=10 accd=0 'acc acc=0 'acc cap capa=0 'air resistance air=0 'steer quantity relative to center steer=0 'car position turn=0 'next skidmarks sprite skid=101 for i=101 to 169 sprite i size 1 next i bg 3 bg copy 0,0,28,8 to 0,0 bg copy 0,0,28,8 to 0,8 bg copy 0,0,28,8 to 0,16 bg copy 0,0,28,8 to 0,24 bg copy 0,0,28,8 to 0,30 bg copy 0,0,28,8 to 0,38 bg copy 0,0,28,8 to 0,46 bg copy 0,0,28,8 to 0,54 bg copy 0,0,28,8 to 0,60 scroll 3,-trackx,-tracky-racey sprite 100,carx-12,cary-12,16 sprite 100 size 2 pal 1 'temp mx=0 my=0 on thumbnail call t sub t wait tap px=sprite.x(100) py=sprite.y(100) trace"p",px,py nx=180/2 ny=180/2 trace"n",nx,ny dx=nx-px dy=ny-py trace"d",dx,dy for i=0 to 3 scroll i,scroll.x(i)-dx,scroll.y(i)-dy next i for i=0 to 169 sprite i,sprite.x(i)+dx,sprite.y(i)+dy, next i end end sub 'call t do scroll 3,-trackx,-tracky-racey wait vbl 'compute acc if touch then accd=min(accd+1/60, 10) call curve(accd_x(), accd_y(), 0, accd, acc) call curve(accs_x(), accs_y(), 0, speed, capa) acc=min(acc, capa) else accd=0 acc=0 end if 'compute air drag call curve(drag_x(),drag_y(),0, speed,air) if speed<=0 then air=0 'compute speed speed=max(speed+(acc-air)/60, 0) add racey,speed 'store last drag gesture if touch and not tap then dragx(steeri)=touch.x-ltx dragy(steeri)=touch.y-lty else dragx(steeri)=0 dragy(steeri)=0 end if add steeri,1,0 to ubound(dragx) if touch then ltx=touch.x lty=touch.y end if 'compute final drag gesture dragh=0 :dragv=0 for i=0 to ubound(dragx) add dragh,dragx(i) add dragv,dragy(i) next i dragh=dragh/ubound(dragx) dragv=dragv/ubound(dragx) 'apply steer call curve(steer_x(),steer_y(),0, dragh,steer) add turn,steer*speed 'snap to closest lane lane=clamp(int(turn/24+0.5),-2,2) snap=abs(steer)<0.03 dist=lane*24-turn if snap then if dist>0 then add turn,min(0.2,dist) else if dist<0 then add turn,max(-0.2,dist) end if end if 'change car asset change=carx-12+turn-sprite.x(100) sprite 100 flip change<0,0 change=abs(change) if change>1.2 then sprite 100,,,19 else if change<0.2 then sprite 100,,,16 end if 'previous position prev=sprite.x(100) 'draw car sprite 100,carx-12+turn,cary-12, 'advance previous skidmark for i=101 to 169 if sprite.y(i)>shown.h then sprite off i else sprite i,,sprite.y(i)+speed, end if next i 'draw skidmark if abs(acc)>3 or change>2 then 'current car position curr=sprite.x(100) for i=0 to speed step 3 t=i/speed sprite skid,lerp(prev,curr,t)+4,cary-t*speed,64 'sprite skid+1,carx-8+turn,cary+min(4,speed/2),64 add skid,1,101 to 169 next i end if 'add skid,2,101 to 168 mx=max(abs(dragh),mx) my=max(abs(dragv),my) 'if timer>7600 then 'do 'wait vbl 'loop 'end if 'h=20 'v=40 goto _1 bg 0 pal 2 text 2,8,left$(str$(speed)+" ",6) text 2,9,left$(str$(acc-air)+" ",6) text 2,10,left$(str$(sgn(change))+" ",6) text 2,11,left$(str$(change)+" ",6) if snap then text 2,12,"snap " else text 2,12,"drive" end if _1: loop #1:DEFAULT PALETTES 12030605050218000A020200002E2D2C 0022201F00363534001E190200060504 #2:DEFAULT CHARACTERS 00000000000000000000000000000000 FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF FFFFFFFFFFFFFFFFE7E7E7E7E7E7E7E7 00000000000000000000000000000000 00000000000000000000000000000000 00000000000000000000000000000000 00000000000000000000000000000000 00000000000000000000000000000000 00000000000000000000000000000000 00000000000000000000000000000000 00000000000000000000000000000000 00000000000000000000000000000000 525252D2F2D2F2527666666656360676 52D2F2DFFB4F4B4A666656300C6A6666 4A4F4B4F4B4A4A4A6E606C6A6666666E 4A4A4A4A4A4A4A4A6E6E6E6E6E6E6E6E 00000000000000000000000000000101 0000000000003CC3000000007EFFC33C 00000000000000000000000000008080 00000000000000000000000000000000 0000000000003CC30000000038FFC33C 00000000000000400000000000008080 00000003060C1A120000000000000000 00007EC30000000000000000707F7FFF 000000C060301808000000000000E0E0 00000003060C18100000000000000000 00007EC300181800000000000000017F 000000C060301808000000000000E0F0 00000003060C1A10000000000000000F 00007EC30018180000000000000000FF 000000C06030580800000000000000F0 00000000000000000000000000000000 00000000000000000103010101010101 8181818181FFFFFF7E7E7E7E7E7E7E7E 000000000000000080C0808080808080 00000101010101000301000000000203 81810102F2FEFE3E7E7EFEFDFDFDFDFD C0C0C040408080804040408080000000 1130202E2E2030100000010101030303 0000000000000000FFFFFFFFFFFFFFFF 080C047474040C88C0C0C08080800000 10302020202030100F0F0F0F0F0F0F0F 0000000000000000FFFFFFFFFFFFFFFF 080C040404040C08F0F0F0F0F0F0F0F0 10302020202030100F0F0F0F0F0F0F0F 0000000000000000FFFFFFFFFFFFFFFF 080C040404040C08F0F0F0F0F0F0F0F0 00000000000000000000000000000000 00000101000000000101010100000000 001881FF00000000FFE7FF8100000000 00008080000000008080808000000000 00030300000000000303030000000000 3000E31F00000000CFFF1F0300000000 80808080000000000080808000000000 10180C06030000000707000000000000 00000010C37E0000FFFEFE0E00000000 C8D83060C00000000000000000000000 10180C06030000000F07000000000000 00181800C37E0000FE80000000000000 08183060C00000000000000000000000 101A0C06030000000F00000000000000 00181800C37E0000FF00000000000000 08583060C0000000F000000000000000 00000000000000000000000000000000 00000000000000000010181808180800 00000000000000000018180008180810 00000000000000000018101810181010 00000000000000000030301020102000 #3:BACKGROUND 00001C40000000000000000000000000 02000100010002000100010002000100 01000200010001000200010001000200 00000000000000000000000000000000 00000000000000000200010001000200 01000100020001000100010001000100 02000100010002000100000000000000 00000000000000000000000000000000 02000100010001000100010002000100 01000200010001000100010001000200 00000000000000000000000000000000 00000000000000000200010001000200 01000100020001000100020001000100 02000100010002000100010000000000 00000000000000000000000000000000 02000100010002000100010002000100 01000200010001000200010001000200 00000000000000000000000000000000 00000000000000000200010001000200 01000100020001000100010001000100 02000100010002000100000000000000 00000000000000000000000000000000 02000100010001000100010002000100 01000200010001000100010001000200 00000000000000000000000000000000 00000000000000000200010001000200 01000100020001000100020001000100 02000100010002000100010000000000 00000000000000000000000000000000 02000100010002000100010002000100 01000200010001000200010001000200 00000000000000000000000000000000 00000000000000000200010001000200 01000100020001000100010001000100 02000100010002000100000000000000 00000000000000000000000000000000 02000100010001000100010002000100 01000200010001000100010001000200 00000000000000000000000000000000 00000000000000000200010001000200 01000100020001000100020001000100 02000100010002000100010000000000 00000000000000000000000000000000 02000100010002000100010002000100 01000200010001000200010001000200 00000000000000000000000000000000 00000000000000000200010001000200 01000100020001000100010001000100 02000100010002000100000000000000 00000000000000000000000000000000 02000100010001000100010002000100 01000200010001000100010001000200 00000000000000000000000000000000 00000000000000000200010001000200 01000100020001000100020001000100 02000100010002000100010000000000 00000000000000000000000000000000 00000000000000000000000000000000 00000000000000000000000000000000 00000000000000000000000000000000 00000000000000000200010001000100 01000100010001000100010001000100 01000100010002000000000000000000 00000000000000000000000000000000 02000100010001000100010001000100 01000100010001000100010001000200 00000000000000000000000000000000 00000000000000000200010001000100 01000100010001000100010001000100 01000100010002000000000000000000 00000000000000000000000000000000 02000100010001000100010001000100 01000100010001000100010001000200 00000000000000000000000000000000 00000000000000000200010001000100 01000100010001000100010001000100 01000100010002000000000000000000 00000000000000000000000000000000 02000100010001000100010001000100 01000100010001000100010001000200 00000000000000000000000000000000 00000000000000000200010001000100 01000100010001000100010001000100 01000100010002000000000000000000 00000000000000000000000000000000 02000100010001000100010001000100 01000100010001000100010001000200 00000000000000000000000000000000 00000000000000000200010001000100 01000100010001000100010001000100 01000100010002000000000000000000 00000000000000000000000000000000 02000100010001000100010001000100 01000100010001000100010001000200 00000000000000000000000000000000 00000000000000000200010001000100 01000100010001000100010001000100 01000100010002000000000000000000 00000000000000000000000000000000 02000100010001000100010001000100 01000100010001000100010001000200 00000000000000000000000000000000 00000000000000000200010001000100 01000100010001000100010001000100 01000100010002000000000000000000 00000000000000000000000000000000 02000100010001000100010001000100 01000100010001000100010001000200 00000000000000000000000000000000 00000000000000000200010001000100 01000100010001000100010001000100 01000100010002000000000000000000 00000000000000000000000000000000 02000100010001000100010001000100 01000100010001000100010001000200 00000000000000000000000000000000 00000000000000000200010001000100 01000100010001000100010001000100 01000100010002000000000000000000 00000000000000000000000000000000 02000100010001000100010001000100 01000100010001000100010001000200 00000000000000000000000000000000 00000000000000000200010001000100 01000100010001000100010001000100 01000100010002000000000000000000 00000000000000000000000000000000 02000100010001000100010001000100 01000100010001000100010001000200 00000000000000000000000000000000 00000000000000000200010001000100 01000100010001000100010001000100 01000100010002000000000000000000 00000000000000000000000000000000 02000100010001000100010001000100 01000100010001000100010001000200 00000000000000000000000000000000 00000000000000000200010001000100 01000100010001000100010001000100 01000100010002000000000000000000 00000000000000000000000000000000 02000100010001000100010001000100 01000100010001000100010001000200 00000000000000000000000000000000 00000000000000000200010001000100 01000100010001000100010001000100 01000100010002000000000000000000 00000000000000000000000000000000 02000100010001000100010001000100 01000100010001000100010001000200 00000000000000000000000000000000 00000000000000000200010001000100 01000100010001000100010001000100 01000100010002000000000000000000 00000000000000000000000000000000 02000100010001000100010001000100 01000100010001000100010001000200 00000000000000000000000000000000 00000000000000000200010001000100 01000100010001000100010001000100 01000100010002000000000000000000 00000000000000000000000000000000 02000100010001000100010001000100 01000100010001000100010001000200 00000000000000000000000000000000 00000000000000000200010001000100 01000100010001000100010001000100 01000100010002000000000000000000 00000000000000000000000000000000 02000100010001000100010001000100 01000100010001000100010001000200 00000000000000000000000000000000 00000000000000000200010001000100 01000100010001000100010001000100 01000100010002000000000000000000 00000000000000000000000000000000 02000100010001000100010001000100 01000100010001000100010001000200 00000000000000000000000000000000 00000000000000000200010001000100 01000100010001000100010001000100 01000100010002000000000000000000 00000000000000000000000000000000 02000100010001000100010001000100 01000100010001000100010001000200 00000000000000000000000000000000 00000000000000000200010001000100 01000100010001000100010001000100 01000100010002000000000000000000 00000000000000000000000000000000 02000100010001000100010001000100 01000100010001000100010001000200 00000000000000000000000000000000 00000000000000000200010001000100 01000100010001000100010001000100 01000100010002000000000000000000 00000000000000000000000000000000 02000100010001000100010001000100 01000100010001000100010001000200 00000000000000000000000000000000 00000000000000000200010001000100 01000100010001000100010001000100 01000100010002000000000000000000 00000000000000000000000000000000 02000100010001000100010001000100 01000100010001000100010001000200 00000000000000000000000000000000 00000000000000000200010001000100 01000100010001000100010001000100 01000100010002000000000000000000 00000000000000000000000000000000 02000100010001000100010001000100 01000100010001000100010001000200 00000000000000000000000000000000 00000000000000000200010001000100 01000100010001000100010001000100 01000100010002000000000000000000 00000000000000000000000000000000 02000100010001000100010001000100 01000100010001000100010001000200 00000000000000000000000000000000 00000000000000000200010001000100 01000100010001000100010001000100 01000100010002000000000000000000 00000000