Rem Project: sidescroller challenge
Rem Created: 19/02/2005 21:17:23
 
Rem ***** Main Source File *****
 
randomize timer()
 
`display
if check display mode(1024,768,32)=1 then set display mode 1024,768,32
hide mouse
autocam off
set camera range 1,10000
position camera 200,0,280
point camera 0,0,280
hide light 0
color backdrop rgb(0,0,0)
set ambient light 80
make light 1
position light 1,100,100,20
set light range 1,100000
color light 1,rgb(255,220,180)
set text font "sf automaton_mod"
set text size 25
fog on
fog distance 3500
 
`create green texture
for x=0 to 100
   for y=0 to 100
      ink rgb(0,x+y,0),0
      dot x,y
   next y
next x
get image 103,0,0,100,100
 
`create orange texture
cls
for x=0 to 100
   for y=0 to 100
      ink rgb((x+y)+50,50+(x+y)/1.5,100),0
      dot x,y
   next y
next x
get image 102,0,0,100,100
 
`create blue texture
cls
for x=0 to 100
   for y=0 to 100
      ink rgb(0,0,x+y),0
      dot x,y
   next y
next x
get image 101,0,0,100,100
 
`create red texture
cls
for x=0 to 100
   for y=0 to 100
      ink rgb((x+y)+50,0,0),0
      dot x,y
   next y
next x
get image 105,0,0,100,100
 
`create star texture
cls
for x=0 to 100
for y=0 to 100
d=rnd(20)
ink rgb(100+rnd(100),100+rnd(100),rnd(100)+100),0
if d=1 then dot x,y
next y
next x
get image 1,0,0,100,100
 
`create tile texture
cls
ink rgb(0,255,0),0
box 0,0,20,20
ink rgb(0,0,0),0
box 1,1,20,20
`ink rgb(0,0,155),0
`box 4,4,16,16
get image 2,0,0,20,20
 
 
 
 
`create stars
make object plain 1000,10600,8000
texture object 1000,1
scale object texture 1000,5,5
set object transparency 1000,1
yrotate object 1000,90
position object 1000,-4000,0,0
set object light 1000,0
set object emissive 1000,rgb(250,250,250)
set object fog 1000,0
 
make object plain 1001,10600,8000
texture object 1001,1
scale object texture 1001,5,5
set object transparency 1001,1
yrotate object 1001,90
position object 1001,-4010,0,0
set object light 1001,0
set object emissive 1001,rgb(250,250,250)
set object fog 1001,0
 
 
 
make object sphere 8888,0.1
make mesh from object 1,8888
delete object 8888
 
`aliens and fuel pods
dim azspeed#(5025)
dim ayspeed#(5025)
dim fuel(5025)
for alien=5000 to 5025
if alien>5020 then fuel(alien)=1
if fuel(alien)=0
  make object sphere alien,15,2,2
  texture object alien,105
  make object cone alien+50000,10
  scale object alien+50000,100,200,100
  texture object alien+50000,102
  add limb alien,1,1
  glue object to limb alien+50000,alien,1
else
  make object sphere alien,15,30,30
  texture object alien,103
endif
set object specular alien,rgb(200,200,200)
set object specular power alien,15
set object emissive alien,rgb(150,150,100)
set object ambient alien,0
set object collision on alien
set object fog alien,0
position object alien,-180,rnd(200)-100,rnd(2000)+500
next alien
 
 
 
`bottom wall
make object plain 4,3000,3000
xrotate object 4,90
set object collision on 4
texture object 4,2
scale object texture 4,20,10
set object transparency 4,1
 
`ghost object on 4
 
`top wall
make object plain 5,3000,3000
xrotate object 5,90
set object collision on 5
texture object 5,2
scale object texture 5,20,10
set object transparency 5,1
`ghost object on 5
 
 
`position walls
position object 4,0,-150,100
position object 5,0,150,100
 
`spaceship
make object cone 1,20
xrotate object 1,90
scale object 1,100,400,100
ghost object on 1
texture object 1,101
set object emissive 1,rgb(200,200,200)
set object specular 1,rgb(250,250,250)
set object specular power 1,10
set object fog 1,0
set object collision on 1
set object collision to boxes 1
 
`jet trail
make object sphere 777,-50,30,30
scale object 777,100,100,1500
texture object 777,102
ghost object on 777
set object emissive 777,rgb(200,200,200)
set object specular 777,rgb(250,250,250)
set object specular power 777,10
position object 777,1000,0,0
disable object zdepth 777
 
`reflection of ship
clone object 302,1 `top
xrotate object 302,90
scale object 302,100,400,100
fade object 302,90
clone object 303,1 `bottom
xrotate object 303,90
scale object 303,100,400,100
fade object 303,90
clone object 888,777
fade object 888,90
scale object 888,100,100,1500
position object 888,1000,0,0
clone object 999,777
fade object 999,90
scale object 999,100,100,1500
position object 999,1000,0,0
ink rgb(0,0,255),0
 
`vapour
make object sphere 111,-80,30,30
scale object 111,500,100,1560
texture object 111,101
ghost object on 111
set object emissive 111,rgb(200,200,200)
set object specular 111,rgb(250,250,250)
set object specular power 111,30
position object 111,0,0,350
 
createsound("laser",1,1500,700,8000,0.01,0.2)
createsound("explosion",2,6200,700,2000,20,0.2)
createsound("explosion2",3,1200,1400,3000,10,0.1)
createsound("fuelup",4,800,700,8000,-0.02,0.2)
createsound("fuelwarning",5,800,1000,6000,0.5,0.1)
 
restart:
 
cls
value#=0.1
fuel#=3.0
lives=3
pz#=150
aliens=40
level=1
scrollspeed#=0.08
 
for alien=5000 to 5025
azspeed#(alien)=1+rnd(10)
ayspeed#(alien)=rnd(20)/10.0
next alien
 
while mouseclick()=0
text screen width()/2-220,210,"Kill 40 aliens before your fuel runs out!"
text screen width()/2-70,240,"Press FIRE!"
endwhile
 
sync on
sync rate 30
 
do
 
text 0,40,str$(screen fps())
 
 
 
py#=py#-mousemovey()
pz#=pz#+mousemovex()
if py#>110 then py#=110
if py#<-110 then py#=-110
if pz#>500 then pz#=500
if pz#<0 then pz#=0
 
`move ship
position object 1,-180,py#,pz#
position object 302,-180,-py#-300,pz#
position object 303,-180,-py#+300,pz#
position object 777,-180,py#,pz#-380
position object 888,-180,-py#-300,pz#-380
position object 999,-180,-py#+300,pz#-380
 
`scroll textures
scroll object texture 1000,0.01,0
scroll object texture 1001,0.008,0
scroll object texture 4,0,scrollspeed#
scroll object texture 5,0,scrollspeed#
scroll object texture 777,-scrollspeed#/6,0
if level>2 then scroll object texture 111,0.01,0.01
 
`handle aliens
for alien=5000 to 5025
`alien movement
ay#=object position y(alien)+ayspeed#(alien)
az#=object position z(alien)-azspeed#(alien)
if ay#>100 or ay#<-100 then ayspeed#(alien)=ayspeed#(alien)*-1
if az#<object position z(1)-300 then inc az#,2000
 
`alien death
if fire=1
if object in screen (alien)=1
 if object position y(1)<object position y(alien)+8 and object position y(1)>object position y(alien)-8
   inc az#,2000
   play sound 2
   dec aliens
  endif
endif
endif
 
`ship death
if object in screen(alien)=1
  if object position y(1)<object position y(alien)+8 and object position y(1)>object position y(alien)-8
    if object position z(1)<object position z(alien)+50 and object position z(1)>object position z(alien)-30
      inc az#,2000
      if fuel(alien)=0
           dec lives
           play sound 3
           if lives<0 then goto dead
           text screen width()/2-70,240,"GET READY!"
           wait 1000
      endif
      if fuel(alien)=1 then inc fuel#
      play sound 4
    endif
  endif
endif
 
position object alien,-180,ay#,az#
turn object left alien,10
next alien
 
`fire
if mouseclick()=1 and charge<0
  fire=1
  charge=20
  length=5
endif
 
if fire=1
play sound 1
line object screen x(1),object screen y(1),screen width(),object screen y(1)
endif
 
dec charge
dec length
if length<0 then fire=0
 
`text
 
text 40,0,"Lives: "+str$(lives)
if fuel#<1.0
   fuelwarning=1
   ink rgb(255,0,0),0
endif
if fuelwarning=1 and warningon=0 then play sound 5:warningon=1
text screen width()-130,0,"Fuel: "+left$(str$(fuel#),4)
ink rgb(0,0,255),0
text screen width()/2-60,0,"Aliens: "+str$(aliens)
if fuel#>1 then fuelwarning=0:warningon=0
 
dec fuel#,0.005
 
if fuel#<0
   play sound 3
   text screen width()/2-70,210,"Out of fuel!"
   text screen width()/2-70,240,"GET READY..."
   sync
   wait 1000
  dec lives
  fuel#=3.0
endif
 
if aliens<1
  inc level
  text screen width()/2-70,210,"Level "+str$(level)
  text screen width()/2-70,240,"GET READY..."
  sync
  wait 1000
  aliens=40
  inc scrollspeed#,0.02
  fuel#=3.0
  for alien=5000 to 5025
    inc azspeed#(alien),3
    inc ayspeed#(alien),0.2
  next alien
endif
 
if level>1
position camera 200,ht#,280+ht#
point camera 0,0,280
ht#=30*sin(theta#)
theta#=wrapvalue(theta#)+0.8
endif
 
dead:
if lives<0
 
  text screen width()/2-70,240,"GAME OVER!"
  text screen width()/2-120,270,"You got to level "+str$(level)
  sync
  wait 3000
  while mouseclick()=0
  text screen width()/2-90,320,"Press fire ...."
  sync
endwhile
  goto restart
endif
 
sync
loop
 
function createsound(name$,soundnumber,frequency#,length#,loudness#,bend#,decay#)
 
if file exist(name$+".wav")=1 then delete file name$+".wav"
open to write 1,name$+".wav"
chunk=int(((length#/1000)*44100*16)/8) `sample size (no of samples * bitrate * channels / 8)
samples=int((length#/1000)*44100) `length *44100
restore
for x=1 to 40
   read byte2
   write byte 1, byte2
next x
write long 1,chunk
rem generate and write wave
for x=1 to samples
  output#=int(sin((x/122.5)*frequency#)*loudness#)*3.0
  dec frequency#,bend#
  if loudness#>0 then dec loudness#,decay#
  write word 1,output#
next x
close file 1
 
load sound name$+".wav",soundnumber
 
data 82:data 73:data 70:data 70:data 208:data 59:data 1:data 0:data 87
data 65:data 86:data 69:data 102:data 109:data 116:data 32:data 16
data 0:data 0:data 0:data 1:data 0:data 2:data 0:data 34:data 86:data 0
data 0:data 136:data 88:data 1:data 0:data 4:data 0:data 16:data 0
data 100:data 97:data 116:data 97
 
endfunction