Dark Bit Factory & Gravity

PROGRAMMING => Other languages => Yabasic => Topic started by: Clanky on February 10, 2008

Title: Yabasic on YouTube
Post by: Clanky on February 10, 2008
Looked up Yabasic on YouTube came up with this ;)

Enjoy!!!
--if that is Yabasic... it's great!!

http://www.youtube.com/watch?v=CdpR3hU5bAI (http://www.youtube.com/watch?v=CdpR3hU5bAI)
Title: Re: Yabasic on YouTube
Post by: Jim on February 10, 2008
cool :)
Title: Re: Yabasic on YouTube
Post by: rain_storm on February 10, 2008
I saw this before but its one impressive program aint it.
Title: Re: Yabasic on YouTube
Post by: Stonemonkey on February 11, 2008
Nice find, it gave me an idea. This is something I'd been working on on the ps2 a few years ago and since I never managed to get xport working so not many saw it running other than a couple of screenshots.

http://www.stonemonkie.pwp.blueyonder.co.uk/F1_GP_yab.avi        1.4Mb download
Title: Re: Yabasic on YouTube
Post by: ninogenio on February 11, 2008
very impressive fryer!

how the eck did you get it to run so smooth on the ps2? id love to see that game running on your ogl engine.
Title: Re: Yabasic on YouTube
Post by: rain_storm on February 11, 2008
Thats incredible stonemonkey. it runs so smooth. Proof that yabasic is a very capable language. And they only show a pic of a tetris clone on the wiki when there is code like this out there. I laugh at all the folk that said you can only draw boxes and circles in yabasic.
Title: Re: Yabasic on YouTube
Post by: Stonemonkey on February 11, 2008
Thanks for the comments, 'very capable' is perhaps not quite how I would describe yabasic but it was fun with a bit of frustration thrown in. I think I decided early on to make that game run at 25fps, it could only just draw the gfx at 50fps and that was without the ai, collisions, player control and "physics"

If anyone's interested I will post the source code but unfortunately it'll have to be in the form of photos of the code in the editor so if anyone's up for some 80s style nostalgia kind of like typing in games from a magazine it's all yours.
Title: Re: Yabasic on YouTube
Post by: rain_storm on February 11, 2008
I'll have a go at that  :cheers:
Title: Re: Yabasic on YouTube
Post by: Stonemonkey on February 11, 2008
Here you go then.

http://www.stonemonkie.pwp.blueyonder.co.uk/f1_source_images.zip
Title: Re: Yabasic on YouTube
Post by: ninogenio on February 11, 2008
nice 1 fryer i cant wait to have a shot k+
Title: Re: Yabasic on YouTube
Post by: rain_storm on February 12, 2008
Thanks for sharing the source code stonemonkey, have some Karma. I'v already started typing it up
Title: Re: Yabasic on YouTube
Post by: Stonemonkey on February 12, 2008
cool, let me know what you've got done so far and I'll make a start on some of it, I'll start from the last page and work back.
Title: Re: Yabasic on YouTube
Post by: rain_storm on February 12, 2008
Just startin page 12 now :D
Title: Re: Yabasic on YouTube
Post by: Stonemonkey on February 12, 2008
heh, I've just worked from the end back to page 10
Title: Re: Yabasic on YouTube
Post by: Stonemonkey on February 12, 2008
Now for the fun bit, debugging. hopefully it'll not be too bad but from what i remember from the magazines there was always something.


Code: [Select]
'page 10


'page 11
  xl=tx
  tx=xr*cs-yr*sn
  yr=xr*sn+ry*cs
  xr=tx
  dx=oxc-xc:dy=oyc-yc
  xc=xc+(8-yc)*dx/dy
  dx=oxl-xl:dy=oyl-yl
  xl=xl+(8-yl)*dx/dy
  dx=oxr-xr:dy=oyr-yr
  xr=xr+(8-yr)*dx/dy
  vz=600/8
  xc2=xc*vz
  yc2=vz*2
  xr2=xr*vz
  xl2=xl*vz
  vz=600/oyc
  xc1=oxc*vz
  yc1=vz*2
  vz=600/oyr
  xr1=oxr*vz


'page 12
  yr1=vz*2
  vz=600/oyl
  xl1=oxl*vz
  yl1=vz*2
  clear fill triangle xl1,yl1 to xl2,yc2 to xc2,yc2
  clear fill triangle xl1,yl1 to xc1,yc1 to xc2,yc2
  clear fill triangle xr1,yr1 to xr2,yc2 to xc2,yc2
  clear fill triangle xr1,yr1 to xc1,yc1 to xc2,yc2
'loop to draw track/barriers/trees
  lt=34
  donet=0
  doneb=0
  mem=mod(lt+tp,l)
  xr=x(mem)-xp
  yr=y(mem)-yp
  x=xr*cs-yr*sn
  y=xr*sn+yr*cs
  repeat lt=lt-1
    mem=mod(lt+tp+1,l)
    an=mod(va(mem)-a+5760,5760)



'page 13
  x=x-st(an)
  y=y-ct(an)
  if y<0 goto none
  xo=ce(an)
  yo=se(an)
  c=20+60-(y/8)   '************************
  c2=c*1.5
  if lt>28 goto trees
  if lt>22 goto barriers
  if lt=22 or lt=12 goto track
  if lt>8 goto barriers
label track
    ocxr=cxr:ocyr=cyr
    ocxl=cxl:ocyl=cyl
    vz=600/(y+y0)
    cxr=(x+xo)*vz
    cyr=vz*2
    vz=600/(y-yo)
    cxl=(x-xo)*vz
    cyl=vz*2


'page 14
donet=donet+1
if donet<2 goto barriers
  clear fill triangle ocxl,ocyl to ocxr,ocyr to cxl,cyl
  clear fill triangle ocxr,ocyr to cxl,cyl to cxr,cyr
if lt>7 goto barriers
    orxr=rxr:oryr=ryr
    orxl=rxl:oryl=ryl
    w=rm(mem)
    xr=xo*w:yr=yo*w
    vz=600/(y+yr)
    rxr=(x+xr)*vz
    ryr=vz*2
    vz=600/(y-yr)
    rxl=(x-xr)*vz
    ryl=vz*2
if lt=7 goto barriers
      setrgb 1,12,20,3
      ac=and(mem,1)*c2
      setrgb 2,c2,ac,ac
    gtriangle orxl,oryl to ocxl,ocyl to rxl,ryl


'page 15
  gtriangle orxr,oryr to ocxr,ocyr to rxr,ryr
  setrgb 1,c2,ac,ac
  gtriangle ocxl,ocyl to cxl,cyl to rxl,ryl
  gtriangle ocxr,ocyr to cxr,cyr to rxr,ryr
label barriers
if lt=28 or lt=15 goto cb
if lt>12 goto trees
label cb
    obxr=bxr:obyr1=byr1:obyr2=byr2
    obxl=bxl:obyl1=byl1:obyl2=byl2
    xr=xo*2
    yr=yo*2
    byr2=600/(y+yr)
    bxr=(x+xr)*byr2
    byr1=byr2*2
    byl2=600/(y-yr)
    bxl=(x-xr)*byl2
    byl1=byl2*2
doneb=doneb+1
if doneb<2 goto trees


'page 16
  setrgb 1,c2,c2,c2
  fill triangle obxr,obyr1 to obxr,obyr2 to bxr,byr1
  fill triangle obxl,obyl1 to obxl,obyl2 to bxl,byl1
  fill triangle bxr,byr1 to bxr,byr2 to obxr,obyr2
  fill triangle bxl,byl1 to bxl,byl2 to obxl,obyl2
label trees
  if mem=1 gosub sl
  w=td(mem)
  xr=xo*w:yr=yo*w
  vz=600/(y+yr)
  txr=(x+xr)*vz
  tyr1=vz*2
  tyr2=-tyr1*th(mem)
  tys=-tyr1*12
  vz=600/(y-yr)
  txl=(x-xr)*vz
  tyl1=vz*2
  tyl2=-tyl1*13
  c5=c*.5
  setrgb 1,0,c5,0


'page 17
    setrgb 2,0,c5+15,0
    w=(tyr1-tys)/4.5
    if w>0 gtriangle txr-w,tyr1 to txr,tyr2 to txr+w,tyr1
    w=(tyl1-tyl2)/5
    if w>0 gtriangle txl-w,tyl1 to txl,tyl2 to txl+w,tyl1
label none
    tc=mod(lt+tp+1,l)
    if tc(tc)>0 gosub testcar
  until(lt=1)
  tc=mod(tp+1,l)
  if tc(tc)>0 gosub testcar
  tc=tp
  if tc(tc)>0 gosub testcar
'draw cockpit
  setrgb 1,4,4,4
  fillrect 202,102 to 320,256
  fillrect -202,102 to -320,256
  sa=(left(1)-right(1))*50
  fill triangle 202,102 to 202+sa,200 to 202-sa,200
  fill triangle -202,102 to -202-sa,200 to -202+sa,200


'page 18
  setrgb 1,40,40,40
  line 202,102 to 202+sa,200
  line -202,102 to -202+sa,200
  setrgb 1,0,0,0
  fill rect -320,150 to 320,256
  fill triangle -320,150 to 320,150 to 0,110
  triangle -320,150 to 320,150 to 0,90
  setrgb 1,0,255,0
  n=2+int(mod(ve(1)*100,30)/6)
  for i=1 to n
    x=(i-4)*10
    if i=4 setrgb 1,255,0,0
  next i
  setrgb 1,255,0,0
  ve=ve(1)*100
  text -15,200,str$(int(ve))
  g=1+int(ve/30)
  text -55,170,str$(int(g))



'page 19
until(1=0)
label testcar
  temp=0
  car=1
'remove next line(test only)
'if mxcar=1 return
  repeat car=car+1
    if tp(car)<>tc goto blank
    if tc(tc)<>car gosub car
    if tc(tc)=car temp=car
label blank
  until(car=mxcar)
  if temp=0 return
  car=temp
  gosub car
return
label car
  arx=xp(car)-xp:ary=yp(car)-yp
  carx=arx*c(5760-a)+ary*s(5760-a)
  cary=-arx*s(5760-a)+ary*c(5760-a)


'page 20
  if cary<0 return
    wa=mod(720-(a(car)-a)/16,360)
    setrgb 1,4,4,4
    r=pr(car)+c
    g=pg(car)+c
    b=pb(car)+c
    w=0
    repeat w=w+1
      wx=cx(w,wa)+carx
      wy=cy(w,wa)+cary
      vz=600/wy
      cx=wx*vz
      cy=vz*1.2
      wsv=vz*0.7
      wsh=vz*0.5
      if wy>0 fill rect cx-wsh,cy-wsv to cx+wsh,cy+wsv
      if w=2 gosub body
    until(w=4)
    setrgb 1,r/2,g/2,b/2
    setrgb 2,r,g,b


'page 21
  setrgb 3,r,g,b
  if cary<3 return
  repeat w=w+1
    wx=cx(w,wa)+carx
    wy=cy(w,wa)+cary
    vz=600/wy
    tx(w)=wx*vz
    if w=6 or w=7 ty(w)=vz*.4
    if w=5 or w=8 ty(w)=vz*.6
  until(w=8)
gtriangle tx(5),ty(5) to tx(6),ty(6) to tx(7),ty(7)
  setrgb 2,r/2,g/2,b/2
gtriangle tx(5),ty(5) to tx(8),ty(8) to tx(7),ty(7)
  setrgb 3,12,20,3
return
label body
'  setrgb 1,0,0,0
  vz=600/cary
  cx=carx*vz
  cy=vz*1.8*c(wa*16)
 

'page 22
    wx=cx(9,wa)+carx
    wy=cy(9,wa)+cary
if wy<0 return
    uz=600/wy
    ex=wx*uz
    ey=uz*1.4
    setrgb 1,r,g,b
    fill triangle ex,ey to cx-cy,vz to cx+cy,vz
    setrgb 1,r/2,g/2,b/2
  fill triangle cx-cy,cy to cx-cy,vz to ex,ey
  fill triangle cx+cy,cy to cx+cy,vz to ex,ey
  setrgb 1,7,7,7
return

label sl
  vx=fl/(y+yo)
  cxr=(x+xo)*vz
  cyr=vz+vz
  vz=fl/(y-yo)
  cxl=(x-xo)*vz


'page 23
    cyl=vz+vz
  clear line cxr,cyr to cxr,-cyr*2
  clear line cxl,cyl to cxl,-cyl*2
  setrgb 1,35,35,35
  fill triangle cxl,-cyl*1.6 to cxl,-cyl*2.2 to cxr,-cyr*1.6
  fill triangle cxr,-cyr*1.6 to cxr,-cyr*2.2 to cxl,-cyl*2.2
return

end
label setup
  open window 640,512
  window origin "CC"
  dim s(5760),c(5760),tx(20),ty(20)
  dim st(5760),ct(5760)
  dim se(5760),ce(5760)
mxlen=1000
  dim mh(36),th(mxlen),td(mxlen)



'page 24
  dim x(mxlen),y(mxlen),xo(mxlen),yo(mxlen),va(mxlen)
  dim rm(mxlen)
  dim cx(20,360),cy(20,360)
mxcar=6
  dim xp(mxcar),yp(mxcar),tp(mxcar),a(mxcar),ve(mxcar)
  dim ac(mxcar),br(mxcar),left(mxcar),right(mxcar)
  dim tc(mxlen),oa(mxcar),pr(mxcar),pg(mxcar),pb(mxcar)
dim cf(mxcar)
  dim dat(1000,10),length(10)
  for i=0 to 5760
    s(i)=sin(i/2880*pi)
    c(i)=cos(i/2880*pi)
    st(i)=sin(i/2880*pi)*15
    ct(i)=cos(i/2880*pi)*15
    se(i)=sin(i/2880*pi)*12
    ce(i)=-cos(i/2880*pi)*12
  next i
  for i=0 to 1000
    td(i)=5.5+2.8*sin(i*i)
    th(i)=12+4*sin(l1*i+i)


'page 25
  next i
  for i=1 to 36
    mh(i)=-100-50*sin(i*cos(i))
  next i
  restore trackdata
  read tracks,track
  for i=1 to tracks
    read length(i)
    for j=1 to length(i)
      read dat(j,i)
    next j
  next i
  level=800-(4-level)*40
  gosub makecar
return


'page 26
  fl=600
  setrgb 0,15,15,15
  ctp=1
  for i=2 to mxcar
    yp(i)=i*20
    xp(i)=10*(and(i,1)-.5)
  next i
return

label maketrack
  a=0
  for i=0 to length(track)
    w=0
    for j=i-5 to i+5
      k=mod(j+length(track),length(track))
      w=w+abs(dat(k,track))
    next j
    rm(i)=1.1+w/300
    a=mod(a+dat(i,track)*16+5760,5760)
    va(i)=a


'page 27
    if i>0 then
      x(i)=x(i-1)+s(a)*15
      y(i)=y(i-1)+c(a)*15
    fi
    xo(i)=c(a)*12
    yo(i)=-s(a)*12
    rect x(i)/8,y(i)/8 to x(i)/8+1,y(i)/8+1
  next i
return

label makecar
  restore cardata
  for i=1 to 9
    read cx(i,0),cy(i,0)
    for j=1 to 360
      a=j*16
      cx(i,j)=cx(i,0)*c(a)-cy(i,0)*s(a)
      cy(i,j)=cx(i,0)*s(a)+cy(i,0)*c(a)
    next j
  next i

'page 28
  ar=.002:bm=.02:am=.014
  for i=1 to mxcar
    read pr(i),pg(i),pb(i)
  next i
return

label cardata
data 1.5,3,-1.5,3,1.5,-3,-1.5,-3
data -1.2,-3.1,-1.2,-3.6,1.2,-3.6,1.2,-3.6,1.2,-3.1
data 0,-3
data 80,0,0
data 80,80,0
data 80,80,80
data 0,0,80
data 80,40,0
data 0,60,0
data 0,40,80
data 40,40,40

'page 29
data 5,5
data 79
data 0,0,0,0,0
data 9,9,9,9,9
data 9,9,9,9,9
data 0,0,0,0,0
data 0,0,0,0,0
data 9,9,9,9,9
data 9,9,9,9,9
data 0,0,0,0,0
data 0,0,0,0,0
data 9,9,9,9,9
data 9,9,9,9,9
data 0,0,0,0,0
data 0,0,0,0,0
data 9,9,9,9,9
data 9,9,9,9,9
data 0,0,0,0

'page 30
data 0,0,0,0,0,0
data 0,0,0,0,0
data 0,0,0,0,0
data 0,0,0,0,0
data 1,1,1,1,1
data 0,0,0,0,0
data 9,9,9,9,9
data 9,9,9,9,9
data 0,0,0,0,0
data 9,9,9,9,9
data -9,-9,-9,-9,-9
data 0,0,0,0,0
data 9,9,9,9,9
data 9,9,9,9,9
data 9,0,9,9,0,0
data 0,0,0,0,0
data 0,0,0,0,0
data 0,0,0,0,0
data 0,0,0,0,0
data 0,0,0,0,0

'page 31
data 0,0,0,0,0
data 7,7,8,8,8
data 8,7,7,8,8
data 8,7,8,9,8
data 8,9,7,4,4,0
data 265
data 0,0,0,0,0
data 0,0,0,0,0
data 0,0,0,0,0
data 0,0,0,0,0
data 9,9,9,9,9
data 9,9,9,9,9
data 0,0,0,0,0
data 0,0,0,0,0
data 9,9,9,9,9
data 9,9,9,9,9
data 0,0,0,0,0
data 0,0,0,0,0
data 0,0,0,0,0
data 0,0,0,0,0

'page 32
data 0,0,0,0,0
data 0,0,0,0,0
data -9,-9,-9,-9,-9
data -9,-9,-9,-9,-9
data 0,0,0,0,0
data 0,0,0,0,0
data 0,0,0,0,0
data 0,0,0,0,0
data 9,9,9,9,9
data 9,9,9,9,9
data 0,0,0,0,0
data 0,0,0,0,0
data 0,0,0,0,0
data 0,0,0,0,0
data 0,0,0,0,0
data 0,0,0,0,0
data 9,9,9,9,9
data 9,9,9,9,9
data 0,0,0,0,0
data 0,0,0,0,0

'page 33
data 0,0,0,0,0
data 0,0,0,0,0
data 0,0,0,0,0
data 0,0,0,0,0
data 0,0,0,0,0
data 0,0,0,0,0,0,0,0
data 9,9,9,9,9
data 9,9,9,9,9
data 0,0,0,0,0
data 0,0,0,0,0
data 0,0,0,0,0
data 0,0,0,0,0
data 0,0,0,0,0
data 0,0,0,0,0
data 0,0,0,0,0
data 0,0,1,0,0
data 0,0,0,0,0
data 0,0,0,0,0,0,0,0

'page 34
data 0,0,0,0,0
data 0,0,0,0,0
data 0,0,0,0,0
data 10,10,10,10,10
data 10,10,10,10
data 10,10,10,10,10
data 10,10,10,10
data 0,0,0,0,0
data 0,0,0,0,0
data 0,0,0,0,0
data 0,0,0,0,0
data 0,0,0,0,0
data 0,0,0,0,0
data 10,10,10,10,10
data 10,10,10,10
data 10,10,10,10,10
data 10,10,10,10
data 0,0,0,0,0
data 0,0,0,0,0
data 0,0,0,0

'page 35
data 553
data 0,0,0,0,0,0,0,0,0,0
data 0,0,0,0,0,0,0,0,0,0
data 0,0,0,0,0,0,0,0,0,0
data 0,0,0

data 0,0,0,0,0,0,0,0,0,0
data 0,0,0,0,0,0,0,0,0,0
data 0,0,0,0,0,0,0,0,0,0
data 9,9,9,9,9,9,9,-9,-9,-9
data -9,-9,-9,-9,-9,-9,8,7,6,6
data 2,2,2,2,2,2,2,2,2,2
data 2,2,2,2,2,2,2,2,2,2
data 2,2,2,2,2,2,2,2,2,2
data 2,2,2,2,2,2,2,2,2,2
data 0,0,0,0,0,0,0,0,0,0
data 0,0,0,0,0,0,0,0,0,0
data 0,0,0,0,0,0,0,0,0,0
data -8,-8,-8,-8,-8,-8,-8,-8,0,0
data 0,0,8,8,8,8,8,8,8,8

'page 36
data 0,0,0,0,0,0,0,0,0,0
data 0,0,0,0,0,0,0,0,0,0
data 4,4,4,4,4,4,4,4,4,4
data 4,4,4,4,4,4,4,4,4,4
data 0,0,0,0,0,0,0,0,0,0
data 0,0,0,0,0,0,0,0,0,0
data 4,4,4,4,4,4,4,4,4,4
data 4,4,4,4,4,4,4,4,4,4
data 0,0,0,0,0,0,0,0,0,0
data 0,0,0,0,0,0,0,0,0,0
data -2,-2,-2,-2,-2,-2,-2,-2,-2,-2
data 0,0,0,0,0,0,0,0,0,0
data 0,0,0,0,0,0,0,0,0,0
data 0,0,0,0,0,0,0,0,0,0
data 0,0,0,0,0,0,0,0,0,0
data -7,-7,-7,-7,-7,-7,-7,-7,-7,-2
data 7,7,7,7,7,7,7,7,7,7
data -6,-6,-6,-6,-6,-5,-5,-5,-5,-4
data 0,0,0,0,0,0,0,0,0,0
data 0,0,0,0,0,0,0,0,0,0

'page 37
data 0,0,0,0,0,0,0,0,0,0
data 0,0,0,0,0,0,0,0,0,0
data 0,0,0,0,0,0,0,0,0,0
data 0,0,0,0,0,0,0,0,0,0
data 0,0,0,0,0,0,0,0,0,0
data 0,0,0,0,0,0,0,0,0,0
data 5,5,5,5,5,5,5,5,5,5
data 4,4,4,4,4,4,4,4,4,4

data 3,3,3,3,3,3,3,3,3,3
data 2,2,2,2,2,2,2,2,2,2
data 2,2,2,2,2,1,1,1,1,1
data 1,1,1,1,1,1,1,1,1,1
data 1,1,1,1,1,1,1,1,1,1
data 1,1,1,1,1,0,0,0,0,0

data 0,0,0,0,0,0,0,0,0,0
data 0,0,0,0,1,0,0,0,0,0
data -1,0,0,0,0,0,0,0,0,0
data 0,0,0,0,0,0,0,0,0,0
Title: Re: Yabasic on YouTube
Post by: rain_storm on February 12, 2008
Iv done up to page 18 it doesnt run yet tho
heres what I got

Code: [Select]
'page 1
'set demo to 0 to watch ai control
'1 for player control
demo=1

'set level for ai (1-easy 4-hard)
level=1

gosub setup
gosub maketrack
gosub setrace
repeat
  setdispbuf db
  db=1-db
  setdrawbuf db
  j1=peek("port1")
'loop for each car collision/ai/physics
  i=mxcar
  repeat
    tp=tc(tp(i))
    if tp=i or tp=0 goto nocoll

'page 2
      x1=xp(tp)-xp(i):y1=yp(tp)-yp(i)
      a1=a(i)
      sn=s(5760-a1)
      cs=c(5760-a1)
      yr=x1*sn+y1*cs
      if abs(yr)>6 goto nocoll
        xr=x1*cs-y1*sn
        if abs(xr)>3 goto nocoll
if cf(i)>10 and cf(tp)>0 goto nc2
'        a(tp)=mod(a(tp)+xr*8+5760, 5760)
'        a1=mod(a1-xr*8+5760,5760)
        xc=-(sig(xr)*3-xr)/8
        yc=-(sig(yr)*6-yr)/8
ca=c(a1):sa=s(a1)
        xp(tp)=xp(tp)-ca*xc+sa*yc
        yp(tp)=yp(tp)-sa*xc-ca*yc
        xp(i)=xp(i)+ca*xc-sa*yc
        yp(i)=yp(i)+sa*xc+ca*yc
'a(i)=a1
if cf(i)>0 and cf(tp)>0 goto nc2

'page 3
cf(i)=5
cf(tp)=15
vet=ve(i)
ve(i)=ve(tp)
ve(tp)=vet
goto nc2
label nocoll
  cf(tp)=cf(tp)-1
if cf(i)=0 cf(tp)=0
  cf(i)=cf(i)-1
label nc2
  i=i-1 until(i=0)
  i=0
  repeat i=i+1
'get cor info
    tp=tp(i)
    xp=xp(i)
    yp=yp(i)
    a=a(i)
    ve=max(ve(i),0)

'page 4
'get track position and update as required
    np=mod(tp+1,1)
    dxc=x(tp)-xp
    dyc=y(tp)-yp
    dxn=x(np)-xp
    dyn=y(np)-yp
    cd=dxc*dxc+dyc*dyc
    nd=dxn*dxn+dyn*dyn
    if nd>cd goto ai
      tc(np)=i
      if tc(tp)=i tc(tp)=0
      tp=np
label ai
    if tc(tp)=0 tc(tp)=i
    if i=demo goto noai
      np1=mod(np+2.9+int(ve*3.1),1)
      np2=mod(np+3.2+int(ve*7.3),1)
      np3=mod(10+np+int(ve*20),1)
      sn=s(a)
      cs=c(a)

'page 5
      dx1=xp-x(np1)
      dz1=yp-y(np1)
      dxr1=cs*dx1-sn*dz1
      dzr1=cs*dz1+sn*dx1
      dx2=xp-x(np2)
      dz2=yp-y(np2)
      dxr2=cs*dx2-sn*dz2
      dzr2=cs*dz2+sn*dx2
      dx3=xp-x(np3)
      dz3=yp-y(np3)
      dxr3=cs*dx3-sn*dz3
      dzr3=cs*dz3+sn*dx3
      tn1=atan(-dxr1,-dzr1)/pi*2880
      tn2=atan(-dxr2,-dzr2)/pi*2880
      tn3=atan(-dxr3,-dzr3)/pi*2880
      oa=oa(i)
'sig()*10
      oa=max(min(oa+sig(tn3)*4,50),-50)
      if tc(np)>0 and tc(np)<>i oa=(-oa(tc(np))+oa)/2
      tcp=tg(tp)

'page 6
      if tcp>0 and tcp<>i oa=-oa(tcp)/2
'ai control
      j1=32768
      if ve<1.3 j1=0
      if abs(tn2)<(level-ve*390) j1=16384
      if tn1>oa+30 j1=j1+32
      if tn1<oa-30 j1=j1+128
label noai
'collision detection
'off track/hit barrier
    rr=.0045
if i=1 and and(j1,512)=512 rr=.0005
    toff=(cd-nd+225)/30
    toff=cd-toff*toff
    lim=12*rm(tp)-1.5
    lim=lim*lim
    if toff>lim rr=.035
    if toff<529 goto nobarcol
      a=va(np)
      xp=(xp*9+x(tp))/10

'page 7
      yp=(yp*9+y(tp))/10
      ve=0
label nobarcol
'car control and physics
    ac=max(min(ac(i)+and(j1,16384)/81920-.1,1),0)
    br=max(min(br(i)+and(j1,32768)/16384-.1,1),0)
    left=max(min(left(i)+and(j1,128)/128*.35-.17,1),0)
    right=max(min(right(i)+and(j1,32)/32*.35-.17,1),0)
    res=ve*(rr+ve*ar)
    ve(i)=max(ve-res+ac*am-br*bm,0)
    sm=32*(2-ve)*ve*(1-br/2.6)
    a(i)=mod(a+(right-left)*sm+57600,5760)
    ve=ve(i)*4.5
    yp(i)=yp+c(a)*ve
   
xp(i)=xp+s(a)*ve
    tp(i)=tp
    ac(i)=ac
    br(i)=br
    left(i)=left
    right(i)=right

'page 8
    oa(i)=oa
  until(i=mxcar)
  xp=xp(1):yp=yp(1):a=a(1):tp=tp(1)
'draw background
  setrgb 1,100,100,100
  setrgb 2,60,60,90
  setrgb 3,60,60,90
  gtriangle 0,-600 to -550,0 to 550,0
  setrgb 2,0,40,10
  setrgb 3,0,40,10
  gtriangle 0,600 to -550,0 to 550,0
  setrgb 1,35,42,35
  setrgb 2,2,22,7
  setrgb 3,0,0,0
  mx=-mod(a*11/16,110)-320
  mh=a/160
  i=0
  repeat i=i+1
    gtriangle mx,mh(mh) to mx-100,0 to mx+100,0
    gtriangle mx-75,mh(mh)/2 to mx-175,0 to mx+25,0

'page 9
    mx=mx+110
    mh=1+mod(mh,36)
  until(i=8)
  mx=-mod(a*11/16,110)-330
  setrgb 1,12,37,3
  setrgb 3,12,20,3
  mh=a/160
  i=0
  repeat i=i+1
    mxt=mx+mh(mh)
    gtriangle mxt,-33 to mxt-8,0 to mtxt+8,0
    mh=1+mod(mh,36)
    mx=mx+110
  until(i=9)
'clipping for closest track section
  cs=c(a):sn=s(a)
  mem=mod(tp+3,1)
  oxc=x(mem)-xp:oyc=y(mem)-yp
  xo=xo(mem):yo=yo(mem)
  oxl=oxc-xo:oyl=oyc-yo

'page 10
  oxr=oxc+xo:oyr=oyc+yo
  mem=mod(tp+1,1)
  xc=x(mem)-xp:yc=y(mem)-yp
  xo=xo(mem):yo=yo(mem)
  xl=xc-xo:yl=yc-yo
  xr=xc+xo:yr=yc+yo
  tx=oxc*cs-oyc*sn
  oyc=oxc*sn+oyc*cs
  oxc=tx
  tx=oxl*cs-oyl*sn
  oyl=oxl*sn+oyl*cs
  oxl=tx
  tx=oxr*cs-oyr*sn
  oyr=oxr*sn+oyr*cs
  oxr=tx
  tx=xc*cs-yc*sn
  yc=xc*sn+yc*cs
  xc=tx
  tx=xl*cs-yl*sn
  yl=xl*sn+yl*cs

'page 11
  xl=tx
  tx=xr*cs-yr*sn
  yr=xr*sn+yr*cs
  xr=tx
  dx=okc-xc:dy=oyc-yc
  xc=xc+(8-yc)*dx/dy
  dx=oxl-xl:dy=oyl-yl
  xl=xl+(8-yl)*dx/dy
  dx=oxr-xr:dy=oyr-yr
  xr=xr+(8-yr)*dx/dy
  vz=600/8
  xc2=xc*vz
  yc2=vz*2
  xr2=xr*vz
  xl2=xl*vz
  vz=600/oyc
  xc1=oxc*vz
  yc1=vz*2
  vz=600/oyr
  xr1=oxr*vz

'page 12
  yr1=vz*2
  vz=600/oyl
  xl1=oxl*vz
  yl1=vz*2
  clear fill triangle xl1,yl1 to xl2,yl2 to xc2,yc2
  clear fill triangle xl1,yl1 to xc1,yc1 to xc2,yc2
  clear fill triangle xr1,yr1 to xr2,yr2 to xc2,yc2
  clear fill triangle xr1,yr1 to xc1,yc1 to xc2,yc2
'loop to draw track/barriers/trees
  lt=34
  donet=0
  doneb=0
  mem=mod(lt+tp,l)
  xr=x(mem)-xp
  yr=y(mem)-yp
  x=xr*cs-yr*sn
  y=xr*sn+yr*cs
  repeat lt=lt-1
    mem=mod(lt+tp+1,l)
    an=mod(va(mem)-a+5760,5760)

'page 13
    x=x-st(an)
    y=y-ct(an)
    if y<0 goto none
    xo=ce(an)
    yo=se(an)
    c=20+60-(y/8)
    c2=c*1.5
    if lt>28 goto trees
    if lt>22 goto barriers
    if lt=22 or lt=12 goto track
    if lt>8 goto barriers
label track
      ocx=cxr:ocyr=cyr
      ocxl=cxl:ocyl=cyl
      vz=600/(y-yo)
      cxr=(x+xo)*vz
      cyr=vz*2
      vz=600/(y+y0)
      cxl=(x-xo)*vz
      cyl=vz*2

'page 14
donet=donet+1
if donet<2 goto barriers
    clear fill triangle ocxl,ocyl to ocxr,ocyr to cxl,cyl
    clear fill triangle ocxr,ocyr to cxl,cyl to cxr,cyr
if lt>7 goto barriers
          orxr=rxr:oryr=ryr
          orxl=rxl:oryl=ryl
          w=rm(mem)
          xr=xo*w:yr=yo*w
          vz=600/(y+yr)
          rxr=(x+xr)*vz
          ryr=vz*2
          vz=600/(y-yr)
          rxl=(x-xr)*vz
          ryl=vz*2
if lt=7 goto barriers
            setrgb 1, 12,20,3
            ac=and(mem,1)*c2
            setrgb 2,c2,ac,ac
    gtriangle orxl,oryl to ocxl,ocyl to rxl,ryl

'page 15
    gtriangle orxr,oryr to ocxr,ocyr to rxr,ryr
            setrgb 1,c2,ac,ac
    gtriangle ocxl,ocyl to cxl,cyl to rxl,ryl
    gtriangle ocxr,ocyr to cxr,cyr to rxr,ryr
label bariers
if lt=28 or lt=15 goto cb
if lt>12 goto trees
label cb
      obxr=bxr:obyr1=byr1:obyr2=byr2
      obxl=bxl:obyl1=byl1:obyl2=byl2
      xr=x0*2
      yr=yo*2
      byr2=600/(y+yr)
      bxr=(x+xr)*byr2
      byr1=byr2*2
      byl2=600/(y-yr)
      bxl=(x-xr)*byl2
      byl1=by12*2
doneb=doneb+1
if doneb<2 goto trees

'page 16
    setrgb 1,c2,c2,c2
    fill triangle obxr,obyr1 to obxr,obyr2 to bxr,byr1
    fill triangle obxl,obyl1 to obxl,obyl2 to bxl,byl1
    fill triangle bxr,byr1 to bxr,byr2 to obxr,obyr2
    fill triangle bxl,byl1 to bxl,byl2 to obxl,obyl2
label trees
    if mem=1 gosub sl
    w=td(mem)
    xr=xo*w:yr=yo*w
    vz=600/(y+yr)
    txr=(x+xr)*vz
    tyr1=vz*2
    tyr2=-tyl1*13
    c5=c*.7
    setrgb 1,0,c5,0

'page 17
    setrgb 2,0,c5+15,0
    w=(tyr1-tys)/4.5
    if w>0 gtriangle txr-w,tyr1 to txr,tyr2 to txr+w,tyr1
    w=(tyl1-tyl1)/5
    if w>0 gtriangle txl-w,tyl1 to txl,tyl2 to txl+w,tyl1
label none
    tc=mod(lt+tp+1,l)
    if tc(tc)>0 gosub testcar
  until(lt=1)
  tc=mod(tp+1,l)
  if tc(tc)>0 gosub testcar
  tc=tp
  if tc(tc)>0 gosub testcar
'draw cockpit
  setrgb 1,4,4,4
  fill rect 202,102 to 320,256
  fill rect -202,102 to -320,256
  sa=(left(1)-right(1))*50
  fill triangle 202,102 to 202+sa,200 to 202-sa,200
  fill triangle -202,102 to -202-sa,200 to -202+sa,200

'page 18
  setrgb 1,40,40,40
  line 202,102 to 202+sa,200
  line -202,102 to -202+sa,200
  setrgb 1,0,0,0
  fill rect -320,150 to 320,256
  fill triangle -320,150 to 320,150 to 0,110
  triangle -320,150 to 320,150 to 0,90
  setrgb 1,0,255,0
  n=2+int(mod(ve(1)*100,30)/6)
  for i=1 to n
    x=(i-4)*10
    fill rect x,162 to x+6,168
    if i=4

Title: Re: Yabasic on YouTube
Post by: Stonemonkey on February 12, 2008
found a few bugs and it's kind of working although it's one of the test tracks so i think i've made a mistake in the data somewhere.



EDIT: bugs fixed, attachment 2 posts down.
Title: Re: Yabasic on YouTube
Post by: rain_storm on February 12, 2008
Ive found a few bugs myself Im proof reading through it atm but that is lookin good so far

Edit : All sorted now I think
Title: Re: Yabasic on YouTube
Post by: Stonemonkey on February 12, 2008
Sorted. :D

If you go to the setup routine near the end of the code you can change the number of cars with mxcars=

in the data section you can select other tracks, there's a line   Data 5,5     ,the first number is the number of tracks in the data, the second is the track selected so you can select tracks 1-5

player control by setting demo to 1

and you can change the ai level too.

cross (delete) accelerate
square(insert) brake
left/right (arrows) steer

Jim! you made the emu too fast, with 200 ai cars it's still running too fast!
Title: Re: Yabasic on YouTube
Post by: rain_storm on February 12, 2008
lol same time

Edit

200 now thats a sight to see. 300 is still acceptable speed. I finally got a lap without crashing but overtaking is hard
Title: Re: Yabasic on YouTube
Post by: Jim on February 13, 2008
Quote
Jim! you made the emu too fast, with 200 ai cars it's still running too fast!
LOL!

Jim
Title: Re: Yabasic on YouTube
Post by: Shockwave on February 13, 2008
I remember playing this game when we exchanged memory cards, I don't think I ever X-Ported this code though, it's a pity as it would have saved you a lot of typing.

The game seriously rules though and was one of the most impressive things that was ever made with Yabasic.

What amazed me the most were the race cars, I couldn't believe how you had made the models look so good with only a few simple shapes.
Title: Re: Yabasic on YouTube
Post by: Clanky on March 03, 2008
omg

I watch this and :bananaphallus:
I play this, and get stuck to the walls... haha.

Any way to make it run ... really slow instead of really fast? lol

Top Job!
Title: Re: Yabasic on YouTube
Post by: ninogenio on March 03, 2008
go to the edit tab in the emulator then go to options and check force flush rate and also make sure synce to 50hz (pal ps2) is checked. then it should run at an ok speed.
Title: Re: Yabasic on YouTube
Post by: Clanky on March 04, 2008
Yea it is checked, still is too fast (for me anyway)...

The demo is enough for me! Haha