cls
 
 
 
remstart
thanks to:
dancedreemer (split screen demo from code snippets board)
Monster Hunt Tutorial (3rd person camera movement)
remend
center text 320,240,"creating media... please be patient"
sync on
sync rate 0
randomize timer()
set text font "verdana"
set text size 14
 
dim CamX#(1)
dim CamY#(1)
dim CamZ#(1)
dim FrontX#(1)
dim FrontZ#(1)
dim X#(1)
dim Y#(1)
dim Z#(1)
dim AngleY#(1)
dim Health(1) : Health(0)=10 : Health(1)=10
dim MissFireX#(1)
dim MissFireY#(1)
dim MissFireZ#(1)
dim missposx#(1)
dim missposy#(1)
dim missposz#(1)
dim MissileFired(1)
dim missdist#(1)
dim MissEnabled(1)
 
 
sync
 
gosub healthbars
gosub radarbg
gosub loadboats
gosub loadlevel
gosub loadweaps
 
 
cls rgb(155,155,255)
 
do
gosub matrupd
gosub movesub
if downkey()=1 and missilefired(0)=0 and MissEnabled(0)=1 then playerfiring=0 : gosub firemissile
if Keystate(31)=1 and missilefired(1)=0 and MissEnabled(1)=1 then playerfiring=1 : gosub firemissile
gosub movemissile
gosub 2ddisplay
gosub healthcheck
sync
loop
 
 
loadboats:
make object box 1,3,1,7
position object 1,125,0,125
make object box 101,3,1,7
position object 101,175,0,175
`healthy
create bitmap 3,4,2
ink rgb(0,255,0),0
box 0,0,1,1
ink rgb(255,0,0),0
box 1,0,2,1
ink rgb(255,255,0),0
box 2,0,3,1
get image 3,0,0,1,1
get image 14,1,0,2,1
get image 15,2,0,3,1
delete bitmap 3
texture object 1,3
texture object 101,14
return
 
 
loadlevel:
`-----sky-----
backdrop on
color backdrop rgb(130,130,255)
if fog available()=1
   fog on
   fog distance 450
   fog color rgb(100,100,100)
endif
 
`-----water-----
make matrix 1,300,300,30,30
gosub makewatertexture
Prepare Matrix Texture 1,1,1,1
dim matrheight(30,30)
for x=0 to 30
   for z=0 to 30
      matrheight(x,z)=rnd(360)
   next z
next x
 
 
`----boundaries----
gosub wallstext
for t=2 to 5
   make object cube t,100
   scale object t,3,30,260
   texture object t,2
   scale object texture t,26,3
next t
for t=4 to 5
   yrotate object t,90
next t
position object 2,20,-5,150
position object 3,280,-5,150
position object 4,150,-5,20
position object 5,150,-5,280
 
`missile zones
for t=35 to 38
   make object cone t,30
   scale object t,100,150,100
   texture object t,15
   set object t,1,1,0
   ghost object on t
next t
position object 35,50,-1,50
position object 36,250,-1,50
position object 37,50,-1,250
position object 38,250,-1,250
return
 
 
 
matrupd:
for x=0 to 30
   for z=0 to 30
      set matrix height 1,x,z,1.5*sin(matrheight(x,z))
      matrheight(x,z)=wrapvalue(matrheight(x,z)+5)
   next z
next x
update matrix 1
return
 
movesub:
 
`-------------BOAT------------------
 
X#(0)=object position x(1)
Z#(0)=object position z(1)
AngleY#(0)=object angle y(1)
X#(1)=object position x(101)
Z#(1)=object position z(101)
AngleY#(1)=object angle y(101)
 
if upkey()=1
   XTest# = Newxvalue(X#(0),AngleY#(0),0.8)
   ZTest# = Newzvalue(Z#(0),AngleY#(0),0.8)
   if XTest#>23 and XTest#<277 and ZTest#>23 and ZTest#<277
      move object 1,0.8
   endif
endif
if leftkey()=1
   yang1#=wrapvalue(object angle y(1)-3)
   yrotate object 1,yang1#
   `turn object left 1,3
endif
if rightkey()=1
   yang1#=wrapvalue(object angle y(1)+3)
   yrotate object 1,yang1#
   `turn object right 1,3
endif
 
if Keystate(17)=1
   XTest# = Newxvalue(X#(1),AngleY#(1),0.8)
   ZTest# = Newzvalue(Z#(1),AngleY#(1),0.8)
   if XTest#>23 and XTest#<277 and ZTest#>23 and ZTest#<277
      move object 101,0.8
   endif
endif
if Keystate(30)=1
   yang2#=wrapvalue(object angle y(101)-3)
   yrotate object 101,yang2#
   `turn object left 101,3
endif
if Keystate(32)=1
   yang2#=wrapvalue(object angle y(101)+3)
   yrotate object 101,yang2#
   `turn object right 101,3
endif
 
X#(0)=object position x(1)
Z#(0)=object position z(1)
X#(1)=object position x(101)
Z#(1)=object position z(101)
 
for t=0 to 1
   Y#(t)=get ground height(1,X#(t),Z#(t))+0.7
   position object (1+(t*100)),X#(t),Y#(t),Z#(t)
next t
 
`-------------------CAMERA------------------
 
for t=0 to 1
   CamX#(t) = Newxvalue(X#(t),AngleY#(t)-180,8)
   CamZ#(t) = Newzvalue(Z#(t),AngleY#(t)-180,8)
   CamY#(t)=get ground height(1,CamX#(t),CamZ#(t))+4.9
   FrontX#(t) = Newxvalue(X#(t),AngleY#(t),20)
   FrontZ#(t) = Newzvalue(Z#(t),AngleY#(t),20)
next t
 
position camera CamX#(0),CamY#(0),CamZ#(0)
point camera FrontX#(0),0,FrontZ#(0)
set camera view 321,1,639,240
 
position camera CamX#(1),CamY#(1),CamZ#(1)
point camera FrontX#(1),0,FrontZ#(1)
set camera view 1,1,319,240
 
 
 
 
 
 
 
 
 
`missile enabled
for t=0 to 1
   reloaddist#=SQRT((50-Z#(t))^2+(50-X#(t))^2)
   if reloaddist#<10 then MissEnabled(t)=1
   reloaddist#=SQRT((250-Z#(t))^2+(50-X#(t))^2)
   if reloaddist#<10 then MissEnabled(t)=1
   reloaddist#=SQRT((50-Z#(t))^2+(250-X#(t))^2)
   if reloaddist#<10 then MissEnabled(t)=1
   reloaddist#=SQRT((250-Z#(t))^2+(250-X#(t))^2)
   if reloaddist#<10 then MissEnabled(t)=1
next t
return
 
 
loadweaps:
make object cylinder 30,5
xrotate object 30,90
scale object 30,15,15,40
fix object pivot 30
hide object 30
make object cylinder 130,5
xrotate object 130,90
scale object 130,15,15,40
fix object pivot 130
hide object 130
return
 
 
firemissile:
 
MissFireX#(playerfiring) = Newxvalue(X#(playerfiring),AngleY#(playerfiring),2)
MissFireZ#(playerfiring) = Newzvalue(Z#(playerfiring),AngleY#(playerfiring),2)
MissFireY#(playerfiring) = get ground height(1,MissFireX#(playerfiring),MissFireZ#(playerfiring))+1
position object 30+(playerfiring*100),MissFireX#(playerfiring),MissFireY#(playerfiring),MissFireZ#(playerfiring)
set object to object orientation 30+(playerfiring*100),1+(playerfiring*100)
show object 30+(playerfiring*100)
MissileFired(playerfiring) = 1
MissEnabled(playerfiring) = 0
return
 
movemissile:
`move the missiles
for t=0 to 1
   if object visible(30+(t*100))=1
      move object 30+(t*100),5
      missposx#(t)=object position x(30+(t*100))
      missposz#(t)=object position z(30+(t*100))
      missposy#(t)=get ground height(1,missposx#(t),missposz#(t))+1
      position object 30+(t*100),missposx#(t),missposy#(t),missposz#(t)
   endif
next t
 
`boundaries
if missposx#(0)>277
   gosub missiledie1
endif
if missposz#(0)>277
   gosub missiledie1
endif
if missposx#(0)<23
   gosub missiledie1
endif
if missposz#(0)<23
   gosub missiledie1
endif
if missposx#(1)>277
   gosub missiledie2
endif
if missposz#(1)>277
   gosub missiledie2
endif
if missposx#(1)<23
   gosub missiledie2
endif
if missposz#(1)<23
   gosub missiledie2
endif
 
 
 
 
`missile collision
if object visible(30)=1
   missdist#(0)=SQRT((missposz#(0)-Z#(1))^2+(missposx#(0)-X#(1))^2)
   if missdist#(0)<5
      Health(0)=Health(0)-1
      gosub missiledie1
   endif
endif
if object visible(130)=1
   missdist#(1)=SQRT((missposz#(1)-Z#(0))^2+(missposx#(1)-X#(0))^2)
   if missdist#(1)<5
      Health(1)=Health(1)-1
      gosub missiledie2
   endif
endif
return
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
makewatertexture:
create bitmap 1,64,64
for x=0 to 63
   for y=0 to 63
      ink rgb(rnd(10),rnd(70),rnd(130)+125),0
      dot x,y
   next y
next x
blur bitmap 1,6
get image 1,0,0,63,63
delete bitmap 1
return
 
 
 
 
 
 
 
 
 
 
 
 
wallstext:
create bitmap 2,64,64
for x=0 to 63
   for y=0 to 63
      ink rgb(rnd(130),rnd(70),rnd(40)),0
      dot x,y
   next y
next x
blur bitmap 2,6
get image 2,0,0,63,63
delete bitmap 2
paste image 2,0,0
return
 
 
missiledie1:
hide object 30
MissileFired(0)=0
return
missiledie2:
hide object 130
MissileFired(1)=0
return
 
 
healthbars:
create bitmap 4,640,480
for t=1 to 10
   ink rgb(255,255,0),0
   box 20,t*10,120,t*10+5
   ink rgb(255,0,0),0
   box 21,t*10+1,119,t*10+4
   ink rgb(0,255,0),0
   box 21,t*10+1,19+(10*t),t*10+4
   get image t+3,20,t*10,121,t*10+6
next t
delete bitmap 4
return
 
 
 
healthcheck:
for t=0 to 1
   If Health(t)=0
      If t=0
         other=1
      else
         other=0
      endif
      cls 0
      ink rgb(255,0,0),0
      set text size 70
      If Health(other)>0
         center text 320,200,"Player " + Str$(other) + " Wins"
      Else
         center text 320,200,"It was a draw"
      Endif
      gosub deleteall
      wait 400
      center text 320,250,"..."
      center text 320,120,"..."
      wait 400
      center text 320,280,".."
      center text 320,90,".."
      wait 400
      center text 320,310,"."
      center text 320,60,"."
      wait 400
      end
   Endif
Next t
return
 
 
 
 
deleteall:
delete matrix 1
for t=1 to 130
   if object exist(t)=1 then delete object t
next t
for t=1 to 15
   delete image t
next t
backdrop off
return
 
 
 
 
 
 
 
 
 
 
 
2ddisplay:
 
ink rgb(0,0,0),0
center text 160,400,"w: forwards"
center text 160,415,"a: left"
center text 160,430,"d: right"
center text 160,445,"s: fire"
center text 480,400,"up key: forwards"
center text 480,415,"left key: left"
center text 480,430,"right key: right"
center text 480,445,"down key: fire"
ink rgb(255,255,255),0
box 565,425,639,479
ink 0,0
Text 580,430,Str$(Screen FPS())
 
`show health bars
for t=0 to 1
   if Health(t)>0 then paste image Health(t)+3,110+t*320,340
   center text 160+T*320,350,"Player " + Str$(t)
next t
center text 320,420,"To load a missile, go to a missile"
center text 320,435,"zone (yellow circles on map)"
 
for t=0 to 1
   if MissEnabled(t)=1
      paste image 17,430-t*320,300
   else
      paste image 18,430-t*320,300
   endif
next t
 
 
`radar
paste image 16,290,345
ink rgb(0,255,0),0
circle x#(0)/5+290,z#(0)/5+345,2
ink rgb(255,0,0),0
circle x#(1)/5+290,z#(1)/5+345,2
 
ink rgb(55,55,55),rgb(255,255,255)
for t=0 to 1
   if MissileFired(t)=1
      dot missposx#(t)/5+290,missposz#(t)/5+345
   endif
next t
 
 
return
 
 
 
radarbg:
create bitmap 17,640,480
ink rgb(255,255,255),rgb(255,255,255)
box 290,345,350,405
ink rgb(255,255,0),0
circle 300,355,3
circle 340,355,3
circle 300,395,3
circle 340,395,3
get image 16,290,345,351,406
delete bitmap 17
 
create bitmap 17,200,50
set cursor 2,0
print "missile loaded"
set cursor 17,20
print "no missile"
get image 17,0,2,100,15
get image 18,0,22,100,35
delete bitmap 17
return