actionscript 3 - How can i hitTesObject a movieclip inside a movieclip AS3? -
i want zombie collect brains(g1b1,g1b2,g1b3,g1b4). these brains inside movieclip 'platform1' because need have scrolling background effect. zombie character can walk can't collect brains.
import flash.display.movieclip; import flash.events.keyboardevent; import flash.events.event; import flash.ui.keyboard; import flash.display.sprite; public class z extends movieclip { private var score:int=0; private var zombiespeed:int=7; //speed zombie private var gravity:int=1; private var jumpspeed:int=0;//current speed jump private var jumpspeedlimit:int=15; //how quick jump private var jump, left, right, down, mainjump:boolean=false; //zombie not jumping public function z() { } public function game1() { stop(); stage.addeventlistener(keyboardevent.key_down, keypressed); stage.addeventlistener(keyboardevent.key_up, keyreleased); zombie.addeventlistener(event.enter_frame, movecharacter1); gameplay1(); } private function keypressed(e:keyboardevent) { if (e.keycode==keyboard.left) { left=true; zombie.gotoandplay("left"); } if (e.keycode==keyboard.right) { right=true; zombie.gotoandplay("right"); } if (e.keycode==keyboard.space || keyboard.up) { jump=true; } if (e.keycode==keyboard.down) { down=true; } } private function keyreleased(e:keyboardevent) { if (e.keycode==keyboard.left || keyboard.d) { left=false; zombiespeed-=5; zombie.gotoandstop("idleleft"); } if (e.keycode==keyboard.right || keyboard.a) { right=false; zombiespeed+=5; zombie.gotoandstop("idleright"); } if (e.keycode==keyboard.space || keyboard.up || keyboard.w) { jump=false; } if (e.keycode==keyboard.down || keyboard.s) { down=false; } } private function movecharacter1(e:event) { if (left) { if (platform1.x<1000 && zombie.x==870) { platform1.x+=5; } else { if (zombie.x>120) { zombie.x-=zombiespeed; trace(platform1.x); } } } if (right) { if (platform1.x>0 && zombie.x==870) { platform1.x-=5; } else { if (zombie.x<880) { zombie.x+=zombiespeed; trace(platform1.x) } } } if (jump) { gojump(); } function gojump() { if(jumpspeed > 0 && jumpspeed <= jumpspeedlimit){ jumpspeed *= 1 + jumpspeedlimit/50; } zombie.y += jumpspeed; (var i=0;i<5;i++) { if(platform1.hittestpoint(zombie.x,zombie.y,true)) { zombie.y--; jumpspeed=0; mainjump=false; } } } **private function gameplay1() { if(zombie.hittestobject(platform1.g1b1)){ platform1.g1b1.visible = false; score+=10; } if(zombie.hittestobject(platform1.g1b2)){ platform1.g1b2.visible = false; score+=10; } if(zombie.hittestobject(platform1.g1b3)){ platform1.g1b3.visible = false; score+=10; } if(zombie.hittestobject(platform1.g1b4)){ platform1.g1b4.visible = false; score+=10; } }** }
Comments
Post a Comment