`--------------------------------
`2D CUBE CATCHER!
`--------------------------------
 
`--------------------------------
` SETUP
`--------------------------------
`world Boundaries
Wx1 = 15 : Wx2 = 320
Wy1 = 200 : Wy2 = 30
Wz1 = 0 : Wz2 = 160
 
`Cube position
Cx = rnd(Wx2-Wx1)+Wx1
Cy# = Wy2
Cz = rnd(Wz2-Wx1)+Wx1
Cs# = 1
 
`Cube volume
Cvx = 10
Cvy = 10
Cvz = 5 : `half actual size for simplicity (no need to divide by 2)
 
`player plain
Px = Wx1
Py = Wy1
Pz = Wz1
`plain volume
Pvx = 16
Pvz = 8
 
randomize timer()
sTime# = timer() : `start time
 
`--------------------------------
` MAIN LOOP
`--------------------------------
sync on
 
DO
cls
gosub Axis
gosub Cube
gosub Player
gosub control
gosub bind
 
inc Cy#,Cs#
if Cy# >= Wy1
   if ABS( (Px+(pvx/2)) - (Cx+(Cvx/2)) ) < Pvx and ABS( (Pz+(pvz/2)) - (Cz+(Cvz/2)) ) < Pvz
      inc Pscore,1
      inc roll,1
      if roll = 3 then onfire = 1
   else
      roll = 0
      onfire = 0
   endif
   Cx = rnd(Wx2-Wx1)+Wx1
   Cy# = Wy2
   Cz = rnd(Wz2-Wx1)+Wx1
   Cvx = rnd(10)+5 : Cvy = rnd(10)+5 : Cvz = rnd(10)+5
   Cs# = rnd(15)
   Cs# = (Cs# /10)+0.5
else
   if onfire = 0
      if (Pvx-Cvx) <> 0 then dec Pvx,(Pvx-Cvx)/ABS(Pvx-Cvx)
      if (Pvz-Cvz) <> 0 then dec Pvz,(Pvz-Cvz)/ABS(Pvz-Cvz)
   else
      Pvx = 30 : Pvz = 15
   endif
endif
 
set cursor 20,320
eTime# = 60-(Timer()-sTime#)/1000
print "Time Remaining: "; eTime#
print "Score: "; Pscore
if onfire = 1 then print "YOU'RE ON FIRE!!!"
print Cs#
 
if eTime# <= 0
   cls
   center text 320,240,"You scored " + str$(Pscore) + "pts!"
   wait key
   sync
   end
endif
 
sync
LOOP
 
`--------------------------------
` GOSUBS
`--------------------------------
axis:
`x-line
ink rgb(255,0,0),0
line 15,200,320,200
`y-line
ink rgb(0,255,0),0
line 15,200,15,20
`z-line (X+Y/2)
ink rgb(0,0,255),0
line 15,200,160,55
RETURN
 
`------
 
cube:
ink rgb(255,255,255),0
`* FG Square
`Fore Bottom Horizontal
line (Cx+Cz),(Cy#-Cz), (Cx+Cz)+Cvx,(Cy#-Cz)
`Fore Top Horizontal
line (Cx+Cz),(Cy#-Cz)-Cvy, (Cx+Cz)+Cvx,(Cy#-Cz)-Cvy
`Fore Left Vert
line (Cx+Cz),(Cy#-Cz), (Cx+Cz),(Cy#-Cz)-Cvy
`Fore Right Vert
line (Cx+Cz)+Cvx,(Cy#-Cz), (Cx+Cz)+Cvx,(Cy#-Cz)-Cvy
 
`* BG Square
`Fore Bottom Horizontal
line (Cx+Cz)+Cvz,(Cy#-Cz)-Cvz, (Cx+Cz)+Cvx+Cvz,(Cy#-Cz)-Cvz
`Fore Top Horizontal
line (Cx+Cz)+Cvz,(Cy#-Cz)-Cvy-Cvz, (Cx+Cz)+Cvx+Cvz,(Cy#-Cz)-Cvy-Cvz
`Fore Left Vert
line (Cx+Cz)+Cvz,(Cy#-Cz)-Cvz, (Cx+Cz)+Cvz,(Cy#-Cz)-Cvy-Cvz
`Fore Right Vert
line (Cx+Cz)+Cvx+Cvz,(Cy#-Cz)-Cvz, (Cx+Cz)+Cvx+Cvz,(Cy#-Cz)-Cvy-Cvz
 
`* Connectors
`LB
line (Cx+Cz),(Cy#-Cz), (Cx+Cz)+Cvz,(Cy#-Cz)-Cvz
`RB
line (Cx+Cz)+Cvx,(Cy#-Cz), (Cx+Cz)+Cvx+Cvz,(Cy#-Cz)-Cvz
`LT
line (Cx+Cz),(Cy#-Cz)-Cvy, (Cx+Cz)+Cvz,(Cy#-Cz)-Cvy-Cvz
`RT
line (Cx+Cz)+Cvx,(Cy#-Cz)-Cvy, (Cx+Cz)+Cvx+Cvz,(Cy#-Cz)-Cvy-Cvz
 
`* Y height line (ground up)
ink rgb(0,255,0),0
line (Cx+Cz)+(Cvx/1.6),(Wy1-Cz)-(Cvy/1.6), (Cx+Cz)+(Cvx/1.6),(Cy#-Cz)-(Cvy/1.6)
RETURN
 
`------
 
player:
if onfire = 0 then ink rgb(0,0,255),0
if onfire = 1 then ink rgb(255,0,0),0
`FG Horizontal
line (Px+Pz),(Py-Pz), (Px+Pz)+Pvx,(Py-Pz)
`BG Horizontal
line (Px+Pz)+Pvz,(Py-Pz)-Pvz, (Px+Pz)+Pvx+Pvz,(Py-Pz)-Pvz
`LB
line (Px+Pz),(Py-Pz), (Px+Pz)+Pvz,(Py-Pz)-Pvz
`RB
line (Px+Pz)+Pvx,(Py-Pz), (Px+Pz)+Pvx+Pvz,(Py-Pz)-Pvz
RETURN
 
`------
 
control:
if rightkey() = 1 then inc Px,2
if leftkey() = 1 then dec Px,2
if upkey() = 1 then inc Pz,1
if downkey() = 1 then dec Pz,1
RETURN
 
`------
 
bind:
if Cx < Wx1 then Cx = Wx1
if Cx > Wx2 then Cx = Wx2
if Cy# > Wy1 then Cy# = Wy1
if Cy# < Wy2 then Cy# = Wy2
if Cz < Wz1 then Cz = Wz1
if Cz > Wz2 then Cz = Wz2
 
if Px < Wx1 then Px = Wx1
if Px > Wx2 then Px = Wx2
if Pz < Wz1 then Pz = Wz1
if Pz > Wz2 then Pz = Wz2
RETURN