2d side shooter by hockey stevie10th Dec 2005 5:19
|
---|
Summary A simple 2d side shooter I wrote up, wip This was written on 5.3 trial version as my version is locked on my hd on a non working computer, and my cd is too damaged to instal :( but Description This is a short 2d side shooter 'game' I wrote, it started as a bunch of bouncing cubes and turned into this. It only has 1 collidable plane so you cant add any platforms or terrain, its pretty limited and has a lot of bugs because of the way I made the controls but might be fun to mess around with. Code ` This code was downloaded from The Game Creators ` It is reproduced here with full permission ` http://www.thegamecreators.com REM Project: test REM Created: 12/8/2005 2:25:53 PM REM REM ***** Main Source File ***** REM set display mode 1280,1024,32 randomize timer() type physBox x as float y as float xvel as float yvel as float xr as float yr as float width as float height as float mass as float bounce as float color as dword endtype type physBullet x as float y as float xvel as float yvel as float ang as float xr as float yr as float size as float mass as float bounce as float color as dword decay as float damage as float grenade as boolean endtype type physLine x as float y as float xvel as float yvel as float ang as float xr as float yr as float size as float mass as float bounce as float color as dword decay as float damage as float endtype type explosion x as integer y as integer radius as float damage as float shakeamt as float health as float endtype set text opaque set text size 32 set text to bold center text screen width()*0.5,screen height()*0.1,"Gravity Demo" center text screen width()*0.5,screen height()*0.1 +text height("X")+2,"lol" set text size 16 set text to normal wait 500 load image "barrel.bmp",10,1 if spacekey() then gosub demo gosub game game: gosub setupWorld gosub setupExplosions cls print "CRAZY SUPER AK47 MONKEY HUNTER V0.2!!!111!" wait 1500 print "" print "" print "HUNT DA MONKEYS" wait 500 cls playerScale# = 2.0 addBarrel(screen width()*0.2,groundHeight-16*playerScale#*0.5,10*playerScale#,playerScale#,0.35) colorBarrel(1,0,255,0) load image "bg1.bmp",1,1 load image "crapak47.bmp",2,1 load image "mf1.bmp",3,1 load sound "ak47.wav",1 load sound "explode.wav",2 dim health(32) as float roundsPerSec as float aimAng# = 0.0 handLength# = 5.0 roundsPerSec = 10 ammoClip = 30 clipCap = 30 ammoPack = 120 ammoPCap = 240 gunDec# = 0.5 gunScl# = 0.5 gunSpd# = 110.0 gunSmax = 15 grenMode = 0 explsize# = 1.0 sprite 1,0,0,2 sprite 2,0,0,3 open to read 1,"sak47.wep" read string 1,name$ read float 1,rec# read float 1,dmg# read float 1,roundsPerSec read word 1,amcmax read word 1,ampmax read float 1,setx# read float 1,sety# read float 1,mfx# read float 1,mfy# close file 1 offset sprite 1,setx#*-1,sety#*-1 lastshot = timer() lasttime = timer() hide mouse do if shiftkey() AND keystate(9) then roundsPerSec=1000 if shiftkey() and keystate(8) then roundsPerSec=1 : gunDec# = 1.0 : gunSpd# = 15 : gunSmax = 3 if shiftkey() and keystate(6) then grenMode = 1 if shiftkey() and keystate(5) then grenMode = 0 if shiftkey() and keystate(7) then roundsPerSec=10 : gunDec# = 0.5 : gunSpd# = 110 : gunSmax = 15 if shiftkey() and keystate(10) then explsize# = 5.0 if shiftkey() and keystate(11) then explsize# = 0.25 if shiftkey() and keystate(12) then explsize# = 1.0 if shiftkey() and keystate(2) input "Gun Decay: ",gunDec# input "Gun Speed: ",gunSpd# input "Gun SMax: ",gunSmax input "RPS: ",roundsPerSec lasttime = timer() endif cls paste image 1,0,0 gosub updatePhys if sprite exist(2) then delete sprite 2 aimAng# = atanfull(mousex()-physBox(1).x,mousey()-physBox(1).y) gunRot# = atanfull(mousey()-physBox(1).y,mousex()-physBox(1).x) if leftkey() then addForce(1,270,6*time#) if rightkey() then addForce(1,90,6*time#) if keystate(4) then explode(screen width()*0.5,screen height()*0.5,1.0,50.0) if spacekey() if jump=0 jump=1 addForce(1,180,10) endif else jump = 0 endif if mouseClick()=1 if (timer() - lastshot)/1000.0 >= 1.0/roundsPerSec b = shootBullet(sin(aimAng#)*(handLength#+58*gunScl#)+physBox(1).x,cos(aimAng#)*(handLength#+58*gunScl#)+physBox(1).y,aimAng#,gunSpd#+rnd(gunSmax),gunDec#,20) if grenMode=1 colorBullet(b,0,255,0) setBulletExplosive(b,explsize#,50.0*explsize#) else colorBullet(b,255,255,0) endif stop sound 1 play sound 1 if flippedGun=0 sprite 2,sprite x(1)+sin(-sprite angle(1)+(100))*(54*gunScl#+setx#),sprite y(1)+cos(-sprite angle(1)+(100))*(54*gunScl#+setx#),3 else sprite 2,sprite x(1)+sin(-sprite angle(1)+(90))*(54*gunScl#+setx#),sprite y(1)+cos(-sprite angle(1)+(90))*(54*gunScl#+setx#),3 endif scale sprite 2,gunScl# * 100 set sprite priority 2,1 rotate sprite 2,gunRot# lastshot = timer() endif endif sprite 1,sin(aimAng#)*handLength#+physBox(1).x,cos(aimAng#)*handLength#+physBox(1).y,2 scale sprite 1,gunScl#*100 if aimAng# < 0 if flippedGun = 0 flippedGun = 1 flip sprite 1 endif else if flippedGun=1 flip sprite 1 flippedGun=0 endif endif crosshair(sprite x(1),sprite y(1),6) crosshair(mousex(),mousey(),8) rotate sprite 1,gunRot# text 0,0,str$((timer() - lastshot)/1000.0)+"/"+str$(1/roundsPerSec)+" - "+str$(timer() - lastshot) loop show mouse return demo: input "Min: ",boxmin input "Max: ",boxmax gosub setupWorld playerScale# = 25.0 addBarrel(screen width()*0.5,groundHeight-16*playerScale#*0.5,10*playerScale#,playerScale#,0.75) colorBarrel(1,255,0,0) for r = 2 to rnd(boxmax-boxmin)+boxmin bnc# = (rnd(75)+20)/100.0 addBarrel(rnd(screen width()*0.9)+rnd(screen width()*0.05),rnd(screen height()*0.75)-20,10.0,(rnd(100)+150)/100,bnc#) colorBarrel(r,rnd(255),rnd(255),rnd(255)) addForce(r,rnd(3600)/10,rnd(100)/10) next r for b = 1 to 20 shootBullet(2,rnd(screen height()*0.75)+5,rnd(90)+45,rnd(35)+10,(rnd(20)+80)/100,20) next b do cls gosub updatePhys if spacekey() then shootBullet(2,screen height()*0.5,rnd(90)+45,rnd(25)+10,1,20) if leftkey() then addForce(1,270,0.75) if rightkey() then addForce(1,90,0.75) if upkey() if jump=0 jump=1 addForce(1,180,10) endif else jump = 0 endif if keystate(16) then dec worldGravY#,0.2 if keystate(30) then inc worldGravY#,0.2 if keystate(17) then dec worldGravX#,0.2 if keystate(31) then inc worldGravX#,0.2 if scancode() then text screen width()-100,5,str$(scancode()) loop return setupExplosions: dim Explosions() as explosion bigFrames = 20 smlFrames = 21 for i = 0 to bigFrames-1 load image "explodebig/screen"+str$(i)+".bmp",20+i,1 next i for i = 0 to smlFrames-1 load image "explodesml/screen"+str$(i)+".bmp",50+i,1 next i return setupWorld: gosub startPhys groundHeight = screen height()*0.95 line 0,groundHeight,screen width(),groundHeight return startPhys: Friction# = 10 timescale# = 2 worldGravY# = 9.8 worldGravX# = 0 lasttime = timer() dim physBox() as physBox dim physBullet() as physBullet dim physLine() as physLine return updatePhys: time# = ((timer()-lasttime)/1000.0)*timescale# lasttime = timer() for i = 0 to array count(physBox()) if physBox(i).y <= groundHeight - 1 then inc physBox(i).yvel,worldGravY#*time# inc physBox(i).xvel,worldGravX#*time# if physBox(i).y + physBox(i).yvel >= groundHeight - physBox(i).height*0.5 physBox(i).yvel = physBox(i).yvel * (-1*physBox(i).bounce) physBox(i).xvel = curvevalue(0,physBox(i).xvel,1*Friction#) if physBox(i).yvel > -1.5 and physbox(i).yvel < 1.5 then physbox(i).yvel = 0 endif if physBox(i).x + physBox(i).xvel < physBox(i).width*0.5 OR physBox(i).x + physBox(i).xvel > screen width() - physBox(i).width*0.5 physBox(i).xvel = physBox(i).xvel * (-1*physBox(i).bounce) endif inc physBox(i).x,physBox(i).xvel inc physBox(i).y,physBox(i).yvel text 5,5,"Timescale: "+str$(time#) text 5,40,str$(physBox(i).x)+","+str$(physBox(i).y) text 5,75,str$(physBox(i).xvel)+","+str$(physBox(i).yvel) next i for b = 1 to array count(physBullet()) del = 0 if physBullet(b).y <= groundHeight - 1 inc physBullet(b).yvel,(worldGravY#*time#)*physBullet(b).decay else if physBullet(b).grenade = 1 ammmt# = ((rnd(900)+400)/100) * physBullet(b).size bloodSquirt(physBullet(b).x,groundHeight,180,ammmt#,((rnd(800)+400)/100)*physBullet(b).size,rgb(128,128,0)) explode(physBullet(b).x,groundHeight,physBullet(b).size,physBullet(b).damage) array delete element physBullet(),b del = 1 else ammmt# = (rnd(200)+200)/100 bloodSquirt(physBullet(b).x,groundHeight,180,ammmt#,((rnd(400)+500)/100)*(((physBullet(b).xvel+physBullet(b).yvel)/2.0)/20),rgb(128,128,0)) array delete element physBullet(),b del = 1 endif endif if del=0 inc physBullet(b).xvel,(worldGravX# * time#) * physBullet(b).decay inc physBullet(b).x,physBullet(b).xvel inc physBullet(b).y,physBullet(b).yvel if (physBullet(b).x >= screen width()+50 OR physBullet(b).x <= -50) OR (physbullet(b).y >= screen height()+50 OR physBullet(b).y <= -50) then array delete element physBullet(),b endif next b for l = 1 to array count(physLine()) inc physLine(l).yvel,(worldGravY#*time#)*physLine(l).decay inc physLine(l).xvel,(worldGravX# * time#) * physLine(l).decay inc physLine(l).x,physLine(l).xvel inc physLine(l).y,physLine(l).yvel if (physLine(l).x >= screen width()+50 OR physLine(l).x <= -50) OR (physLine(l).y >= screen height()+50 OR physLine(l).y <= -50) then array delete element physLine(),l next l for e = 0 to 25 if sprite exist(20+e) then delete sprite 20+e next e for e = 0 to array count(explosions()) if explosions(e).health = 100 for i = 1 to array count(physBox()) dist# = sqrt((explosions(e).x - physBox(i).x)^2 + (explosions(e).y - physBox(i).y)^2) if dist# <= explosions(e).radius*4 addForce(i,-atanfull(explosions(e).x - physBox(i).x,physBox(i).y - explosions(e).y),20/dist#*explosions(e).damage) `hurt for same amt endif next i endif if sprite exist(20+e) then delete sprite 20+e if explosions(e).radius <= 40 frameNo = bigFrames - (explosions(e).health/100*bigFrames) sprite 20+e,explosions(e).x-explosions(e).radius,explosions(e).y-explosions(e).radius,50+frameNo size sprite 20+e,explosions(e).radius*2,explosions(e).radius*2 isbig=1 if frameNo >= bigframes - 4 then delete sprite 20+e else frameNo = smlFrames - (explosions(e).health/100*smlFrames) sprite 20+e,explosions(e).x-explosions(e).radius,explosions(e).y-explosions(e).radius,20+frameNo size sprite 20+e,explosions(e).radius*2,explosions(e).radius*2 isbig=0 if frameNo >= bigframes - 4 then delete sprite 20+e endif dec explosions(e).health,time#*60 if explosions(e).health <= 0 if sprite exist(20+e) then delete sprite 20+e array delete element explosions(),e endif next e gosub drawBoxes return drawBoxes: line screen width()*0.5,screen height()*0.5,screen width()*0.5+worldGravX#,screen height()*0.5+worldGravY# for b = 1 to array count(physBox()) center text physBox(b).x,physBox(b).y - physBox(b).height * 0.5 - text height("X") - 4,str$(b) sprite 10+b,physBox(b).x-physBox(b).width*0.5,physBox(b).y-physBox(b).height*0.5,10 size sprite 10+b,physBox(b).width,physBox(b).height next b for b = 1 to array count(physBullet()) length# = (((abs(physBullet(b).xvel) + abs(physBullet(b).yvel))/2)/2.5)*5 ink physBullet(b).color,0 if length# < 1 then length# = 1 ang = atanfull(physBullet(b).x - (physBullet(b).x+physBullet(b).xvel),physBullet(b).y - (physBullet(b).y+physBullet(b).yvel)) line sin(ang)*(length#*-0.5)+physBullet(b).x,cos(ang)*(length#*-0.5)+physBullet(b).y,sin(ang)*(length#*0.5)+physBullet(b).x,cos(ang)*(length#*0.5)+physBullet(b).y next b for b = 1 to array count(physLine()) length# = (((abs(physLine(b).xvel) + abs(physLine(b).yvel))/2)/2.5)*5 ink physLine(b).color,0 if length# < 1 then length# = 1 ang = atanfull(physLine(b).x - (physLine(b).x+physLine(b).xvel),physLine(b).y - (physLine(b).y+physLine(b).yvel)) line sin(ang)*(length#*-0.5)+physLine(b).x,cos(ang)*(length#*-0.5)+physLine(b).y,sin(ang)*(length#*0.5)+physLine(b).x,cos(ang)*(length#*0.5)+physLine(b).y next b ink rgb(255,255,255),0 if image exist(1)=0 then line 0,groundHeight,screen width(),groundHeight return throwMode: picked = 0 repeat if mouseclick() for i = 1 to array count(physBox()) if (mousex() > physBox(i).x - physBox(i).width*0.5 AND mousex() < physBox(i).x + physBox(i).width*0.5) AND (mousey() > physBox(i).y - physBox(i).height * 0.5 AND mousey() < physBox(i).y + physBox(i).height*0.5) picked = i endif next i endif until picked>0 ink rgb(255,0,0),0 box physBox(picked).x - physBox(picked).width*0.5-1,physBox(picked).y - physBox(picked).height*0.5-1,physBox(picked).x+physBox(picked).width*0.5+1,physBox(picked).x+physBox(picked).height*0.5+1 ink rgb(255,255,255),0 sync wait 2500 throwAng# = 180.0 throwPow# = 15.0 throw = 0 repeat cls gosub drawBoxes if leftkey() then inc throwAng#,1.5 if rightkey() then dec throwAng#,1.5 if upkey() then inc throwPow#,1 if downkey() then dec throwPow#,1 line sin(throwAng#)*(throwPow#+15)+physBox(picked).x,cos(throwAng#)*(throwPow#+15)+physBox(picked).y,sin(throwAng#)*15+physBox(picked).x,cos(throwAng#)*15+physBox(picked).y if mouseclick() then throw=1 until throw=1 addForce(picked,throwAng#,throwPow#) lasttime = timer() return function addForce(phys,rot#,strength#) rot# = wrapvalue(rot#) physBox(phys).xvel = sin(rot#)*strength# + physBox(phys).xvel physBox(phys).yvel = cos(rot#)*strength# + physBox(phys).yvel endfunction function moveBullet(bullet,ang#,speed#) physBullet(bullet).xvel = sin(ang#)*speed# physBullet(bullet).yvel = cos(ang#)*speed# physBullet(bullet).ang = ang# endfunction function moveLine(bullet,ang#,speed#) physLine(bullet).xvel = sin(ang#)*speed# physLine(bullet).yvel = cos(ang#)*speed# physLine(bullet).ang = ang# endfunction function bloodSquirt(x,y,ang#,bloodiness#,speed#,color as dword) bloodDrops = (bloodiness#)*10 for bloodno = 1 to bloodDrops shot=shootLine(x,y,ang#+(rnd(100)-50),speed#*(rnd(100)/100.0),1,0) colorLine(shot,rgbr(color),rgbg(color),rgbb(color)) next bloodno endfunction function colorBullet(bullet,r,g,b) physBullet(bullet).color = rgb(r,g,b) endfunction function colorLine(bullet,r,g,b) physLine(bullet).color = rgb(r,g,b) endfunction function addBarrel(x,y,mass#,size#,bounce#) array insert at bottom physBox() c = array count(physBox()) physBox(c).x = x physBox(c).y = y physBox(c).mass = mass# physBox(c).width = 10*size# physBox(c).height = 16*size# physBox(c).bounce = bounce# endfunction function colorBarrel(bno,r,g,b) physBox(bno).color = rgb(r,g,b) endfunction function shootBullet(x,y,ang#,speed#,decay#,damage#) array insert at bottom physBullet() c = array count(physBullet()) physBullet(c).x = x physBullet(c).y = y physBullet(c).damage = damage# physBullet(c).decay = decay# moveBullet(c,ang#,speed#) physBullet(c).color = rgb(255,255,255) endfunction c function shootLine(x,y,ang#,speed#,decay#,damage#) array insert at bottom physLine() c = array count(physLine()) physLine(c).x = x physLine(c).y = y physLine(c).damage = damage# physLine(c).decay = decay# moveLine(c,ang#,speed#) endfunction c function crosshair(x,y,size) line x-size*0.5,y,x+size*0.5,y line x,y-size*0.5,x,y+size*0.5 endfunction function explode(x,y,size#,damage#) stop sound 2 play sound 2 array insert at bottom explosions() e = array count(explosions()) explosions(e).x = x explosions(e).y = y explosions(e).radius = size#*60.0 explosions(e).damage = damage# explosions(e).health = 100 endfunction function setBulletExplosive(bullet,size#,dmg#) physBullet(bullet).grenade = 1 physBullet(bullet).size = size# physBullet(bullet).damage = dmg# endfunction |