Rem Project: frogger
Rem Created: 10/9/2005 7:10:44 PM
Rem Creator: sizer : gregory.sizer@us.army.mil
`-------------------------------------------
cls
sync on
sync rate 0
set display mode 800,600,32
set text size 10
`game variables
dim fx#(1)
dim fy#(1)
dim lives#(1)
dim goal#(9,3)
dim level#(1)
dim score#(1)
dim y_col#(27,2)
dim x_col#(4,22)
dim gator$(2)
dim lilly$(1)
dim car$(1)
dim l_semi$(1)
dim r_semi$(1)
dim l_start#(1)
dim r_start#(1)
`initialize hazards
text 275,300,"Initializing Game"
sync
setup_game()
cls
text 285,300,"Use arrow keys to move"
text 225,315,"Press [END] or [ESCAPE] key to quit"
text 275,330,"Press any key to continue"
sync
wait key
`-------------------------------------------
`main loop
do
   cls
   text 20,550,"Lives Left:" + str$(lives#(1)) + "    Level:" + str$(level#(1)) + "    FPS:" + str$(screen fps()) + "      Score:" + str$(score#(1))
   Draw_BG()
   Con_Frog()
   Con_Traffic()
   Con_Agua()
   if fy#(1) > 190
      Collide()
   else
      watercollision()
   endif
   ChkGoal()
   ChkLvl()
   if lives#(1)<0 then GameOver()
   ` end program when [END] key is pressed
   if keystate(207) then end
   sync
loop
`-------------------------------------------
`setup game
function setup_game()
   gator$(1)=">\===----"
   gator$(2)="----===/<"
   lilly$(1)="%%%"
   car$(1)="[#]"
   l_semi$(1)="[#]=[#####]"
   r_semi$(1)="[#####]=[#]"
   l_start#(1)=len(l_semi$)
   l_start#(1)=800-l_start#
   r_start#(1)=len(r_semi$)
   fx#(1)=400
   fy#(1)=500
   lives#(1)=9
   level#(1)=1
   for i = 1 to 22
      y_col#(i,1)=462-(i*10)
      y_col#(i,2)=190-(i*10)
      x_col#(1,i)=(i*10)+r_start#(1)
      x_col#(2,i)=l_start#(1)-(i*10)
   next i
   for i = 1 to 9
      goal#(i,1)=0
   next i
   goal#(1,2)=65
   goal#(1,3)=105
   goal#(2,2)=145
   goal#(2,3)=185
   goal#(3,2)=225
   goal#(3,3)=265
   goal#(4,2)=305
   goal#(4,3)=345
   goal#(5,2)=385
   goal#(5,3)=425
   goal#(6,2)=465
   goal#(6,3)=505
   goal#(7,2)=545
   goal#(7,3)=585
   goal#(8,2)=625
   goal#(8,3)=665
   goal#(9,2)=705
   goal#(9,3)=745
   sync
   for i=1 to 300
      Con_Traffic()
      Con_Agua()
   next i
endfunction
`-------------------------------------------
`main screen
function Draw_BG()
   ink RGB(0,64,0),RGB(0,0,0)
   for s2=1 to 3
      print "########     #####     #####     #####     #####     #####     #####     #####     #####     ########"
   next s2
   ink RGB(0,0,255),RGB(255,255,255)
   for w=1 to 10
      print "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
   next i
   ink RGB(108,80,40),RGB(240,216,40)
   for s1=1 to 3
      print ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"
   next s1
   ink RGB(255,255,0),RGB(0,0,0)
   for r=1 to 15
      select r
         case 4 : print "=====================================================================================================" :endcase
         case 8 : print "=====================================================================================================" :endcase
         case 12 : print "=====================================================================================================" :endcase
         case default : print "" : endcase
      endselect
   next r
   ink RGB(108,80,40),RGB(108,80,40)
   for s0=1 to 3
      print "*****************************************************************************************************"
   next s0
   print "-----------------------------------------------------------------------------------------------------"
endfunction
`-------------------------------------------4
`control frogger
function Con_Frog()
   if keystate(200) then fy#(1)=fy#(1)-10`up
   if keystate(208) then fy#(1)=fy#(1)+10`down
   if keystate(203) then fx#(1)=fx#(1)-10`left
   if keystate(205) then fx#(1)=fx#(1)+10`right
   if fy#(1) >= 499 then fy#(1)=498
   if fx#(1) >= 791 then fx#(1)=790
   if fx#(1) <= 9 then fx#(1)=10
   if fy#(1) <= 9 then fy#(1)=10
   ink RGB(0,255,0),RGB(0,0,0)
   text fx#(1),fy#(1),"@"
endfunction
`-------------------------------------------
`control traffic
function Con_Traffic()
   ink RGB(255,255,255),RGB(0,0,0)
   for i = 1 to 22
` sets current vehicle moving left position
      x_col#(1,i)=x_col#(1,i)-(i*0.5)
      if x_col#(1,i)<=1 then x_col#(1,i)=l_start#(1)
` sets current vehicle moving right position
      x_col#(2,i)=x_col#(2,i)+(i*0.5)
      if x_col#(2,i)>=790 then x_col#(2,i)=r_start#(1)
   next i
` display vehicles in current position
   for i = 1 to 22
      text x_col#(1,i),y_col#(i,1),car$(1)
      text x_col#(2,i),y_col#(i,1),car$(1)
   next i
endfunction
`-------------------------------------------
`control water stuff
function Con_Agua()
   ink RGB(0,128,0),RGB(0,0,0)
   for i = 1 to 16
      x_col#(3,i)=x_col#(3,i)-(i*0.5)
      if x_col#(3,i)<=1 then x_col#(3,i)=l_start#(1)
      x_col#(4,i)=x_col#(4,i)+(i*0.5)
      if x_col#(4,i)>=790 then x_col#(4,i)=r_start#(1)
   next i
   for i = 1 to 15 step 2 `move gator left, lilly right
      text x_col#(3,i),y_col#(i,2),gator$(1)
      text x_col#(4,i),y_col#(i,2),lilly$(1)
   next i
   for i = 2 to 16 step 2 `move lilly right, gator left
      text x_col#(3,i),y_col#(i,2),lilly$(1)
      text x_col#(4,i),y_col#(i,2),gator$(2)
   next i
endfunction
`-------------------------------------------
`road collision
function Collide()
   if fy#(1) >= 228
      for i = 1 to 22
         ` if on road die if hit by car
         if fy#(1) <= y_col#(i,1)+12 and fx#(1) <= x_col#(1,i)+15 and fy#(1) >= y_col#(i,1)-5 and fx#(1) >= x_col#(1,i)-5 then dead(fx#(1),fy#(1))
      next i
   endif
endfunction
`-------------------------------------------
function watercollision()
` anti-collision for hoping on lilly and gator
   splash#=1
   for i = 1 to 15 step 2
      if fx#(1) >= x_col#(3,i) and fx#(1) <= (x_col#(3,i)+50) and fy#(1) >= y_col#(i,2)-5 and fy#(1) <= y_col#(i,2)+8 ` if on gator or lilly
          fx#(1) = (x_col#(3,i)+25) `set x to center of gator / lilly
          fy#(1) = y_col#(i,2)  `set y to center of gator / lilly
          splash#=0
      endif
      if fx#(1) >= x_col#(4,i) and fx#(1) <= (x_col#(4,i)+15) and fy#(1) >= y_col#(i,2)-5 and fy#(1) <= y_col#(i,2)+8 ` if on gator or lilly
          fx#(1) = (x_col#(4,i)+7) `set x to center of lilly
          fy#(1) = y_col#(i,2)  `set y to center of lilly
          splash#=0
      endif
   next i
   for i = 2 to 16 step 2
      if fx#(1) >= x_col#(3,i) and fx#(1) <= (x_col#(3,i)+15) and fy#(1) >= y_col#(i,2)-5 and fy#(1) <= y_col#(i,2)+8 ` if on gator or lilly
         fx#(1) = (x_col#(3,i)+7) `set x to center of lilly
         fy#(1) = y_col#(i,2)  `set y to center of lilly
         splash#=0
      endif
      if fx#(1) >= x_col#(4,i) and fx#(1) <= (x_col#(4,i)+50) and fy#(1) >= y_col#(i,2)-5 and fy#(1) <= y_col#(i,2)+8 ` if on gator
         fx#(1) = (x_col#(4,i)+25) `set x to center of gator
         fy#(1) = y_col#(i,2)  `set y to center of gator
         splash#=0
      endif
   next i
   if splash#=1 then dead(fx#(1),fy#(1))
endfunction
`-------------------------------------------
`check if in goal then reset frog and increment score.
function ChkGoal()
   for i = 1 to 9
      if fx#(1) > goal#(i,2) and fx#(1) < goal#(i,3) and fy#(1) < 42
         goal#(i,1) = 1
         fx#(1)=400
         fy#(1)=500
         inc score#(1)
      endif
      if goal#(i,1) = 1 then text (goal#(i,2)+20),22,"@"
   next i
endfunction
`-------------------------------------------
`check goals if full inc level add bonus for lives left
function ChkLvl()
   for i = 1 to 9
      if goal#(i,1) = 1 then inc t#
   next i
   if t# = 9
      score#(1) = score#(1) + lives#(1)
      inc level#(1)
      inc lives#(1)
      for i = 1 to 9
         goal#(i,1) = 0
      next i
   endif
endfunction
`-------------------------------------------
`draw dead frog and restart player less 1 life
function dead(x,y)
   text x,y,"X"
   text (x+30),(y-25),"YOU DIED!"
   fx#(1)=400
   fy#(1)=500
   lives#(1)=lives#(1)-1
   sync
   wait 500
endfunction
`-------------------------------------------
`display game over screen
function GameOver()
   cls
   set text size 48
   text 350,300,"GAME OVER"
   set text size 10
   text 300,400,"PRESS ANY KEY TO RESTART"
   sync
   wait key
   lives#(1)=9
   fx#(1)=400
   fy#(1)=500
endfunction