Rem Project: bearings
Rem Created: 10/03/2006 09:21:27
 
Rem ***** Main Source File *****
 
set display mode 1024,768,32
sync on
hide mouse
autocam off
color backdrop 0
position camera 0,0,-50
hide light 0
make light 1
position light 1,-50,-50,-10
set ambient light 10
 
gosub values
gosub make_planets
gosub make_ship
gosub make_particles
gosub make_stars
 
 
starttime=timer()
do
 
time=timer()-starttime
dt=time-oldtime
oldtime=time
 
gosub controls
gosub collision
gosub physics
gosub update_particles
gosub stats
gosub fuel
sync
loop
 
values:
 
x#=-10
y#=-10
angvel#=0.1
thrustvalue#=50
mass#=10000000 `mass of ship
gravconst#=.4
fuel#=100
fueldepletion#=0.001
 
return
 
fuel:
 
if upkey()=1 and fuel#>=0 then dec fuel#,fueldepletion#*dt
if fuel#<0 then fuel#=0
 
 
return
 
make_particles:
 
fire=free_entity()
ink rgb(255,200,50),0
box 0,0,1,1
get image fire,0,0,1,1
make particles 1,fire,10,3
set particle life 1,5
set particle floor 1,0
set particle gravity 1,50
return
 
update_particles:
if upkey()=1 and fuel#>0 and damage#<100 then show particles 1 else hide particles 1
position particles 1,object position x(ship)-sin(angle#)*object size x(ship)/2,object position y(ship)-cos(angle#)*object size y(ship)/2,object position z(ship)
rotate particles 1,0,0,-angle#
return
 
stats:
ink rgb(0,255,0),0
if damage#>100 then damage#=100
text 0,0,"Damage: "+str$(int(damage#))+" %"
text 0,20,"Fuel: "+str$(int(fuel#))
text 0,40,"Rating: "+str$(int(rating#))
text 0,60,caption$
if damage#>=100 or fuel#<=0 then text 0,100,"Game Over"
return
 
make_planets:
surface=free_entity()
create bitmap 1,100,100
ink rgb(255,255,240),0
box 0,0,100,100
for n=1 to 100
ink rgb(200+rnd(50),200+rnd(50),200),0
circle rnd(100),rnd(100),rnd(20)
next n
blur bitmap 1,3
get image surface,0,0,100,100
delete bitmap 1
 
numberofplanets=5
dim planet(numberofplanets)
dim planetmass#(numberofplanets)
for n=1 to numberofplanets
planet(n)=free_object()
make object sphere planet(n),12*cos(n*18)+2,20,20
 
texture object planet(n),surface
set object emissive planet(n),rgb(80+sin(n*30),20+cos(n*30),tan(n*30))
planetmass#(n)=object size x(planet(n))^3
position object planet(n),70*sin(n*23)-50,60*cos(n*15)-40,0
 
next n
 
ringsimage=free_entity()
create bitmap 1,600,600
ink 0,0
box 0,0,600,600
for n=1 to 200
ink rgb(200+rnd(50),200+rnd(50),200),0
circle 300,300,rnd(90)+210
next n
blur bitmap 1,3
get image ringsimage,0,0,600,600
delete bitmap 1
 
rings=free_object()
make object plain rings,20,20
set object light rings,0
texture object rings,ringsimage
n=2
set object emissive rings,rgb(80+sin(n*30),20+cos(n*30),tan(n*30))
set object transparency rings,5
set alpha mapping on rings,80
position object rings,70*sin(n*23)-50,60*cos(n*15)-40,0
rotate object rings,-90,60,-10
 
 
return
 
make_ship:
shipsurface=free_entity()
create bitmap 1,100,100
ink rgb(150,150,150),0
box 0,0,100,100
for n=1 to 100
ink rgb(200+rnd(50),200+rnd(50),250),0
circle rnd(100),rnd(100),rnd(20)
next n
get image shipsurface,0,0,100,100
delete bitmap 1
ship=free_object()
make object cone ship,1.2
texture object ship,shipsurface
set object light ship,0
return
 
controls:
 
if upkey()=1 and fuel#>0 and damage#<100 then thrust#=thrustvalue# else thrust#=0
if leftkey()=1 then dec angle#,angvel#*dt
if rightkey()=1 then inc angle#,angvel#*dt
 
return
 
physics:
 
totalgravx#=0
totalgravy#=0
 
for n=1 to numberofplanets
  dist#=sqrt((abs(object position x(ship)-object position x(planet(n)))^2)+(abs(object position y(ship)-object position y(planet(n)))^2))
  bearing#=atanfull(-object position x(planet(n))+object position x(ship),-object position y(planet(n))+object position y(ship))
  gravx#=gravityflag*(gravconst#*planetmass#(n)/(dist#^1.5))*sin(bearing#)
  gravy#=gravityflag*(gravconst#*planetmass#(n)/(dist#^1.5))*cos(bearing#)
  inc totalgravx#,gravx#
  inc totalgravy#,gravy#
next n
 
zrotate object ship,-angle#
 
thrusty#=thrust#*cos(angle#)
thrustx#=thrust#*sin(angle#)
 
forcey#=thrusty#-totalgravy#
forcex#=thrustx#-totalgravx#
 
accelerationx#=forcex#/mass#
accelerationy#=forcey#/mass#
 
inc velocityx#,accelerationx#*dt
inc velocityy#,accelerationy#*dt
inc x#,velocityx#*dt
inc y#,velocityy#*dt
 
speed#=sqrt(velocityx#^2+velocityy#^2)
 
if object screen x(ship)<0 then x#=-x#-1
if object screen x(ship)>screen width() then x#=-x#+1
if object screen y(ship)<0 then y#=-y#+1
if object screen y(ship)>screen height() then y#=-y#-1
position object ship,x#,y#,0
 
return
 
 
collision:
 
for n=1 to numberofplanets
collisiondist#=intersect object(planet(n),object position x(ship),object position y(ship),object position z(ship),object position x(planet(n)),object position y(planet(n)),object position z(planet(n)))
if collisiondist#=0 then collisiondist#=1000
if collisiondist#<object size x(ship)/2
  inc damage#,speed#*2000
  if n<>currentmoon then inc rating#,10/(speed#*2000):gosub messagecontent
  currentmoon=n
  gravityflag=0
  velocityx#=0
  velocityy#=0
  goto getoutofloop
else
  gravityflag=1
endif
next n
 
getoutofloop:
 
return
 
messagecontent:
 
if int(10/(speed#*2000))=0 then caption$="Crash landing!"
if int(10/(speed#*2000))=1 then caption$="Terrible landing!"
if int(10/(speed#*2000))=2 then caption$="Poor landing"
if int(10/(speed#*2000))=3 then caption$="Acceptable landing"
if int(10/(speed#*2000))=4 then caption$="Good landing"
if int(10/(speed#*2000))=5 then caption$="Excellent landing"
if int(10/(speed#*2000))>=6 then caption$="You are Buzz Aldrin!"
 
return
 
make_stars:
 
starimage=free_entity()
ink -1,0
create bitmap 1,600,600
for n=1 to 5000
dot rnd(600),rnd(600)
next n
get image starimage,0,0,600,600
delete bitmap 1
stars=free_object()
make object sphere stars,-1000
texture object stars,starimage
scale object texture stars,3,3
set object light stars,0
 
return
 
function free_object()
repeat
inc n
until object exist(n)=0
endfunction n
 
function free_entity()
repeat
inc n
until image exist(n)=0 and sprite exist(n)=0
endfunction n