REM  Coded by Phaelax (phaelax@hotmail.com)
REM  http://www.angelfire.com/80s/phaelax/ (still there?)
REM =========================================================
 
`set display mode 1600,1200,32
set display mode 1024, 768, 32
set camera range 1,10000
 
rem concrete
for x=1 to 128
   for y = 1 to 128
      r = rnd(255)
      dot x,y,rgb(r,r,r)
   next y
next x
get image 1,1,1,128,128
 
rem water
for x=1 to 64
   for y = 1 to 64
      r = rnd(128)+128
      dot x,y,rgb(r/3,r/3,r)
   next y
next x
get image 2,1,1,64,64
 
rem water
for x=1 to 64
   for y = 1 to 64
      r = rnd(128)+128
      dot x,y,rgb(r,r/2,r/2)
   next y
next x
get image 3,1,1,64,64
 
rem cursor
cls 0
ink rgb(255,0,0),0
box 31,1,33,64
box 1,31,64,33
get image 4,1,1,64,64
 
 
 
 
backdrop on
color backdrop 0
sync on
hide mouse
 
 
REM DEFINE VARIABLES
rem "total" is the total number of objects that currently have collision
    `setup for them.
rem "amt_grav#" is really the amount of force acting against gravity.
rem "grav_str#" is the strength of the gravity.
rem "x#,y#,z#" is the player's starting position
 
total=15
next_free_object = 574
playersize#=30.0
playersizey#=55.0
amt_grav#=6.0
grav_str#=0.3
dim sobject#(total, 6)
gosub define_collision_areas
x#=900.0
y#=70.0
z#=2000.0
dim bullet(5,5)
bullet_speed#=22.0
my_life=100
sw=screen width()
sh=screen height()
shotDelay = 500
 
 
REM water
make object plain 1, 100,100
xrotate object 1,270
set object cull 1,0
fix object pivot 1
scale object 1,7000,7000,100
position object 1,2000,0,2000
texture object 1,2
scale object texture 1,25,25
 
REM underwater ground
make object plain 2, 100,100
xrotate object 2,270
set object cull 2,0
fix object pivot 2
scale object 2,7000,7000,100
position object 2,2000,-650,2000
texture object 2,3
scale object texture 2,25,25
 
 
 
 
 
REM INITIALIZE MISC THINGS
sync rate 60
 
 
 
 
 
REM CREATE MODELS\OBJECTS
rem cursor
make object plain 517,10,10
lock object on 517
position object 517, 0,0,120
texture object 517,4
ghost object on 517
 
rem bullet
for t=1 to 5
 `inside of bullet
  make object sphere t+549, 20
  ghost object on t+549
  color object t+549,rgb(200,200,0)
 `outside of bullet
  make object sphere t+554,25
  ghost object on t+554
  color object t+554,rgb(255,125,0)
  glue object to limb t+554,t+549,0
 `bullet explosion object
  make object plain t+559,100,100
  ghost object on t+559
  bullet(t,1)=0
  bullet(t,2)=t+549
next t
 
 
rem load rest of world
gosub create_world
 
 
 
 
REM ======================== MAIN LOOP ====================================
DO
  ink rgb(0,0,200),0
  bar=(sw/2)-my_life
  box bar,sh-21,bar+(my_life*3),sh-1
  ink rgb(255,255,255),0
  gosub reset_variables
  gosub player_controls
  rem jumping
  if jump=1
    dec grav#,grav_str#
    y#=y#+grav#
  endif
  rem crouching
  if crouching=1 and playersizey#>35.0 then dec playersizey#,2:dec y#,2
  if crouching=0 and playersizey#<55.0 then inc playersizey#,2
 
  gosub handle_bullets
  gosub do_the_collision
  gosub camera_status
 
 
  if jump=0 then plat=0
  if x#>0.0 and x#<500.0 and z#>1750.0 and z#<2250.0 and y#<=10.5+playersizey# and y#>=-10.5+playersizey# and plat=0
    plat=1
    jump=1
    grav#=40
  endif
 if x#>2900.0 and x#<3400.0 and z#>5005.0 and z#<5505.0 and y#<=10.5+playersizey# and y#>=-10.5+playersizey# and plat=0
    plat=1
    jump=1
    grav#=40
  endif
 if x#>2900.0 and x#<3400.0 and z#>-1494.0 and z#<-994.0 and y#<=10.5+playersizey# and y#>=-10.5+playersizey# and plat=0
    plat=1
    jump=1
    grav#=40
  endif
 
 
  if y# < 0
      if fogon = 0
         amt_grav#=3.0
         grav_str# = 0.01
         fogon=1
         fog on
         fog color rgb(0,0,255)
         fog distance 2000
      endif
  else
      if fogon=1
         amt_grav#=6.0
         grav_str# = 0.3
         fogon=0
         fog off
      endif
  endif
 
 
 
set cursor 0,0
print "FPS: "+str$(screen fps())
print "X: ",x#
print "Y: ",y#
print "Z: ",z#
print "damage#: "+str$(damage#)
print "My Life: "+str$(my_life)
sync
LOOP
REM ======================== END MAIN LOOP ===========================
 
 
 
 
 
REM ________________________ FUNCTIONS _________________________
 
player_controls:
  if shiftkey()=1 then runspeed#=6.0
  if upkey()=1
    x#=newxvalue(x#,a#,6+runspeed#)
    z#=newzvalue(z#,a#,6+runspeed#)
  endif
  if downkey()=1
    x#=newxvalue(x#,a#,-6-runspeed#)
    z#=newzvalue(z#,a#,-6-runspeed#)
  endif
  if leftkey()=1
    x#=newxvalue(x#,wrapvalue(a#-90.0),5.0+runspeed#)
    z#=newzvalue(z#,wrapvalue(a#-90.0),5.0+runspeed#)
  endif
  if rightkey()=1
    x#=newxvalue(x#,wrapvalue(a#+90.0),5.0+runspeed#)
    z#=newzvalue(z#,wrapvalue(a#+90.0),5.0+runspeed#)
  endif
  if keystate(82)=1 and jump=0 then jump=1:grav#=amt_grav#:oldjump#=y#
  if keystate(79)=1 and jump=0 then crouching=1
  if mouseclick()=2 and jump=0 then jump=1:grav#=amt_grav#:oldjump#=y#
  if mouseclick()=1 and timer() >= lastShot+shotDelay and anything_alive<5 then fireshot=1:lastShot=timer()
  if keystate(31)=1 and jump=0 then jump=1:grav#=30
return
` _____________________________________________________________________
camera_status:
  rem rotate camera according to mouse
  a#=wrapvalue(a#+(mousemovex()/3.0))
  rem position and rotate camera
  cxa#=cxa#+(mousemovey()/3.0)
  if cxa#<-90.0 then cxa#=-90.0
  if cxa#>90.0 then cxa#=90.0
  position camera x#,y#+playersizey#,z#
  rotate camera wrapvalue(cxa#),a#,0
return
` _____________________________________________________________________
reset_variables:
  hithead=0
  runspeed#=0
  oldx#=x#
  oldy#=y#
  oldz#=z#
return
` _____________________________________________________________________
create_world:
  `walkway below build'ns
  make object cube 500,100
  scale object 500,2500,20,300
  position object 500,1750,0,2000
  texture object 500,1
  `color object 500, rgb(0,200,0)
  scale object texture 500,12,2
 
  make object cube 600,100
  scale object 600,300,20,6000
  position object 600,3150,0,2000
  texture object 600,1
  `color object 600, rgb(0,200,0)
  scale object texture 600,2,30
 
  `jump pad
  make object cube 501,100
  scale object 501,500,20,500
  position object 501,254,0,2000
  `texture object 501,16
  color object 501, rgb(255,0,0)
 
  make object cube 601,100
  scale object 601,500,20,500
  position object 601,3150,0,5255
  `texture object 601,16
  color object 601, rgb(255,0,0)
 
  make object cube 602,100
  scale object 602,500,20,500
  position object 602,3150,0,-1244
  `texture object 602,16
  color object 602, rgb(255,0,0)
 
 
  `build'n #1
  make object cube 505,100
  scale object 505,500,3000,2000
  position object 505,375,500,3350
  `color object 505,rgb(255,0,0)
  texture object 505,1
  scale object texture 505,8,16
 
  make object cube 506,100
  scale object 506,500,3000,2000
  position object 506,1575,500,3350
  color object 506,rgb(255,0,0)
  `texture object 506,1
  `scale object texture 506,8,16
 
  make object cube 507,100
  scale object 507,700,3000,1600
  position object 507,975,500,3350
  color object 507,rgb(128,128,255)
  `texture object 507,33
  scale object texture 507,2,8
 
  make object plain 508,710,3000
  position object 508,975,500,2450
  `texture object 508,29
  ghost object on 508
 
  make object plain 509,710,3000
  position object 509,975,500,4250
  `texture object 509,29
  ghost object on 509
 
  make object cube 513,100
  scale object 513, 1800,20,2100
  position object 513, 975,2000,3350
  `texture object 513,5
  scale object texture 513,10,12
 
  make object cube 626,100
  scale object 626,10,400,800
  xrotate object 626,180
  position object 626,1825,1200,3350
  `texture object 626,30
 
 `build'n #2
  make object cube 502,100
  scale object 502,500,3000,2000
  position object 502,375,500,650
  `texture object 502,5
  scale object texture 502,4,8
  make object cube 510,100
  scale object 510,500,3000,2000
  position object 510,1575,500,650
  `texture object 510,5
  scale object texture 510,4,8
  make object cube 511,100
  scale object 511,700,3000,1600
  position object 511,975,500,650
  `texture object 511,31
  scale object texture 511,2,8
  make object plain 512,710,3000
  `position object 512,975,500,-250
  texture object 512,29
  ghost object on 512
  make object plain 503,710,3000
  position object 503,975,500,1550
  `texture object 503,29
  ghost object on 503
 
  make object cube 514,100
  scale object 514, 1800,20,2100
  position object 514, 975,2000,650
  `texture object 514,5
  scale object texture 514,10,12
 
  make object cube 627,100
  scale object 627,10,400,800
  xrotate object 627,180
  position object 627,1825,1200,650
  `texture object 627,32
 
 
 `build'n #3
  make object cube 504,100
  scale object 504,2000,2000,5000
  position object 504,4600,500,2000
  `texture object 504,8
  scale object texture 504,20,10
 
  make object cone 519,100
  xrotate object 519,180
  position object 519,1575,0,2350
  `texture object 519,5
 
  make object cone 515,100
  xrotate object 515,180
  position object 515,1575,500,2350
  `texture object 515,5
 
 
 
  make object cone 520,100
  xrotate object 520,180
  position object 520,1575,1000,2350
  `texture object 520,5
 
  make object cone 521,100
  xrotate object 521,180
  position object 521,1575,1500,2350
  `texture object 521,5
 
 
  make object cone 522,100
  xrotate object 522,180
  position object 522,375,0,2350
  `texture object 522,5
 
  make object cone 523,100
  xrotate object 523,180
  position object 523,375,500,2350
  `texture object 523,5
 
  make object cone 524,100
  xrotate object 524,180
  position object 524,375,1000,2350
  `texture object 524,5
 
  make object cone 525,100
  xrotate object 525,180
  position object 525,375,1500,2350
  `texture object 525,5
 
return
` _____________________________________________________________________
define_collision_areas:
  for sc=1 to total
    read sobject#(sc,1)
    read sobject#(sc,2)
    read sobject#(sc,3)
    read sobject#(sc,4)
    read sobject#(sc,5)
    read sobject#(sc,6)
  next sc
return
` _____________________________________________________________________
do_the_collision:
 
  REM COLLISION DETECTION
  FOR t = 1 to total
    if abs(oldx#-sobject#(t,1))<sobject#(t,4)+playersize# and abs(oldz#-sobject#(t,3))<sobject#(t,6)+playersize# and abs((y#)-sobject#(t,2))<sobject#(t,5)+playersizey#
      if y#<sobject#(t,2)-sobject#(t,5)
        y#=oldy#:grav#=grav#*-0.5:crouching=2
        if crouching=2 then dec playersizey#,2:dec y#,2
      endif
      if y#>sobject#(t,2)+sobject#(t,5) then jump=0:currents=t
    else
      crouching=0
    endif
    if abs(x#-sobject#(t,1))<sobject#(t,4)+playersize# and abs(z#-sobject#(t,3))<sobject#(t,6)+playersize# and abs((y#)-sobject#(t,2))<sobject#(t,5)+playersizey#
      if jump=0 and (y#-playersizey#)+30>=sobject#(t,2)+sobject#(t,5) then y#=sobject#(t,2)+sobject#(t,5)+playersizey#+0.5:currents=t
      if abs(oldx#-sobject#(t,1))<sobject#(t,4)+playersize# then z#=oldz#
      if abs(oldz#-sobject#(t,3))<sobject#(t,6)+playersize# then x#=oldx#
    endif
  NEXT t
 
  if currents<>0
    if abs(x#-sobject#(currents,1))>sobject#(currents,4)+playersize# or abs(z#-sobject#(currents,3))>sobject#(currents,6)+playersize#
      if jump=0
        jump=1
        grav#=0
        currents=0
      endif
    endif
  endif
 
return
` _____________________________________________________________________
bullet_collision:
 ox#=object position x(bullet(bt,2))
 oy#=object position y(bullet(bt,2))
 oz#=object position z(bullet(bt,2))
 
  if ox#>11000 or ox#<-2000 or oz#>7000 or oz#<-3000 or oy#<-700 or oy#>6500
    bullet(bt,1)=0
    hide object bullet(bt,2):hide object bullet(bt,2)+5
    fire=0
    bullet(bt,3)=1
 
  endif
 
 FOR t = 1 to total
  if abs(ox#-sobject#(t,1))<sobject#(t,4)+10 and abs(oz#-sobject#(t,3))<sobject#(t,6)+10 and abs((oy#)-sobject#(t,2))<sobject#(t,5)+10
    bullet(bt,1)=0
    hide object bullet(bt,2):hide object bullet(bt,2)+5
    fire=0
    bullet(bt,3)=1
    gosub check_dmg
  endif
 NEXT t
 
return
` _____________________________________________________________________
handle_bullets:
  if fireshot=1
    for bt=1 to 5
      if bullet(bt,1)=0 and found=0
        found=1
        fireshot=0
        firing=1
        bullet(bt,1)=1
        position object bullet(bt,2),x#,y#+playersizey#,z#
        set object to camera orientation bullet(bt,2)
        show object bullet(bt,2):show object bullet(bt,2)+5
      endif
    next t
    found=0
  endif
 
  if firing=1
    anything_alive=0
    for bt=1 to 5
      if bullet(bt,1)=1
        move object bullet(bt,2),bullet_speed#
        gosub bullet_collision
      endif
      anything_alive=anything_alive+bullet(bt,1)
    next t
  endif
 
  if anything_alive=0 then firing=0
 
 
  for bt=1 to 5
    if bullet(bt,3)=1
      box#=object position x(bullet(bt,2))
      boy#=object position y(bullet(bt,2))
      boz#=object position z(bullet(bt,2))
      position object bullet(bt,2)+10, box#,boy#,boz#
      bullet(bt,4)=19
      bullet(bt,3)=0
      bullet(bt,5)=1
    endif
    if bullet(bt,5)=1
      set object to camera orientation bullet(bt,2)+10
      bullet(bt,4)=bullet(bt,4)+1
      `texture object bullet(bt,2)+10,bullet(bt,4)
      if bullet(bt,4)=28 then bullet(bt,5)=0
    endif
  next bt
return
` _____________________________________________________________________
check_dmg:
  dmg_range=abs(ox#-x#)+abs(oy#-y#)+abs(oz#-z#)
  if dmg_range<200
    damage#=(20-(dmg_range/10))*7
    dec my_life,damage#
  endif
return
 
 
 
 
REM ________________________END FUNCTIONS _________________________
 
REM COLLISION DATA
data 2000.0,-650.0,2000.0,3500.0,1.0,3500.0
 
data 2000.0,0.0,2000.0,1500.0,10.0,150.0
data 3150.0,0.0,2000.0,150.0,10.0,3000.0
 
data 250.0,0.0,2000.0,250.0,10.0,250.0
data 3150.0,0.0,5255.0,250.0,10.0,250.0
data 3150.0,0.0,-1244.0,250.0,10.0,250.0
 
 
data 375.0,500.0,3350.0,250.0,1500.0,1000.0
data 1575.0,500.0,3350.0,250.0,1500.0,1000.0
data 975.0,500.0,3350.0,355.0,1500.0,900.0
data 975.0,2000.0,3350.0,900.0,10.0,1050.0
 
data 375.0,500.0,650.0,250.0,1500.0,1000.0
data 1575.0,500.0,650.0,250.0,1500.0,1000.0
data 975.0,500.0,650.0,355.0,1500.0,900.0
data 975.0,2000.0,650.0,900.0,10.0,1050.0
 
data 4600.0,500.0,2000.0,1000.0,1000.0,2500.0