remstart
   -------------------------------------------------------------------
   Cone Racer
   -------------------------------------------------------------------
   By NinJA999
   05/31/07
   -------------------------------------------------------------------
   Try to beat 17 seconds--my personal best!
   It might take a few tries to get used to the controls, though.
   If you beat it, try making your own map in the data statements!
   -------------------------------------------------------------------
remend
 
`---Setup---
set display mode 1024,768,32
sync on
sync rate 60
hide mouse
 
`Color choices!
dim cubecolors(8)
cubecolors(0)=RGB(255,0,0)
cubecolors(1)=RGB(255,128,0)
cubecolors(2)=RGB(255,255,0)
cubecolors(3)=RGB(0,255,0)
cubecolors(4)=RGB(0,0,255)
cubecolors(5)=RGB(128,0,128)
cubecolors(6)=RGB(255,0,255)
cubecolors(7)=RGB(255,255,255)
curcolor=0
cubecolor = cubecolors(curcolor)
 
`For centering text
screenhcenter=screen width()/2
screenvcenter=screen height()/2
set text font "Georgia"
set text size 20
ink rgb(255,0,0),0
 
`Intro screen
do
   cls
   ink rgb(255,0,0),0
   center text screenhcenter,screenvcenter-40,"--Cone Racer--"
   center text screenhcenter,screenvcenter-15,"Press Left and Right to change the color of the controllable cube."
   center text screenhcenter,screenvcenter+5,"Press Space to Start."
   ink cubecolor,0
   center text screenhcenter,screenvcenter+30,"<- CHANGE COLOR ->"
   ink rgb(255,0,0),0
   center text screenhcenter,screenvcenter+50,"During the game, use the arrow keys to swerve the cube around"
   center text screenhcenter,screenvcenter+65,"the cones.  Follow the red patches of grass."
   if spacekey() then goto startgame
   if rightkey() then inc curcolor
   if leftkey() then dec curcolor
   if curcolor>7 then curcolor=0
   if curcolor<0 then curcolor=7
   cubecolor = cubecolors(curcolor)
   `to allow for arrow presses
   wait 100
   sync
loop
 
`actual game setup
startgame:
set text size 40
ink rgb(255,255,255),0
draw to back
cls
center text screenhcenter,screenvcenter,"LOADING!"
sync
sync
autocam off
set global collision on
gosub fieldsetup
make object cube 1,5
X#=initialX#
Z#=initialZ#
Y#=2.5
position object 1,X#,Y#,Z#
set object collision on 1
color object 1,cubecolor
angle# = 180
draw to front
ink rgb(255,255,255),0
set text size 40
set text font "Georgia"
starttime#=Timer()
waypoint=1
color backdrop rgb(128,128,255)
 
`---MAIN LOOP---
do
 
   `controls
   if upkey() and spacekey() = 0 then speed#=speed#+0.05
   if downkey() and spacekey() = 0 then speed#=speed#-0.05
   if upkey() = 0 and downkey() = 0 and spacekey() = 0 then speed#=speed#/1.02
 
   if rightkey() and spacekey() = 0 then turnp#=turnp#+0.2
   if leftkey() and spacekey() = 0 then turnp#=turnp#-0.2
   if rightkey() = 0 and leftkey() = 0 and spacekey() = 0 then turnp#=turnp#/1.2
 
   if spacekey() then speed#=speed#/1.1
   if spacekey() and rightkey() then turnp#=turnp#+0.6
   if spacekey() and leftkey() then turnp#=turnp#-0.6
 
   `allow speed to reach 0 at a point
   if speed# > -0.04 and speed# < 0.04 then speed# = 0
 
   `limit preliminary turn
   if turnp# > 10 then turnp# = 10
   if turnp# < -10 then turnp# = -10
 
   `more car-like turning (turn faster if you're moving slower)
   if speed# > 0 or speed# < 0 then turn#=turnp#/speed#
   `except when you're moving really slow!
   if speed# < 0.2 and speed# > -0.2 then turn# = turnp#*speed#
 
   `limit turn and speed
   if turn# > 8 then turn# = 8
   if turn# < -8 then turn# = -8
   if speed# > 3.5 then speed# = 3.5
   if speed# < -3.5 then speed# = -3.5
 
   angle#=angle#+turn#
 
   rotate object 1,0,wrapvalue(angle#),0
   X#=newXvalue(X#,angle#,speed#)
   Z#=newZvalue(Z#,angle#,speed#)
 
   `if you go over the edge, you fall!
   if X#>100 or X#<0 then Y#=Y#-10
   if Z#>200 or Z#<0 then Y#=Y#-10
   if Y#<2.5
      if X#<101 then X#=101
      if X#>-1 then X#=-1
      if Z#<201 then X#=201
      if Z#>-1 then Z#=-1
   endif
 
   if Y#<-300 then gosub restart
 
   Position object 1,X#,Y#,Z#
 
   `camera stuff
   cam_angle#=cam_angle#+(angle#-cam_angle#)/5
 
   camX#=newXvalue(X#,cam_angle#+180,speed#+20)
   camZ#=newZvalue(Z#,cam_angle#+180,speed#+20)
 
   position camera camX#,speed#+10,camZ#
 
   point camera X#,Y#,Z#
 
   fov#=speed#/5
   set camera fov fov#+1
 
   elapsedtime#=(Timer()-starttime#)/1000
   min#=elapsedtime#/60
 
   `HUD
   text 10,10,"Speed: "+str$(Round(speed#,1))
   text 10,50,str$(waypoint-1)+" Cones out of 6"
   if min#>1
      text 10,90,"Elapsed: "+str$(Int(min#))+" min, "+str$(Int(elapsedtime#-(Int(min#)*60)))+" sec"
   else
      text 10,90,"Elapsed: "+str$(Int(elapsedtime#))+" sec"
   endif
 
   `Cone collision checking
   for i=10 to (coneobj-1)
      if object collision(i,1) then gosub restart
   next i
 
   `Waypoint collision checking
   for i=20 to (boxobj-1)
      if object collision(i,1) then waypoint=waypoint+1
      if waypoint>7 then goto youwin
   next i
 
   `take care of deleting the boxes (in case the waypoint changes)
   for i=20 to boxobj-1
      delete object i
   next i
   boxobj=20
 
   gosub waypoint:
 
sync
loop
 
`make the field
fieldsetup:
`allow for grass & red grass:
create bitmap 1,256,128
set current bitmap 1
`grass
for i=0 to 128
   for j=0 to 128
      ink rgb(10,100+rnd(30),25),0
      dot i,j
   next j
next i
`red grass
for i=128 to 256
   for j=0 to 128
      ink rgb(100+rnd(100),0,0),0
      dot i,j
   next j
next i
get image 1,0,0,256,128
cls
set current bitmap 0
delete bitmap 1
make matrix 1,100,200,10,20
prepare matrix texture 1,1,2,1
fill matrix 1,0.0,1
`Cone counter (cone objects start with 10)
coneobj=10
`Box counter (box objects start with 20)
boxobj=20
`read map stored in data statements & place cones and cube
for i=1 to 20
   for j=1 to 10
      Read r
      select r
         case 8
            initialX#=(11-j)*10-5
            initialZ#=i*10-5
         endcase
         case 9
            make object cone coneobj, 5
            position object coneobj, (11-j)*10-5, 3, i*10-5
            color object coneobj, rgb(255,128,0)
            set object collision on coneobj
            set object collision to polygons coneobj
            coneobj=coneobj+1
         endcase
      endselect
   next j
next i
restore
update matrix 1
return
 
`called each loop, and makes the waypoint collision boxes and red grass
waypoint:
for i=1 to 20
   for j=1 to 10
      Read r
      select r
         case waypoint
            `red grass
            set matrix tile 1,(11-j)-1,i-1,2
            `collision box
            make object box boxobj,10,5,10
            position object boxobj, (11-j)*10-5,2.5,i*10-5
            set object collision on boxobj
            hide object boxobj
            boxobj=boxobj+1
         endcase
         case default
            `everything else should be normal grass
            set matrix tile 1,(11-j)-1,i-1,1
         endcase
      endselect
   next j
next i
restore
`after about an hour, finally realized why the matrix wasn't showing my tiles!
update matrix 1
return
 
`after going off the side, or hitting a cone, everything except the time must be reset.
restart:
   X#=initialX#
   Z#=initialZ#
   Y#=2.5
   angle#=180
   speed#=0
   waypoint=1
return
 
`WINNER!!! display how long it took
youwin:
   elapsedtime#=(Timer()-starttime#)/1000
   min#=elapsedtime#/60
   do
      ink rgb(255,0,0),rgb(0,0,0)
      cls
      if min#>1
         center text screenhcenter,screenvcenter,"YOU FINISHED IN "+str$(Int(min#))+" min and "+str$(Int(elapsedtime#-(Int(min#)*60)))+" sec!!!"
      else
         center text screenhcenter,screenvcenter,"YOU FINISHED IN "+str$(Int(elapsedtime#))+" sec!!!"
      endif
      sync
   loop
end
 
remstart
---CONE FIELD DATA---
100x200 field area
10x10 blocks
10x20 coded area:
0 = Blank
1-6 = Cone Collision Boxes
7 = Finish
8 = Start
9 = Cone
 
Try your hand at making your own field, if you are tired of mine!
remend
 
Data 0,0,0,0,9,7,9,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,9,6,6
Data 0,0,0,0,0,0,0,0,0,0
Data 5,5,9,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,9,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 3,3,9,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,9,2,2
Data 0,0,0,0,0,0,0,0,0,0
Data 1,1,1,1,1,1,9,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,9,8,9,0
 
`for rounding the speed
Function Round(toround#,digits)
   rounded#=Int(toround#*(10^digits))
   rounded#=rounded#/(10^digits)
Endfunction rounded#