set display mode 1024,768,32 sync on sync rate 0 autocam off make object cube 1,1 hide object 1 position object 1,0,0,5 global sw# global sh# sw#=screen width() sh#=screen height() color backdrop 0 hide mouse make_sound(1) make_sound(2) make_sound(3) make_sound(4) set camera to image 0,10,256,256 sprite 10,0,0,10 size sprite 10,sw#,sh# set sprite alpha 10,20 set sprite priority 10,1 set sprite 10,0,1 type lettertype angle as float x as float y as float vx as float vy as float endtype alphav#=0.05 shipa#=0.0001 shipmaxv#=0.2 shipang#=180 make_letter(1,"V") set sprite diffuse 1,0,255,0 size sprite 1,sprite width(1)/2.0,sprite height(1)/2.0 offset sprite 1,sprite width(1)/2.0,sprite height(1)/2.0 shipx#=sw#/2.0 shipy#=sh#/2.0 sprite 1,shipx#,shipy#,1 rotate sprite 1,shipang# bullet=100 bulletspeed#=0.2 make_letter(bullet,"o") set sprite diffuse bullet,255,0,0 size sprite bullet,sprite width(bullet)/4.0,sprite height(bullet)/4.0 offset sprite bullet,sprite width(bullet)/2.0,sprite height(bullet)/2.0 hide sprite bullet dim letter(90) as lettertype for ascii=65 to 90 make_letter(ascii,chr$(ascii)) letter(ascii).x=100+rnd(sw#-200) letter(ascii).y=100+rnd(sh#-200) sprite ascii,letter(ascii).x,letter(ascii).y,ascii offset sprite ascii,sprite width(ascii)/2.0,sprite height(ascii)/2.0 letter(ascii).angle=rnd(360) next ascii dim targetactive(90) for target=65 to 90 targetactive(target)=1 next target set text size 20 ink rgb(0,255,0),0 shield#=500 lives=5 set sprite diffuse 1,250,128,0 st#=timer() do t#=timer()-st# dt#=t#-ot# ot#=t# gosub move_letters gosub move_ship gosub fire gosub ship_collision gosub bullet_collision `text 0,0,str$(screen fps()) text 0,20,"Score: "+str$(score) text 0,40,"Lives: "+str$(lives) sync loop fire: if spacekey()=1 and spacekeydown=0 and firing=0 spacekeydown=1 show sprite bullet sprite bullet,sprite x(1),sprite y(1),bullet rotate sprite bullet,shipang# firing=1 play sound 1 endif if firing=1 move sprite bullet,-bulletspeed#*dt# if sprite x(bullet)<0 or sprite x(bullet)>sw# or sprite y(bullet)<0 or sprite y(bullet)>sh# hide sprite bullet firing=0 endif endif if spacekey()=0 and spacekeydown=1 then spacekeydown=0 return bullet_collision: for target=65 to 90 if sprite visible(target)=1 and sprite visible(bullet)=1 if sprite collision(bullet,target)=1 hide sprite target inc hits play sound 2 highertargetactive=0 if target<90 for check=target+1 to 90 if targetactive(check)=1 then highertargetactive=1:exit next check endif if highertargetactive=1 then inc score,1 else inc score,10 targetactive(target)=0 hide sprite bullet firing=0 if hits=26 for n=65 to 90 show sprite n targetactive(n)=1 next n inc alphav#,0.025 shield#=500 set sprite diffuse 1,255,128,0 hits=0 endif endif endif next target return ship_collision: for target=65 to 90 if sprite visible(target)=1 and shield#=0 if sprite collision(1,target)=1 hide sprite 1 set sprite diffuse 1,255,128,0 dec lives play sound 3 if lives<0 then gosub game_over shield#=500 endif endif next target if shield#>0 then dec shield#,0.1*dt# if shield#>0 and shield#<250 and ready=0 ready=1 show sprite 1 shipx#=sw#/2.0 shipy#=sh#/2.0 shipvx#=0 shipvy#=0 sprite 1,shipx#,shipy#,1 endif if shield#<0 shield#=0 set sprite diffuse 1,0,255,0 ready=0 endif return game_over: cls text$="Game Over! You scored "+str$(score)+" points." text sw#/2.0-text width(text$)/2.0,sh#/2.0,text$ sync wait 500 wait key end return move_ship: if rightkey()=1 then inc shipang#,0.1*dt#:rotate sprite 1,shipang# if leftkey()=1 then dec shipang#,0.1*dt#:rotate sprite 1,shipang# if upkey()=1 inc shipvx#,shipa#*sin(shipang#+180)*dt# inc shipvy#,shipa#*cos(shipang#)*dt# endif if shipvx#>shipmaxv# then shipvx#=shipmaxv# if shipvy#>shipmaxv# then shipvy#=shipmaxv# if shipvx#<-shipmaxv# then shipvx#=-shipmaxv# if shipvy#<-shipmaxv# then shipvy#=-shipmaxv# inc shipx#,shipvx#*dt# inc shipy#,shipvy#*dt# if shipx#>sw#-sprite width(1) then dec shipx#,sw#-sprite width(1) if shipy#>sh#-sprite height(1) then dec shipy#,sh#-sprite height(1) if shipx#<0 then inc shipx#,sw#-sprite width(1) if shipy#<0 then inc shipy#,sh#-sprite height(1) sprite 1,shipx#,shipy#,1 return move_letters: for ascii=65 to 90 letter(ascii).vx=alphav#*sin(letter(ascii).angle) letter(ascii).vy=alphav#*cos(letter(ascii).angle) inc letter(ascii).x,letter(ascii).vx*dt# inc letter(ascii).y,letter(ascii).vy*dt# if letter(ascii).x>sw#-sprite width(ascii) or letter(ascii).x<0 then letter(ascii).angle=-letter(ascii).angle if letter(ascii).y>sh#-sprite height(ascii) or letter(ascii).y<0 then letter(ascii).angle=-(letter(ascii).angle-180) sprite ascii,letter(ascii).x,letter(ascii).y,ascii next ascii return function alpha(image,red,green,blue) `this is for converting an image with no alpha layer into a monochrome image with alpha layer created from rgb values. `image: image number `red, gree, blue: the single colour the final image will be memblock=1 make memblock from image memblock,image sx=memblock dword(memblock,0) sy=memblock dword(memblock,4) for x=0 to sx-1 for y=0 to sy-1 pos=(y*sx+x)*4+12 b=memblock byte(memblock,pos) g=memblock byte(memblock,pos+1) r=memblock byte(memblock,pos+2) a=int((b+g+r)/3.0) b=blue g=green r=red if a>255 then a=255 if a<0 then a=0 write memblock byte memblock,pos,b write memblock byte memblock,pos+1,g write memblock byte memblock,pos+2,r write memblock byte memblock,pos+3,a next y next x make image from memblock image,memblock endfunction function make_letter(spritenumber,letter$) ink -1,0 set text size 100 set text font "Arial" set text to bold create bitmap 1,text width(letter$),text height(letter$) text 0,0,letter$ blur bitmap 1,2 get image spritenumber,0,0,text width(letter$),text height(letter$) sprite spritenumber,sw#,sh#,spritenumber size sprite spritenumber,sprite width(spritenumber)/2.0,sprite height(spritenumber)/2.0 cls paste sprite spritenumber,0,0 get image spritenumber,0,0,sprite width(spritenumber),sprite height(spritenumber),1 alpha(spritenumber,255,255,255) delete bitmap 1 delete sprite spritenumber sprite spritenumber,0,0,spritenumber `set sprite alpha spritenumber,150 set sprite diffuse spritenumber,0,0,rnd(150)+100 endfunction function make_sound(number) format as dword channels as dword sampleRate as dword adr as dword chunkSize as dword sampleSize as dword dword7 as dword format = 1 channels = 1 sampleRate = 22050 sampleSize = 16 chunkSize = (int(sampleSize / 8.0+0.5))*channels adr = sampleRate*chunkSize dword7 = 0 rem ################################### rem Use a select-case statement so you can create multiple sounds rem Just add a new case statement for each sound number you want to create select number case 1 rem ########################################################## rem Adjust these values to get different sounds rem Very minor adjustments will create very different sounds length = 100 wave#=0 increment#=25.0 gain#=0.01 amplitude=25535 decay=10 rem ######################################################### speed=sampleRate endcase case 2 rem ########################################################## rem Adjust these values to get different sounds rem Very minor adjustments will create very different sounds length = 200 wave#=0 increment#=5.0 gain#=-0.1 amplitude=25535 decay=8 rem ######################################################### speed=sampleRate endcase case 3 rem ########################################################## rem Adjust these values to get different sounds rem Very minor adjustments will create very different sounds length = 800 wave#=0 increment#=10.0 gain#=0.05 amplitude=25535 decay=5 rem ######################################################### speed=sampleRate endcase case 4 rem ########################################################## rem Adjust these values to get different sounds rem Very minor adjustments will create very different sounds length = 400 wave#=0 increment#=30.0 gain#=-10.0 amplitude=8000 decay=2 rem ######################################################### speed=sampleRate endcase endselect rem number of samples samples = length*sampleRate/1000 rem size of memblock size = samples*int(sampleSize/8.0+0.5) + 28 make memblock 1, size write memblock dword 1, 0, format write memblock dword 1, 4, channels write memblock dword 1, 8, sampleRate write memblock dword 1, 12, adr write memblock dword 1, 16, chunkSize write memblock dword 1, 20, sampleSize write memblock dword 1, 24, dword7 pos = 28 out as word for i = 1 to samples out = sin(wave#)*amplitude write memblock word 1, pos, out inc pos, 2 wave#=wave#+increment# if wave#>360.0 wave#=wave#-360.0 increment#=increment#-gain# endif amplitude=amplitude-decay if amplitude<0 then amplitude=0 next i make sound from memblock number,1 delete memblock 1 set sound speed number,speed endfunction