

rem play intro
load animation "media/cover.avi", 1
remstart
load animation "media/froggie.avi", 2

play animation 1
while animation playing(1)=1
sync
endwhile

play animation 2
while animation playing(2)=1
sync
endwhile
remend


rem Loading screen
load bitmap "media\loading.bmp",1
copy bitmap 1,0,0,1024,768,0,0,0,screen width(),screen height()
sync : delete bitmap 1



sync on : sync rate 20 : backdrop on : hide mouse
if check display mode(1024,768,32)=1 then set display mode 1024,768,32

set text font "Arial" : set text size 50
set text to bold : set text transparent


rem load and set background
load image "media\beach.jpg", 1
make matrix 1,50,100,1,35
prepare matrix texture 1,1,1,35
position matrix 1,-25,0,0
for i=1 to 35
   set matrix tile 1,0,i-1,i
next i
update matrix 1

skyobj=10 : load object "object\sky.X", skyobj

rem make ocean matrix
load image "media\ocean1.bmp",2
make matrix 2,65,100,1,35
prepare matrix texture 2,2,1,35
position matrix 2,22,-.01,.1
for i=1 to 35
   set matrix tile 2,0,i-1,i
next i
update matrix 2

rem extend sand left
load image "media\sand1.bmp", 3
make matrix 3,100,100,1,35
prepare matrix texture 3,3,1,35
position matrix 3,-90,-.01,.1
for i=1 to 35
   set matrix tile 3,0,i-1,i
next i
update matrix 3

rem make the mountain
set image colorkey 255,0,255
load image "media\mountains.bmp",4
make object plain 4,200,28
set object texture 4,2,1
set object light 4,0
set object 4,1,1,1
texture object 4,4
position object 4,0,2,100

rem make bushes etc
for i=41 to 45
load object "object\bush.x", i
scale object i, 300, 300, 300
position object i, -22, (get ground height(1,0,0)+object size y(i)/2), 100
hide object i
next i


rem load objects
load object "object\purplefrog.x", 1
scale object 1,200,200,200
position object 1,15,get ground height(1,10,10)+(object size y(1)/2),10
load object "object\purplefrog-dying.x", 101
scale object 101,200,200,200
set object speed 101, 300
hide object 101


load object "object\orangefrog.X", 2
scale object 2,200,200,200
position object 2,-15,get ground height(1,0,10)+(object size y(1)/2),10
load object "object\orangefrog-dying.X", 102
scale object 102,200,200,200
set object speed 102, 300
hide object 102


load object "object\purple-wins.x", 201
scale object 201,300,300,300
position object 201,0,get ground height(1,0,10)+(object size y(201)/2),15
set object speed 201, 100
hide object 201
load object "object\orange-wins.x",202
scale object 202,300,300,300
position object 202,0,get ground height(1,0,10)+(object size y(202)/2),15
set object speed 202, 100
hide object 202



for i=15 to 17
load object "object\frog.x", i
position object i, rnd(12)-6, (get ground height(1,0,0)+object size y(i)/2), 75
hide object i
next i


for i=11 to 12
load object "object\butterfly.x", i
scale object i, 300, 300, 300
position object i, rnd(12)-6, get ground height(1,-10,10)+object size y(i)+3.5, 75
hide object i
make object collision box i,-0.8,-0.9,-1,0.8,1,1,1
next i


for i=13 to 14
load object "object\bug-animate.x", i
scale object i, 400, 400, 400
position object i, rnd(i)-4.5, (get ground height(1,0,0)+object size y(i)/2), 75
hide object i
rem loop object 13
next i


make object cube 20,2
position object 20, rnd(12)-6, (get ground height(1,0,0)+object size y(20)/2), 0
hide object 20


make object cube 30,2
position object 30, rnd(12)-6, (get ground height(1,0,0)+object size y(30)/2), 0
hide object 30


rem load hearts
for i=21 to 23
load object "object\heart.x", i
scale object i, 35,35,35
position object i, (i-27)*2, 1, 1
next i


for i=24 to 26
load object "object\heart.x", i
scale object i, 35,35,35
position object i,(i-22)*2,1,1
next i


load music "media\01.mp3", 1
loop music 1

load sound "sound\jump_01.wav", 1
load sound "sound\win_13.wav", 2
load sound "sound\hit_03.wav", 3
load sound "sound\score_10.wav", 4
load animation "media\credit.avi", 5
load music "media\credit.mp3", 5



rem setup camera and other stuff
position camera 0,15,-8
point camera 0,0,20
rem color backdrop rgb(0,100,100)
set object skyobj,1,0,0,0,0,0,0
position object skyobj,0,-50,120
yrotate object skyobj, -180
scale object skyobj,1000,1000,1000


rem light
set point light 0,25,30,25
set ambient light 80



set global collision on

speedFactor# = 1
currentT = timer()
playerCollision = 0
frogX# = object size x(1)
frogY# = object size y(1)
frogZ# = object size z(1)
backgroundRolling = 1
startTime = timer()
timeCount = timer()

player1Direction$ = "unknown"
player1Height# = 0
player1Status = 0
player1Score = 0

player2Direction$ = "unknown"
player2Height# = 0
player2Status = 0
player2Score = 0

object20Direction$ = "left"
object30Direction$ = "right"

make object collision box 1,-0.8,-0.9,-1,0.8,1,1,1
make object collision box 2,-0.8,-0.9,-1,0.8,1,1,1






do

if inkey$()="r" then backgroundRolling=1
if inkey$()="t" then backgroundRolling=0


if backgroundRolling=1
shift matrix up 1: update matrix 1
shift matrix up 2: update matrix 2
shift matrix up 3: update matrix 3
endif

if inkey$()="6" then gameOver(1)
if inkey$()="7" then gameOver(2)

if inkey$()="1" then move camera 1
if inkey$()="2" then move camera -1

gosub _player1Control
gosub _player2Control
gosub _enemyControl

char1Collision=enemyCollision(1)
char2Collision=enemyCollision(2)
if char1Collision<0 then heartMinus(1)
if char2Collision<0 then heartMinus(2)
if char1Collision>0 then player1Score = addScore(player1Score)
if char2Collision>0 then player2Score = addScore(player2Score)

center text screen width()/2-400,screen height()/2-300, str$(player1Score)
center text screen width()/2+400,screen height()/2-300, str$(player2Score)

box 32,700,38+((screen width()-16)/100)*(currentT-startTime)/3000,700+20,rgb(0,100,0),rgb(0,100,0),rgb(0,255,0),rgb(0,255,0)
if (currentT-startTime)>280000 then gameOver(-1)

speedFactor# = (timer()-currentT)/50.0
currentT = timer()

sync
loop






_enemyControl:
if (timer()-timeCount)>3000
   timeCount = timer()

   if object visible(13)=1
      if object visible(12)=1
         if object visible(14)=1
            if object visible(11)=1
            else
               show object 11
            endif
         else
            show object 14
         endif
      else
         show object 12
      endif
   else
      show object 13
   endif

   rem move frogs
   for i=15 to 17
      if object visible(i)=0
      show object i
      i=18
      endif
   next i

endif

if rnd(3)=0
for i=41 to 45
    if object visible(i)=0
    show object i
    i=46
    endif
next i
endif


if object visible(13)=1 then enemyMove1(13, speedFactor#)
if object visible(11)=1 then enemyMove2(11, speedFactor#)
if object visible(12)=1 then enemyMove3(12, speedFactor#)
if object visible(14)=1 then enemyMove4(14, speedFactor#)
if object visible(15)=1 then enemyMove5(15, speedFactor#)
if object visible(16)=1 then enemyMove1(16, speedFactor#)
if object visible(17)=1 then enemyMove1(17, speedFactor#)
gosub _object20Move
gosub _object30Move
gosub _moveBush

return


function enemyMove1(objectNumber, speedFactor#):
position object objectNumber, object position x(objectNumber), object position y(objectNumber), (object position z(objectNumber)-0.3*speedFactor#)

if object position z(objectNumber)<0
position object objectNumber, rnd(12)-4.5, (get ground height(1,10,10)+(object size y(objectNumber)/2)), 75
hide object objectNumber
endif
endfunction


function enemyMove2(objectNumber, speedFactor#):
xVal# = object position x(objectNumber)
xVal20# = object position x(20)

if xVal#<xVal20#
position object objectNumber, (object position x(objectNumber)+0.2*speedFactor#), object position y(objectNumber), object position z(objectNumber)
else
position object objectNumber, (object position x(objectNumber)-0.2*speedFactor#), object position y(objectNumber), object position z(objectNumber)
endif

position object objectNumber, object position x(objectNumber), object position y(objectNumber), (object position z(objectNumber)-0.2*speedFactor#)
if object position z(objectNumber)<0
position object objectNumber, rnd(objectNumber)-4.5, (get ground height(1,0,0)+object size y(objectNumber)+3.5), 75
hide object objectNumber
endif
endfunction


function enemyMove3(objectNumber, speedFactor#):
xVal# = object position x(objectNumber)
xVal1# = object position x(1)
xVal2# = object position x(2)

if (abs(xVal#-xVal1#)<abs(xVal#-xVal2#))
   if abs(xVal#-xVal1#)<0.3*speedFactor#
      position object objectNumber, xVal1#, object position y(objectNumber), object position z(objectNumber)
   else
      if xVal#<xVal1#
      position object objectNumber, (object position x(objectNumber)+0.3*speedFactor#), object position y(objectNumber), object position z(objectNumber)
      else
      position object objectNumber, (object position x(objectNumber)-0.3*speedFactor#), object position y(objectNumber), object position z(objectNumber)
      endif
   endif
else
   if abs(xVal#-xVal2#)<0.3*speedFactor#
      position object objectNumber, xVal2#, object position y(objectNumber), object position z(objectNumber)
   else
      if xVal#<xVal2#
      position object objectNumber, (object position x(objectNumber)+0.3*speedFactor#), object position y(objectNumber), object position z(objectNumber)
      else
      position object objectNumber, (object position x(objectNumber)-0.3*speedFactor#), object position y(objectNumber), object position z(objectNumber)
      endif
   endif
endif

position object objectNumber, object position x(objectNumber), object position y(objectNumber), (object position z(objectNumber)-0.2*speedFactor#)
if object position z(objectNumber)<0
position object objectNumber, rnd(objectNumber)-4.5, (get ground height(1,0,0)+object size y(objectNumber)+3.5), 75
hide object objectNumber
endif
endfunction


function enemyMove4(objectNumber, speedFactor#):
xVal# = object position x(objectNumber)
xVal20# = object position x(20)

if xVal#<xVal20#
position object objectNumber, (object position x(objectNumber)+0.2*speedFactor#), object position y(objectNumber), object position z(objectNumber)
else
position object objectNumber, (object position x(objectNumber)-0.2*speedFactor#), object position y(objectNumber), object position z(objectNumber)
endif

position object objectNumber, object position x(objectNumber), object position y(objectNumber), (object position z(objectNumber)-0.2*speedFactor#)
if object position z(objectNumber)<0
position object objectNumber, rnd(objectNumber)-4.5, (get ground height(1,0,0)+object size y(objectNumber)/2), 75
hide object objectNumber
endif
endfunction


function enemyMove5(objectNumber, speedFactor#):
xVal# = object position x(objectNumber)
xVal30# = object position x(30)

if xVal#<xVal30#
position object objectNumber, (object position x(objectNumber)+0.2*speedFactor#), object position y(objectNumber), object position z(objectNumber)
else
position object objectNumber, (object position x(objectNumber)-0.2*speedFactor#), object position y(objectNumber), object position z(objectNumber)
endif

position object objectNumber, object position x(objectNumber), object position y(objectNumber), (object position z(objectNumber)-0.2*speedFactor#)
if object position z(objectNumber)<0
position object objectNumber, rnd(objectNumber)-4.5, (get ground height(1,0,0)+object size y(objectNumber)/2), 75
hide object objectNumber
endif
endfunction


_object20Move:
   if object20Direction$="left"
      position object 20, object position x(20)-0.4*speedFactor#, object position y(20), object position z(20)
      if object position x(20)<-10
      position object 20, object position x(20)+0.4*speedFactor#, object position y(20), object position z(20)
      object20Direction$="right"
      endif
   else
      position object 20, object position x(20)+0.4*speedFactor#, object position y(20), object position z(20)
      if object position x(20)>10
      position object 20, object position x(20)-0.4*speedFactor#, object position y(20), object position z(20)
      object20Direction$="left"
      endif
   endif
return


_object30Move:
   if object30Direction$="left"
      position object 30, object position x(30)-0.4*speedFactor#, object position y(30), object position z(30)
      if object position x(30)<-10
      position object 30, object position x(30)+0.4*speedFactor#, object position y(30), object position z(30)
      object30Direction$="right"
      endif
   else
      position object 30, object position x(30)+0.4*speedFactor#, object position y(30), object position z(30)
      if object position x(30)>10
      position object 30, object position x(30)-0.4*speedFactor#, object position y(30), object position z(30)
      object30Direction$="left"
      endif
   endif
return


_moveBush:
for i=41 to 45
   if object visible(i)=1
   position object i, object position x(i), object position y(i), object position z(i)-speedFactor#*2.5
   if object position z(i)<(-100)
   position object i, -22, (get ground height(1,0,0)+object size y(i)/2), 100
   hide object i
   endif
   endif
next i
return


_player1Control:
player1Height# = object position y(1)

if player1Status=0
   if leftkey()=1
      if object position x(1)>-15
      position object 1, (object position x(1)-0.5*speedFactor#), object position y(1), object position z(1)
      player1Direction$="left"
         gosub _playerCollision
         if object collision (1,2)>0
            if (player2Direction$="unknown" and object position x(1)>-13.5)
            position object 2, (object position x(2)-0.5*speedFactor#), object position y(2), object position z(2)
            else
            position object 1, (object position x(1)+0.5*speedFactor#), object position y(1), object position z(1)
            endif
         endif
      endif

   else
      if rightkey()=1
      if object position x(1)<15
      position object 1, (object position x(1)+0.5*speedFactor#), object position y(1), object position z(1)
      player1Direction$="right"
         gosub _playerCollision
         if object collision (1,2)>0
            if (player2Direction$="unknown" and object position x(1)<13.5)
            position object 2, (object position x(2)+0.5*speedFactor#), object position y(2), object position z(2)
            else
            position object 1, (object position x(1)-0.5*speedFactor#), object position y(1), object position z(1)
            endif
         endif
      endif
      else
      player1Direction$="unknown"
      endif
   endif

   if upkey()=1
      if object position z(1)<12
      position object 1, object position x(1), object position y(1), (object position z(1)+2.3)
         gosub _playerCollision
         if object collision (1,2)>0
         position object 1, object position x(1), object position y(1), (object position z(1)-2.3)
         endif
      endif
   else
      if downkey()=1
      if object position z(1)>11
      position object 1, object position x(1), object position y(1), (object position z(1)-2.3)
         gosub _playerCollision
         if object collision (1,2)>0
         position object 1, object position x(1), object position y(1), (object position z(1)+2.3)
         endif
      endif
      endif
   endif

   if spacekey()=1
      play sound 1
      gosub _player1Jump
   endif

else
   gosub _player1Jump
endif

return


_player1Jump:
if player1Status=1
   if player1Height#<4
   move object up 1,0.5*speedFactor#
   player1Height#=player1Height#+0.5*speedFactor#
      gosub _playerCollision
      if object collision(1,2)>0
      move object down 1,0.5*speedFactor#
      player1Height#=player1Height#-0.5*speedFactor#
      endif
   else
   player1Status=2
   endif
endif
if player1Status=0
   player1Status=1
   move object up 1,0.5*speedFactor#
   player1Height#=player1Height#+0.5*speedFactor#
      if object collision(1,2)>0
      move object down 1,0.5*speedFactor#
      player1Height#=player1Height#-0.5*speedFactor#
      endif
endif
if player1Status=2
   if ((object position y(1)-0.5*speedFactor#-0.5*frogY#)<=get ground height(1,object position x(1), object position z(1)))
   player1Status=0
   position object 1,object position x(1),0.5*frogY#+get ground height(1,object position x(1), object position z(1)),object position z(1)
   player1Height#=object position y(1)
      gosub _playerCollision
      if object collision (1,2)>0
      move object up 1,0.5*speedFactor#
      player1Height#=player1Height#+0.5*speedFactor#
      endif
   else
   move object down 1,0.5*speedFactor#
   player1Height#=player1Height#-0.5*speedFactor#
      gosub _playerCollision
      if object collision (1,2)>0
      move object up 1,0.5*speedFactor#
      player1Height#=player1Height#+0.5*speedFactor#
      endif
   endif
endif

if player1Direction$="left"
   if object position x(1)>-15 then move object left 1,0.5*speedFactor#
   gosub _playerCollision
   if object collision (1,2)>0 then move object right 1,0.5*speedFactor#
endif

if player1Direction$="right"
   if object position x(1)<15 then move object right 1,0.5*speedFactor#
   gosub _playerCollision
   if object collision (1,2)>0 then move object left 1,0.5*speedFactor#
endif

return



_player2Control:
player2Height# = object position y(2)

if player2Status=0
   if inkey$()="a"
      if object position x(2)>-15
      position object 2, (object position x(2)-0.5*speedFactor#), object position y(2), object position z(2)
      player2Direction$="left"
         gosub _playerCollision
         if object collision (1,2)>0
            if (player1Direction$="unknown" and object position x(2)>-13.5)
            position object 1, (object position x(1)-0.5*speedFactor#), object position y(1), object position z(1)
            else
            position object 2, (object position x(2)+0.5*speedFactor#), object position y(2), object position z(2)
            endif
         endif
      endif

   else
      if inkey$()="d"
      if object position x(2)<15
      position object 2, (object position x(2)+0.5*speedFactor#), object position y(2), object position z(2)
      player2Direction$="right"
         gosub _playerCollision
         if object collision (1,2)>0
            if (player1Direction$="unknown" and object position x(2)<13.5)
            position object 1, (object position x(1)+0.5*speedFactor#), object position y(1), object position z(1)
            else
            position object 2, (object position x(2)-0.5*speedFactor#), object position y(2), object position z(2)
            endif
         endif
      endif
      else
      player2Direction$="unknown"
      endif
   endif

   if inkey$()="w"
      if object position z(2)<12
      position object 2, object position x(2), object position y(2), (object position z(2)+2.3)
         gosub _playerCollision
         if object collision (1,2)>0
         position object 2, object position x(2), object position y(2), (object position z(2)-2.3)
         endif
      endif
   else
      if inkey$()="s"
      if object position z(2)>11
      position object 2, object position x(2), object position y(2), (object position z(2)-2.3)
         gosub _playerCollision
         if object collision (1,2)>0
         position object 2, object position x(2), object position y(2), (object position z(2)+2.3)
         endif
      endif
      endif
   endif


   if mouseclick()=1
      play sound 1
      gosub _player2Jump
   endif

else
   gosub _player2Jump
endif

return


_player2Jump:
if player2Status=1
   if player2Height#<4
   move object up 2,0.5*speedFactor#
   player2Height#=player2Height#+0.5*speedFactor#
      gosub _playerCollision
      if object collision(1,2)>0
      move object down 2,0.5*speedFactor#
      player2Height#=player2Height#-0.5*speedFactor#
      endif
   else
   player2Status=2
   endif
endif
if player2Status=0
   player2Status=1
   move object up 2,0.5*speedFactor#
   player2Height#=player2Height#+0.5*speedFactor#
      gosub _playerCollision
      if object collision(1,2)>0
      move object down 2,0.5*speedFactor#
      player2Height#=player2Height#-0.5*speedFactor#
      endif
endif
if player2Status=2
   if ((object position y(2)-0.5*speedFactor#-0.5*frogY#)<=get ground height(1,object position x(2), object position z(2)))
   player2Status=0
   position object 2,object position x(2),0.5*frogY#+get ground height(1,object position x(2), object position z(2)),object position z(2)
   player2Height#=object position y(2)
      gosub _playerCollision
      if object collision (1,2)>0
      move object up 2,0.5*speedFactor#
      player2Height#=player2Height#+0.5*speedFactor#
      endif
   else
   move object down 2,0.5*speedFactor#
   player2Height#=player2Height#-0.5*speedFactor#
      gosub _playerCollision
      if object collision (1,2)>0
      move object up 2,0.5*speedFactor#
      player2Height#=player2Height#+0.5*speedFactor#
      endif
   endif
endif

if player2Direction$="left"
   if object position x(2)>-15 then move object left 2,0.5*speedFactor#
   gosub _playerCollision
   if object collision (1,2)>0 then move object right 2,0.5*speedFactor#
endif

if player2Direction$="right"
   if object position x(2)<15 then move object right 2,0.5*speedFactor#
   gosub _playerCollision
   if object collision (1,2)>0 then move object left 2,0.5*speedFactor#
endif

return


function enemyCollision(objectNumber):
result=0

for i=11 to 17
if (object collision (objectNumber, i)>0)

   if i<15
      play sound 3
      result=-1
      if i<13 then position object i, rnd(12)-4.5, (get ground height(1,0,0)+object size y(i)+3.5), 75
      if i>12 then position object i, rnd(12)-4.5, (get ground height(1,0,0)+object size y(i)/2), 75
      hide object i

      hide object objectNumber
      position object objectNumber+100, object position x(objectNumber), object position y(objectNumber), object position z(objectNumber)
      show object objectNumber+100
      play object objectNumber+100
      while object playing(objectNumber+100)=1
      sync
      endwhile

      hide object objectNumber+100
      if objectNumber=1
      position object 1,-10,get ground height(1,15,10)+(object size y(1)/2),10
      player1Direction$ = "unknown"
      player1Height# = 0
      player1Status = 0
      player1Score = 0
      else
      position object 2,10,get ground height(1,-15,10)+(object size y(2)/2),10
      player2Direction$ = "unknown"
      player2Height# = 0
      player2Status = 0
      player2Score = 0
      endif
      show object objectNumber

   else
      play sound 4
      result=1
      position object i, rnd(12)-4.5, (get ground height(1,0,0)+object size y(i)/2), 75
      hide object i
   endif
endif
next i
endfunction result



function heartPlus(objectNumber):
if (objectNumber=1)
   if object visible(22)=1
      show object 23
   else
      show object 22
   endif
else
   rem do the same for 24-26
endif
endfunction


function heartMinus(objectNumber):
if (objectNumber=1)
   if object visible(23)=1
      hide object 23
   else
      if object visible(22)=1
         hide object 22
      else
         rem game over, char 2 win
         hide object 21
         sync
         gameOver(2)
      endif
   endif
else
   if object visible(26)=1
      hide object 26
   else
      if object visible(25)=1
         hide object 25
      else
         rem game over, char 1 win
         hide object 24
         sync
         gameOver(1)
      endif
   endif
endif
endfunction

function addScore(playerScore):
playerScore = playerScore+100
endfunction playerScore


function gameOver(option):

for i=1 to 199
if object exist(i)=1
if i=4
else
delete object i
endif
endif
next i


if option=1
show object 201
play object 201
endif
if option=2
show object 202
play object 202
endif

if option<0
   if player1Score <= player2Score
      show object 202
      play object 202
      option=2
   else
      show object 201
      play object 201
      option=1
   endif
endif

stop music 1
play sound 2

while object playing(option+200)=1
if option>0
   if option=2
      center text screen width()/2,screen height()/2-100, "Player 2 WON!"
   else
      center text screen width()/2,screen height()/2-100, "Player 1 WON!"
   endif
else
   if player1Score < player2Score
      center text screen width()/2,screen height()/2-100, "Player 2 WON!"
   else
      center text screen width()/2,screen height()/2-100, "Player 1 WON!"
   endif
endif
sync
endwhile
sleep 1000

play animation 5
play music 5

while animation playing(5)=1
sync
endwhile

end
endfunction


_playerCollision:
if object collision(1,2)>0
playerCollision=1
else
playerCollision=0
endif
return


