ACE Gunner by HowDo23rd Dec 2004 10:52
|
---|
Summary Simple Game that uses joystick, collision, texture and sound commands. Description Simple shoot em up game, you at the tail end of the mother ship and you have to stop the other ships from passing you, it show you how to use a joystick with a sprite and detech a 3D object. Also how to load in a texture and show it on the cube, plus loading in sound to go off when the fire button is pressed on the joystick. Code ` This code was downloaded from The Game Creators ` It is reproduced here with full permission ` http://www.thegamecreators.com Rem Project: starflied5 Rem Created: 20/12/2004 16:45:34 Rem ***** Main Source File ***** sync on autocam off hide mouse color backdrop 0 rem Prepare Force Feedback (if available) ForcePresent=0 empty checklist PERFORM CHECKLIST FOR CONTROL DEVICES for c=1 to checklist quantity() if checklist value a(c)=1 SET CONTROL DEVICE checklist string$(c) ForcePresent=1 endif next c rem Load images set image colorkey 255,0,255 load image "crosshair.bmp",1 `load image "C:\Program Files\Dark Basic Software\Dark Basic Professional\Help\examples\input\crosshair.bmp",1 load image "Metal_Plates_T.BMP",2 rem Setup crosshair sprite rem load sound load sound "Ray gun.wav",1,0 for t=2 to 10 clone sound t,1 next t set current bitmap 0 set sprite 1,0,1 offset sprite 1,16,16 rem Particle effect setup autocam off rem Set start pos posx#=320 posy#=240 global stars=200,ship=0,mb#=10.0,score=0,shipassed=0,tv,show Dim star_ang#(stars) Dim star_rad#(stars) Dim star_spd#(stars) dim ship_ang#(ship) dim ship_rad#(ship) dim ship_spd#(ship) dim ship_zis#(ship) sw=screen width() sh=screen height() show=0 rem make stars for st=0 to stars star_ang#(st)=rnd(36000)/100.00 star_rad#(st)=rnd(sw/2) star_spd#(st)=0.5+abs(sin(rnd(360))) next st `make ships numberofships=rnd(10)+1 dim shipspeed#(numberofships) for ship=1 to numberofships make object cube ship,1 TEXTURE OBJECT ship,2 shipspeed#(ship)=rnd(20)/70+1 position object ship,rnd(20)-10,rnd(20)-10,rnd(500) next ship rem Position crosshair sprite 1,posx,posy,1 do rem Read joystick posx#=posx#+(joystick x()/128.0) posy#=posy#+(joystick y()/128.0) `posx#=posx#+joystick x() `posy#=posy#+joystick y() posx=posx# : posy=posy# fire=joystick fire a() if show=0 set text size 70 center text sw/2,sh/2-150,"ACE" center text sw/2,sh/2-50,"Gunner" set text size 12 center text sw/2,sh/2+75,"Press SpaceBar to Start" if keystate(57) cls shipassed=0:show=1 for hd = 1 to numberships show object hd next hd endif endif rem Position crosshair and scores sprite 1,posx,posy,1 text 0,0,"Score "+str$(score)+" " tv=len("Ship Passed "+str$(shipassed)+" ") text sw-(8*tv),0,"Ship Passed "+str$(shipassed)+" " `move ships if show<>0 if shipassed<>50 for ship=1 to numberofships move object ship,-shipspeed#(ship) if object position z(ship)<0 then position object ship,rnd(20)-10,rnd(20)-10,500:inc shipassed next ship endif rem stop if ship passed = if shipassed>=50 for hd=1 to numberships hide object hd next center text sw/2,sh/2,"GAME OVER" center text sw/2,sh/2+50,"You Scored "+str$(score)+" this time round." center text sw/2,sh/2+100,"Press Space Bar to Start Again" endif rem start again if keystate(57) cls shipassed=0 for hd = 1 to numberships show object hd next hd endif rem Make bullet hole if triggered if fire=1 and cool=0 cool=10 for t=1 to 10 if sound playing(t)=0 then play sound t: t=11 next t if ForcePresent=1 then force shoot 100,100 if laser>5 then laser=0 endif if cool>0 then dec cool rem laser ines if laser=0 line 0,sh/2,posx,posy line sw,sh/2,posx,posy endif rem get object number of 3d object at 2d coordinates object=pick object(posx,posy,1,numberofships) if object>0 rem get distance from 3d object to coordinates distance=get pick distance() if distance<200 then hide object object :score=score+20:position object object,rnd(20)-10,rnd(20)-10,500:show object object endif endif inc laser rem show stars for st=0 to stars star_rad#(st)=star_rad#(st)-star_spd#(st) if star_rad#(st)<0 then star_rad#(st)=star_rad#(st)+sw/2 px=sw/2+(sin(star_ang#(st))*star_rad#(st)) py=sh/2+(cos(star_ang#(st))*star_rad#(st)) pc=(star_rad#(st))+55 if pc>255 then pc=255 dot px,py,rgb(pc,pc,pc) next st rem update sync loop |