The NEW Jetpack demo by Jack2nd Aug 2004 9:30
|
---|
Summary It was boring and so I programmed that... Description +++ Many thanks to Tracer. +++ Code ` This code was downloaded from The Game Creators ` It is reproduced here with full permission ` http://www.thegamecreators.com sync on rem make ground make matrix 1,1000,1000,50,50 randomize matrix 1,10 set matrix wireframe off 1 set camera range 1,40000 color backdrop rgb(150,150,250) rem a jetpacker without media! rem make object sphere 1,10 scale object 1,100,200,100 make mesh from object 1,1 delete object 1 make object cube 1,5 scale object 1,200,150,100 make mesh from object 2,1 delete object 1 make object sphere 1,7 make mesh from object 3,1 delete object 1 make object cylinder 1,5 make mesh from object 4,1 delete object 1 make object sphere 1,5 scale object 1,80,125,80 make mesh from object 5,1 delete object 1 make object cylinder 1,5 scale object 1,100,350,100 make mesh from object 6,1 delete object 1 make object plain 1,0,0 make mesh from object 7,1 delete object 1 make object cube 1,2 scale object 1,100,100,400 make mesh from object 8,1 delete object 1 make object cube 1,2 add limb 1,1,8 offset limb 1,1,0,2,2 delete mesh 8 rotate object 1,90,180,180 make mesh from object 8,1 delete object 1 make object sphere 3,8 color object 3,rgb(255,255,255) add limb 3,1,1 color limb 3,1,0 offset limb 3,1,0,-12,0 add limb 3,2,2 color limb 3,2,rgb(255,0,0) offset limb 3,2,0,-7,-5 add limb 3,3,3 offset limb 3,3,0,0,1 color limb 3,3,0 add limb 3,4,4 offset limb 3,4,-2,-12,-5 add limb 3,5,4 offset limb 3,5,2,-12,-5 add limb 3,6,5 link limb 3,6,4 offset limb 3,6,0,-3,0 add limb 3,7,5 link limb 3,7,5 offset limb 3,7,0,-3,0 create bitmap 1,128,128 ink rgb(100,100,0),0 box 1,1,127,127 for count=1 to 1000 col=rnd(15)+10 ink rgb(col*10,col*10,0),0 line rnd(128),rnd(128),rnd(128),rnd(128) next count sync get image 1,0,0,128,128 set current bitmap 0 delete bitmap 1 texture limb 3,6,1 texture limb 3,7,1 add limb 3,8,6 offset limb 3,8,-2,-16,0 color limb 3,8,0 add limb 3,9,6 offset limb 3,9,2,-16,0 color limb 3,9,0 add limb 3,10,7 offset limb 3,10,-3,-8,0 add limb 3,11,6 link limb 3,11,10 offset limb 3,11,0,0,8 rotate limb 3,11,90,0,0 color limb 3,11,0 add limb 3,12,7 offset limb 3,12,3,-8,0 add limb 3,13,6 link limb 3,13,12 offset limb 3,13,0,0,8 rotate limb 3,13,90,0,0 color limb 3,13,0 add limb 3,14,8 link limb 3,14,11 offset limb 3,14,0,9,0 color limb 3,14,rgb(100,100,100) add limb 3,15,8 link limb 3,15,13 offset limb 3,15,0,9,0 color limb 3,15,rgb(100,100,100) position object 3,0,100,50 rem make floor-texture cls rgb(30,80,10) ink rgb(60,100,30),0 for x=0 to 56 dot x,rnd(56):dot x,rnd(56):dot x,rnd(56):dot x,rnd(56) dot x,rnd(56):dot x,rnd(56):dot x,rnd(56):dot x,rnd(56) next x ink rgb(40,110,40),0 for x=0 to 56 dot x,rnd(56):dot x,rnd(56):dot x,rnd(56):dot x,rnd(56) dot x,rnd(56):dot x,rnd(56):dot x,rnd(56):dot x,rnd(56) next x ink rgb(10,65,20),0 for x=0 to 56 dot x,rnd(56):dot x,rnd(56):dot x,rnd(56):dot x,rnd(56) dot x,rnd(56):dot x,rnd(56):dot x,rnd(56):dot x,rnd(56) next x get image 9,0,0,56,56 prepare matrix texture 1,9,1,1 for x=0 to 9 for y=0 to 9 set matrix tile 1,x,y,1 next y next x rem Make aeroplane. Same method as the jetpacker, but a simpler model make object sphere 1,5 scale object 1,100,100,1000 make mesh from object 9,1 delete object 1 make object cone 1,5 xrotate object 1,90 add limb 1,1,9 offset limb 1,1,0,15,0 rotate limb 1,1,90,0,0 fix object pivot 1 make mesh from object 10,1 delete object 1 make object cone 4,100 xrotate object 4,90 fix object pivot 4 scale object 4,100,1,100 color object 4,0 add limb 4,1,7 scale limb 4,1,100,100,10000 offset limb 4,1,-5,-20,15 add limb 4,2,10 link limb 4,2,1 position object 4,0,300,0 point object 4,0,300,300 objects=4 rem These arrays are used for working out where to put the bounding box rem for collision on the models dim sizex(4) dim sizey(4) dim sizez(4) sizex(4)=50 sizey(4)=5 sizez(4)=50 rem Health. Simple enough dim health(4) health(4)=100 rem Waypoints for the objects to move around dim wayps(4,1) wayps(4)=2 wayps(4,1)=1 dim wayp(4,10,1,1) wayp(4,1)=0 wayp(4,1,1)=300 wayp(4,1,1,1)=0 wayp(4,2)=0 wayp(4,2,1)=300 wayp(4,2,1,1)=300 rem The extremely clever wall arrays. They basically say where the bounding rem box for all the walls are. the 0 slot is the back point in the box, rem and the 1 slot is the furthest point, eg wallx(1,0)=-500 and rem wallx(1,1)=500 would make the bounding box go from -500 to +500 in the x rem axis dim wallx(4,1) dim wally(4,1) dim wallz(4,1) wallx(1,0)=0 wallx(1,1)=500 wally(1,0)=0 wally(1,1)=50 wallz(1,0)=0 wallz(1,1)=500 wallx(2,0)=200 wallx(2,1)=300 wally(2,0)=50 wally(2,1)=150 wallz(2,0)=200 wallz(2,1)=300 wallx(3,0)=-200 wallx(3,1)=0 wally(3,0)=-100 wally(3,1)=0 wallz(3,0)=0 wallz(3,1)=500 walls=3 rem These let the program work out how many bullets are in the air topammo=100 ammo=101 rem This sets up the arm rotation xr=90 rem This sets up the guns shots=2 shot=1 rem The Player<s health health=100 rem Making the cubes to go in the wall bounding-boxes. I<ll automate this rem one day make object cube 1,500 scale object 1,100,10,100 position object 1,250,25,250 make object cube 2,100 position object 2,250,100,250 make object cube 999,100 scale object 999,200,100,500 position object 999,-100,-50,250 rem This creates the stone texture for the walls, using lines of different rem shades of grey to make it look worn create bitmap 1,128,128 ink rgb(100,100,100),0 box 1,1,128,128 sync for count=1 to 1000 col=rnd(20)+5 ink rgb(col,col,col),0 line rnd(128),rnd(128),rnd(128),rnd(128) next count get image 2,1,1,128,128 texture object 1,2 texture object 2,2 texture object 999,2 set current bitmap 0 delete bitmap 1 rem Making bullets :) for count=10 to 100 make object cube count,1 position object count,-1000,-1000,-1000 rem This looks cool sometimes :) rem ghost object on count next count set camera range 1,1000 rem Camera setup if you<re using the fixed camera view position camera 250,200,250 fog on fog color rgb(150,150,250) fog distance 1500 do rem For collision. 24 is added to oldy because the model<s centre is rem actually its head. Foolish me. oldx=object position x(3) oldy=object position y(3)+24 oldz=object position z(3) rem Collision with the matrix if oldx<1000 and oldz<1000 and oldx>0 and oldz>0 and oldy>-40 and oldy<get ground height(1,oldx,oldz)+56 oldy=get ground height(1,oldx,oldz)+56 if yspeed#<-10 then inc health,yspeed# rem Stop all jumping grounded=1 yspeed#=0 else grounded=0 endif rem Stop walking if no keys are being pressed if scancode()<>17 and scancode()<>31 and mouseclick()<>2 and upkey()=0 and downkey()=0 then walk=0 rem move forwards if scancode()=17 or upkey()=1 or mouseclick()=2 or mouseclick()=3 then walk=5 rem Move backwards if scancode()=31 or downkey()=1 then walk=-5 rem Strafing, A and D keys are 30 and 32 in scancodes if scancode()=30 then strafe=-5 if scancode()=32 then strafe=5 rem Stop strafing if no buttons are being pressed. Another way of doing this rem is a few nested ifs, but I<m making this demo code clear to read if scancode()<>30 and scancode()<>32 then strafe=0 rem Jumping! Because of the way the code works (badly) you have to be moving rem on x or z to jump, so I just inc walk,1. Simple but improvement needed if spacekey()=1 : yspeed#=curvevalue(35,yspeed#,24) : if yspeed#<1 then inc walk,1 : endif if walk<>0 or strafe<>0 then movement=2 else movement=0 inc oldy,yspeed#+movement position object 3,oldx,oldy,oldz rem This makes it look like the jetpack really works (kinda) It scrolls the rem Flame texture coming out of the jetpack scroll limb texture 3,6,0,-0.05 scroll limb texture 3,7,0,-0.05 rem First move player forwards <walk> units yr=object angle y(3) rotate object 3,0,yr,0 move object 3,walk*2 rem Do strafing, <strafe> units rotate object 3,0,wrapvalue(yr+90),0 move object 3,strafe rem turn the player around with cursor keys or mouse yrotate object 3,wrapvalue(yr+mousemovex()/1.2+rightkey()*5-leftkey()*5) rem Where the player is now newx=object position x(3) rem Yet again, y is changed because the model is made wrong. This took far rem too long to fix :( newy=object position y(3)-48 newz=object position z(3) rem Count through all the walls to see if the player is colliding with them for count=1 to walls rem first of all you just work out if the player is in the bounding box if newx>wallx(count,0)-15 and newx<wallx(count,1)+15 if newy>wally(count,0)-15 and newy<wally(count,1)+15 if newz>wallz(count,0)-15 and newz<wallz(count,1)+15 rem the overly complicated way of finding out where the player is and rem Putting him back if newx>wallx(count,0)-15 then dec newx,newx-oldx if newx<wallx(count,1)+15 then inc newx,newx-oldx if newy>wally(count,0)-15 then dec newy,newy-(oldy-48) if newy<wally(count,1)+15 : inc newy,newy-(oldy-48) : if yspeed#<-10 then inc health,yspeed# : endif if newz>wallz(count,0)-15 then dec newz,newz-oldz if newz<wallz(count,1)+15 then inc newz,newz-oldz rem Hitting a wall normally stops you moving :) Watch Road Runner for rem more information if you didn<t know this yspeed#=0 endif endif endif next count rem Move moving objects for count=4 to objects if health(count)>0 and object exist(count)=1 if object position x(count)>wayp(count,wayps(count,1))-5 and object position x(count)<wayp(count,wayps(count,1))+5 if object position y(count)>wayp(count,wayps(count,1),1)-5 and object position y(count)<wayp(count,wayps(count,1),1)+5 if object position z(count)>wayp(count,wayps(count,1),1,1)-5 and object position z(count)<wayp(count,wayps(count,1),1,1)+5 wayps(count,1)=wayps(count,1)+1 if wayps(count,1)>wayps(count) then wayps(count,1)=1 point object count,wayp(count,wayps(count,1)),wayp(count,wayps(count,1),1),wayp(count,wayps(count,1),1,1) endif endif endif move object count,10 rem Work out the bounding box for the object wallx(count,0)=object position x(count)-sizex(count) wallx(count,1)=object position x(count)+sizex(count) wally(count,0)=object position y(count)-sizey(count) wally(count,1)=object position y(count)+sizey(count) wallz(count,0)=object position z(count)-sizez(count) wallz(count,1)=object position z(count)+sizez(count) else rem Kill it if it<s dead if object exist(count)=1 then delete object count endif next count rem Yet again, it<s because the model<s made wrong inc newy,24 rem Position the object after collision position object 3,newx,newy,newz rem Gravity has never been written like this before yspeed#=curvevalue(-14,yspeed#,25) rem Camera code - for those of you that wanted that, here it is. rem Nice and quick and simple position camera newx,newy,newz if yspeed#<-10 then xr=40 if mousemovex()<>0 then mmovex=mousemovex()/abs(mousemovex()) else mmovex=0 turntarg=rightkey()+mmovex-leftkey() if scancode()=30 then turntarg=-3 if scancode()=32 then turntarg=3 turn=curvevalue(turntarg*30,turn,10) rotate camera xr,wrapvalue(yr+turn),0 move camera -50 if camera position y()<get ground height(1,camera position x(),camera position z()) then position camera camera position x(),get ground height(1,camera position x(),camera position z()),camera position z() rem Unrem these two lines and rem out the lines above for a fixed camera rem position camera 500,600,500 rem point camera newx,newy,newz rem Aiming - uses the mouse xr=wrapvalue(xr+mousemovey()) if yspeed#<-10 xr=280 lastfalling=1 else if lastfalling=1 then xr=40 lastfalling=0 endif rem Stop the arms from rotating too far :) if xr<280 and xr>180 then xr=280 if xr>40 and xr<180 then xr=40 rotate limb 3,10,xr,0,0 rotate limb 3,12,xr,0,0 rem Shooting! if mouseclick()=1 and timer=0 or mouseclick()=3 and timer=0 and ammo>10 rem Work out which gun to shoot from inc shot if shot=3 then shot=1 rem Gun firing animation rotate limb 3,shot+13,315,0,0 if shot=1 then angleone=45 else angletwo=45 rem Set the timer so you don<t shoot too fast timer=10 rem You<ll eventually run out of ammo (I think, I<ve never done it before) dec ammo rem Position and rotate the bullet position object ammo,limb position x(3,shot+13),limb position y(3,shot+13),limb position z(3,shot+13) rotate object ammo,xr,yr,0 endif rem Animate the guns angleone=curvevalue(0,angleone,10) if limb angle x(3,14)<359.5 then rotate limb 3,14,wrapvalue(360-angleone),0,0 angletwo=curvevalue(0,angletwo,10) if limb angle x(3,15)<359.5 then rotate limb 3,15,wrapvalue(360-angletwo),0,0 rem Make the timer work if timer>0 then dec timer rem Move the bullets for count=topammo to ammo step -1 move object count,50 rem Collision x=object position x(count) y=object position y(count) z=object position z(count) hit=0 rem Detect collision with the moving objects for targ=4 to objects if health(targ)>0 and object exist(targ)=1 if x>wallx(targ,0) and x<wallx(targ,1) if y>wally(targ,0) and y<wally(targ,1) if z>wallz(targ,0) and z<wallz(targ,1) rem Dec health health(targ)=health(targ)-15 rem Show the bullet has hit something. I<ve forgotten why I need this hit=1 rem Just to show you hit :) color object targ,rgb(health(targ)*2.5,health(targ)*2.5,health(targ)*2.5) sync endif endif endif endif next targ if object position x(count)>1000 or object position x(count)<-1000 or object position z(count)>1000 or object position z(count)<-1000 or object position y(count)<-1000 or object position y(count)>1000 or hit=1 dec topammo position object count,-1000,-1000,-1000 endif next count rem Reset ammo if all the bullets fired are now dead if topammo=ammo and topammo<100 : topammo=100 : ammo=101 : endif rem Draw health meter on screen ink rgb(health*2.5,0,0),0 box 1,1,health,20 ink rgb(255,255,255),0 center text health/2,5,str$(health) rem Take a screenshot with the control key! if controlkey()=1 and click=0 inc shots save bitmap "screenshot"+str$(shots)+".bmp" click=1 else if controlkey()=0 then click=0 endif sync loop |