Animated 2D Sprite Character With Gun by Flyin Mushroom23rd Nov 2008 3:29
|
---|
Summary Animated character that is able to move in eight directions and shoot a firearm. (MEDIA IN DOWNLOAD) Description Animated character that is able to move in eight directions and shoot a firearm. Code ` This code was downloaded from The Game Creators ` It is reproduced here with full permission ` http://www.thegamecreators.com hide mouse : sync on : sync rate 60 backdrop on : color backdrop rgb(0,0,0) rem ------- Load Human Characters gosub load_player_images rem ------- Load Sound load sound "shoot.wav",1 rem ------ Human Character Varibles playery=0 playerx=0 rem ------ human character speed in change of position (higher the # the faster) playerspeed=1 rem ------ animated walking speed (higher the # the slower) anispeed=5 rem ------ variables for when sprite gets flipped back & forth hor=0 ver=0 rem --ARRAY CREATION-- 1=start 2=time 3=x 4=y 5=direction moving at time fired dim bullet(18,5) start=0 rem ------ playpos = determines the direction the player is facing rem ------------- default= DOWN (4) playpos=4 a=1 fire=0 rem ----- variable controlling upleft, upright,downleft,downright ani=0 rem ----- variable controlling up, down, left, right, player image ANIMATION ani1=0 sprite 1,200+playerx,100+playery,a set text font "arial" : set text size 12 rem ---------------------- MAIN LOOP --------------------------- do rem ---------- Display Of Characters Current Direction select playpos case 1 : text 300,20,"LEFT": endcase case 2 : text 300,20,"RIGHT": endcase case 3 : text 300,20,"UP": endcase case 4 : text 300,20,"DOWN": endcase case 5 : text 300,20,"UP-LEFT": endcase case 6 : text 300,20,"UP-RIGHT": endcase case 7 : text 300,20,"DOWN-LEFT": endcase case 8 : text 300,20,"DOWN-RIGHT": endcase case default : text 320,400," " : endcase endselect center text 100,450,"Use Arrow Keys To Move Character" center text 500,450,"Use Space-Bar To Fire Handgun" gosub player_controls sprite 1,200+playerx,100+playery,a gosub bullets_control sync : loop rem ----------------------- END OF MAIN LOOP --------------------- rem --------------------- Bullets Control bullets_control: rem ------- SHOOTING if fire=0 and spacekey()=1 then fire=1 if spacekey()=0 and fire=1 play sound 1 if playpos=1 or playpos=2 then a=15 if playpos=3 then a=10 if playpos=4 then a=5 if playpos=5 or playpos=6 then a=20 if playpos=7 or playpos=8 then a=25 for z=1 to 18 if bullet(z,1)=0 rem ---- bullet(z,1)= sets BULLET ON/OFF --- bullet(z,2)= sets BULLET TIME bullet(z,1)=1 : bullet(z,2)=50 rem ---- sets Bullet to come out gun if playpos=1 bullet(z,5)=1 : bullet(z,3)=sprite x(1)-18 : bullet(z,4)=sprite y(1)+8 : endif if playpos=2 bullet(z,5)=2 : bullet(z,3)=sprite x(1)+18 : bullet(z,4)=sprite y(1)+8 : endif if playpos=3 bullet(z,5)=3 : bullet(z,3)=sprite x(1)+8 : bullet(z,4)=sprite y(1) : endif if playpos=4 bullet(z,5)=4 : bullet(z,3)=sprite x(1)+8 : bullet(z,4)=sprite y(1)+25 : endif if playpos=5 bullet(z,5)=5 : bullet(z,3)=sprite x(1) : bullet(z,4)=sprite y(1) : endif if playpos=6 bullet(z,5)=6 : bullet(z,3)=sprite x(1)+20 : bullet(z,4)=sprite y(1) : endif if playpos=7 bullet(z,5)=7 : bullet(z,3)=sprite x(1) : bullet(z,4)=sprite y(1)+13 : endif if playpos=8 bullet(z,5)=8 : bullet(z,3)=sprite x(1)+16 : bullet(z,4)=sprite y(1)+10 : endif dot bullet(z,3),bullet(z,4) goto bull : endif next z bull: fire=0 endif rem ------------- MOVES BULLETS for z=1 to 18 if bullet(z,2)<1 then bullet(z,1)=0 if bullet(z,2)>0 bullet(z,2)=bullet(z,2)-1 rem -------- moves bullets ACCORDING to the position of the PLAYER rem ---- 1=LEFT / 2=RIGHT / 3=UP / 4=DOWN if bullet(z,5)=1 then bullet(z,3)=bullet(z,3)-10 if bullet(z,5)=2 then bullet(z,3)=bullet(z,3)+10 if bullet(z,5)=3 then bullet(z,4)=bullet(z,4)-10 if bullet(z,5)=4 then bullet(z,4)=bullet(z,4)+10 if bullet(z,5)=5 then bullet(z,3)=bullet(z,3)-10 : bullet(z,4)=bullet(z,4)-10 if bullet(z,5)=6 then bullet(z,3)=bullet(z,3)+10 : bullet(z,4)=bullet(z,4)-10 if bullet(z,5)=7 then bullet(z,3)=bullet(z,3)-10 : bullet(z,4)=bullet(z,4)+10 if bullet(z,5)=8 then bullet(z,3)=bullet(z,3)+10 : bullet(z,4)=bullet(z,4)+10 endif ink rgb(200,200,200),1 if bullet(z,1)=1 then dot bullet(z,3),bullet(z,4) next z return rem ------------------------ PLAYER CONTROLS player_controls: if downkey()=1 or upkey()=1 ver=1 else ver=0 endif if leftkey()=1 or rightkey()=1 hor=1 else hor=0 endif if ver=0 and leftkey()=1 playpos=1 if sprite mirrored(1)=0 then mirror sprite 1 if ani1>anispeed then ani1=0 if ani1=0 then a=a+1 : ani1=1 ani1=ani1+1 playerx=playerx-playerspeed if a<11 then a=11 if a>14 then a=11 endif if ver=0 and rightkey()=1 playpos=2 if sprite mirrored(1)=1 then mirror sprite 1 if ani1>anispeed then ani1=0 if ani1=0 then a=a+1 : ani1=1 ani1=ani1+1 playerx=playerx+playerspeed if a<11 then a=11 if a>14 then a=11 endif if hor=0 and upkey()=1 playpos=3 if ani1>anispeed then ani1=0 if ani1=0 then a=a+1 : ani1=1 ani1=ani1+1 playery=playery-playerspeed if a<7 then a=7 if a>9 then a=7 endif if hor=0 and downkey()=1 playpos=4 if ani1>anispeed then ani1=0 if ani1=0 then a=a+1 : ani1=1 ani1=ani1+1 playery=playery+playerspeed if a>4 then a=2 endif if ver=0 and leftkey()=0 then ani=0 if ver=1 and leftkey()=1 if upkey()=1 playpos=5 if sprite mirrored(1)=1 then mirror sprite 1 if ani>anispeed then ani=0 if ani=0 then a=a+1 : ani=1 ani=ani+1 playery=playery-playerspeed playerx=playerx-playerspeed if a<16 then a=16 if a>19 then a=16 endif : endif if ver=0 and rightkey()=0 then ani=0 if ver=1 and rightkey()=1 if upkey()=1 playpos=6 if sprite mirrored(1)=0 then mirror sprite 1 if ani>anispeed then ani=0 if ani=0 then a=a+1 : ani=1 ani=ani+1 playery=playery-playerspeed playerx=playerx+playerspeed if a<16 then a=16 if a>19 then a=16 endif : endif if ver=0 and leftkey()=0 then ani=0 if ver=1 and leftkey()=1 if downkey()=1 playpos=7 if sprite mirrored(1)=0 then mirror sprite 1 if ani>anispeed then ani=0 if ani=0 then a=a+1 : ani=1 ani=ani+1 playery=playery+playerspeed playerx=playerx-playerspeed if a<21 then a=21 if a>24 then a=21 endif : endif if ver=0 and rightkey()=0 then ani=0 if ver=1 and rightkey()=1 if downkey()=1 playpos=8 if sprite mirrored(1)=1 then mirror sprite 1 if ani>anispeed then ani=0 if ani=0 then a=a+1 : ani=1 ani=ani+1 playery=playery+playerspeed playerx=playerx+playerspeed if a<21 then a=21 if a>24 then a=21 endif : endif return rem ------------------------- PLAYER IMAGES load_player_images: load bitmap "updown1.bmp",1 get image 1,0,0,17,26 : get image 2,18,0,36,26 : get image 3,40,0,58,26 get image 4,61,0,80,26 : get image 5,84,0,100,26 get image 6,0,28,17,54 : get image 7,18,28,36,54 : get image 8,40,28,58,54 get image 9,61,28,80,54 : get image 10,84,28,100,54 : delete bitmap 1 load bitmap "side1.bmp",1 get image 11,0,0,20,28 : get image 12,20,0,40,28 : get image 13,40,0,60,28 get image 14,60,0,80,28 : get image 15,80,0,100,28 : delete bitmap 1 load bitmap "upside1.bmp",1 get image 16,0,0,20,28 : get image 17,20,0,40,28 : get image 18,40,0,60,28 get image 19,60,0,80,28 : get image 20,80,0,100,28 : delete bitmap 1 load bitmap "downside1.bmp",1 get image 21,0,0,20,28 : get image 22,20,0,40,28 : get image 23,40,0,60,28 get image 24,60,0,80,28 : get image 25,80,0,100,28 : delete bitmap 1 return |