TGC Codebase Backup



ASCII Frogger by sizer

16th Oct 2005 18:58
Summary

ASCII Frogger DBPro Competition Entry



Description

My first entry for any competition on the forums.



Code
                                    ` This code was downloaded from The Game Creators
                                    ` It is reproduced here with full permission
                                    ` http://www.thegamecreators.com
                                    
                                    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
global fx# as integer
global fy# as integer
global lives# as integer
dim goal#(9,3)
global level# as integer
global score# as integer
dim y_col#(27,2)
dim x_col#(4,22)
dim gator$(2)
global lilly$ as string
global car$ as string
global l_start# as integer
global r_start# as integer
`initialize hazards
text 275,300,"Initializing Game"
sync
setup_game()
repeat
   cls
   text 285,300,"Use arrow keys to move"
   text 225,315,"Press [END] or [ESCAPE] key to quit"
   text 275,330,"Press [SPACE] key to continue"
   sync
until keystate(57)
`-------------------------------------------
`main loop
do
   cls
   text 20,550,"Lives Left:" + str$(lives#) + "    Level:" + str$(level#) + "    FPS:" + str$(screen fps()) + "      Score:" + str$(score#)
   Draw_BG()
   Con_Traffic()
   Con_Agua()
   if fy# > 190
      Collide()
   else
      watercollision()
   endif
   ChkGoal()
   ChkLvl()
   if lives#<0 then GameOver()
   ` end program when [END] key is pressed
   if keystate(207) then end
   Con_Frog()
   sync
loop
`-------------------------------------------
`setup game
function setup_game()
   gator$(1)=">\===----"
   gator$(2)="----===/<"
   lilly$="%%%"
   tw#=250
   car$="[#]"
   l_start#=len(car$)
   l_start#=800-l_start#
   r_start#=len(car$)
   fx#=400
   fy#=500
   lives#=9
   level#=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#
      x_col#(2,i)=l_start#-(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
`-------------------------------------------
`control frogger
function Con_Frog()
   if keystate(200) then fy#=fy#-10`up
   if keystate(208) then fy#=fy#+10`down
   if keystate(203) then fx#=fx#-10`left
   if keystate(205) then fx#=fx#+10`right
   if fy# >= 499 then fy#=498
   if fx# >= 791 then fx#=790
   if fx# <= 9 then fx#=10
   if fy# <= 9 then fy#=10
   ink RGB(0,255,0),RGB(0,0,0)
   text fx#,fy#,"@"
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#
` 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#
   next i
` display vehicles in current position
   for i = 1 to 22
      text x_col#(1,i),y_col#(i,1),car$
      text x_col#(2,i),y_col#(i,1),car$
   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#
      x_col#(4,i)=x_col#(4,i)+(i*0.5)
      if x_col#(4,i)>=790 then x_col#(4,i)=r_start#
   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$
   next i
   for i = 2 to 16 step 2 `move lilly right, gator left
      text x_col#(3,i),y_col#(i,2),lilly$
      text x_col#(4,i),y_col#(i,2),gator$(2)
   next i
endfunction
`-------------------------------------------
`road collision
function Collide()
   if fy# >= 228
      for i = 1 to 22
         ` if on road die if hit by car
         if fy# <= y_col#(i,1)+12 and fx# <= x_col#(1,i)+15 and fy# >= y_col#(i,1)-5 and fx# >= x_col#(1,i)-5 then dead(fx#,fy#)
      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# >= x_col#(3,i) and fx# <= (x_col#(3,i)+50) and fy# >= y_col#(i,2)-5 and fy# <= y_col#(i,2)+8 ` if on gator or lilly
          fx# = (x_col#(3,i)+25) `set x to center of gator / lilly
          fy# = y_col#(i,2)  `set y to center of gator / lilly
          splash#=0
      endif
      if fx# >= x_col#(4,i) and fx# <= (x_col#(4,i)+15) and fy# >= y_col#(i,2)-5 and fy# <= y_col#(i,2)+8 ` if on gator or lilly
          fx# = (x_col#(4,i)+7) `set x to center of lilly
          fy# = y_col#(i,2)  `set y to center of lilly
          splash#=0
      endif
   next i
   for i = 2 to 16 step 2
      if fx# >= x_col#(3,i) and fx# <= (x_col#(3,i)+15) and fy# >= y_col#(i,2)-5 and fy# <= y_col#(i,2)+8 ` if on gator or lilly
         fx# = (x_col#(3,i)+7) `set x to center of lilly
         fy# = y_col#(i,2)  `set y to center of lilly
         splash#=0
      endif
      if fx# >= x_col#(4,i) and fx# <= (x_col#(4,i)+50) and fy# >= y_col#(i,2)-5 and fy# <= y_col#(i,2)+8 ` if on gator
         fx# = (x_col#(4,i)+25) `set x to center of gator
         fy# = y_col#(i,2)  `set y to center of gator
         splash#=0
      endif
   next i
   if splash#=1 then dead(fx#,fy#)
endfunction
`-------------------------------------------
`check if in goal then reset frog and increment score.
function ChkGoal()
   for i = 1 to 9
      if fx# > goal#(i,2) and fx# < goal#(i,3) and fy# < 42
         goal#(i,1) = 1
         fx#=400
         fy#=500
         inc score#
      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# = score# + lives#
      inc level#
      inc lives#
      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#=400
   fy#=500
   lives#=lives#-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#=9
   fx#=400
   fy#=500
endfunction