2D Animated Human That Follows A Circle by Flyin Mushroom23rd Nov 2008 3:33
|
---|
Summary Computer controlled character that follows a circle based on the users control. (MEDIA DOWNLOAD) Description Computer controlled character that follows a circle based on the users control. 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 ------ complayer 1=left 2=right 3=up 4=down 5=upleft 6=upright 7=downleft 8=downright complayer=0 : comfire=0 gosub load_player_images remstart (sprite animation speed) ANISPEED= higher the # the slower Playerspeed= the # the number the faster the sprite moves position remend playery=0 : playerx=0 : playerspeed=1 : anispeed=5 rem ------ playpos = determines the direction the player is facing rem ------------- default= DOWN (4) playpos=4 : a=1 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 rem -------- thing for complayer to follow and shoot at cx=200 : cy=400 rem -------------------------- MAIN LOOP ------------------------- do rem ------------ box for 2d sprite to follow ------------ circle cx,cy,5 rem ----------- controls for to move the circle for the sprite to follow if upkey()=1 then dec cy,5 if downkey()=1 then inc cy,5 if leftkey()=1 then dec cx,5 if rightkey()=1 then inc cx,5 center text 320,420,"USE ARROW KEYS TO MOVE CIRCLE" gosub comp_moves sprite 1,200+playerx,100+playery,a sync : loop rem -------------------- END OF MAIN LOOP ------------------------ rem ------------------------ PLAYER CONTROLS comp_moves: if cy-sprite y(1)>0 then complayer=4 if cy-sprite y(1)<0 then complayer=3 if cx-sprite x(1)<-11 then complayer=1 if cx-sprite x(1)>0 then complayer=2 if cy-sprite y(1)>0 and cx-sprite x(1)<-11 then complayer=7 if cy-sprite y(1)>0 and cx-sprite x(1)>0 then complayer=8 if cy-sprite y(1)<-11 and cx-sprite x(1)<-11 then complayer=5 if cy-sprite y(1)<-11 and cx-sprite x(1)>0 then complayer=6 if complayer=0 then ani1=0 : ani=0 rem -------- left if complayer=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 rem -------- right if complayer=2 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 rem -------- up if complayer=3 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 rem -------- down if complayer=4 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 rem ---------- up-left if complayer=5 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 rem ---------- up-right if complayer=6 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 rem ---------- down-left if complayer=7 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 rem ---------- down-right if complayer=8 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 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 |