'This is the Erland Rovik's porting to RapidQ of the Peter Cooper's QB Raytracer.
'I simply put it to work. Finally it behaves more or less as Peter's original
'It's the simplest one in the ABC packets, so donīt expect textures and things 
'It does'nt use DirectX so it should WORK in Linux (i don't have LINUX, so i trust William Yu's manual)
'The keys are  Z for left, X for right and space to go forward
'Enjoy!
'Antoni Gual  agual@eic.ictnet.es

declare sub raytrace
declare sub key(key as byte)
declare sub paint
declare sub size

DIM st%(0 TO 360) as integer
DIM ct%(0 TO 360) as integer
DIM a$(1 TO 11) as string
dim QBclrs(0 to 15) as long
dim sa% as integer,tmp1% as integer,px% as integer,py% as integer,t% as integer
dim xb as integer,yb as integer,bx as integer,by as integer,l% as integer,k% as integer
dim x% as integer,dd%(0 to 59) as integer,clr%(0 to 59) as integer


QBclrs(0) =0
QBclrs(1) =&H800000
QBclrs(2) =&H008000
QBclrs(3) =&H808000
qbclrs(4) =&h000080
qbclrs(5) =&H800080
qbclrs(6) =&h808000
qbclrs(7) =&h808080
qbclrs(8) =&h404040
qbclrs(9) =&hff0000
qbclrs(10)=&H00FF00
qbclrs(11)=&H00FFFF
qbclrs(12)=&HFF0000
qbclrs(13)=&Hff00FF
qbclrs(14)=&HffFF00
qbclrs(15)=&HffFFff

'maze defs
a$(1) = "1919191919"
a$(2) = "9000000001"
a$(3) = "1000000409"
a$(4) = "9010005001"
a$(5) = "1020040009"
a$(6) = "9030000001"
a$(7) = "1000078009"
a$(8) = "9050087001"
a$(9) = "1060000009"
a$(10)= "9191919191"
'TRIGONOMETRIC TABLES
FOR tmp1% = 0 TO 360
 st%(tmp1%) = (SIN(tmp1% * .0174)) * 100
NEXT tmp1%
FOR tmp1% = 0 TO 360
 ct%(tmp1%) = (COS(tmp1% * .0174)) * 100
NEXT tmp1%
'init position
px% = 15: py% = 15: sa% = 0
raytrace

Create form as qform
 	clientheight=200
 	clientwidth=300
	center 
        create can as qcanvas
  		width=form.width
  		height=form.height
                onpaint=paint
 	end create 
 	onkeypress=key
end create


sub key(key as byte)
 select case chr$(key)
 case "x":sa% = sa% + 3
 case "z":sa% = (sa% + 357) MOD 360
 case " "
    px% = px% + cint(st%(t% MOD 360) / 50)
    py% = py% + cint(ct%(t% MOD 360) / 50)
case else
    exit sub
end select
raytrace
paint
end sub

sub raytrace
FOR t% = sa% TO sa% + 59 STEP 1
  xb!=(st%(t% MOD 360) / 100)              'get inc
  yb!=(ct%(t% MOD 360) / 100)              'get inc
  bx!=px%                                'decimal copy
  by!=py%                                'decimal copy
  l%=0                                   'reset length
  DO
   bx!=bx!+xb!
   by!=by!+yb!
   l%=l%+1
   k%=asc(MID$(a$(cint(by!/10)),cint(bx!/10),1))-48
  LOOP UNTIL k%
  clr%(t%-sa%)=k%     
  dd%(t%-sa%)=1000/l%
   NEXT t%
end sub

sub paint
can.fillrect 0,0,300,200,&H999999
for i%=0 to 59 
  x%=i%*5
  can.fillrect x%,100-dd%(i%),x%+5,100+dd%(i%),qbclrs(clr%(i%))
  can.LINE x%,100-dd%(i%),x%+5,100-dd%(i%),0
  can.LINE x%,100+dd%(i%),x%+5,100+dd%(i%),0
next
end sub
form.showmodal

