Trailer : Adobe flash cs4 Game tutorial Enemy AI








Belajarlah untuk memberikan musuh Game Anda kecerdasan buatan. Dapatkan FLA di situs saya


Enemy AI

package {



import flash.events.Event;

import flash.display.MovieClip;

import flash.display.Sprite;



public class enemy extends Sprite {

private var core:Object;

private var yd:Number;

private var xd:Number;

public function enemy() {

addEventListener(Event.ADDED_TO_STAGE,onadd);

}



private function onadd(e:Event) {

core=MovieClip(root);

yd = core.sp.y-y;

xd = core.sp.x-x;

addEventListener(Event.ENTER_FRAME,loop);



}



private function loop(e:Event) {



var angle:Number=Math.atan2(yd,xd);



x+=Math.cos(angle)*3;

y+=Math.sin(angle)*3;





for (var i:int = 0; i<100) { if (run<0) { x+=4.5; } else { x-=4.5; } } if (hitTestObject(bulletTarget)) { core.bulletholder.getChildAt(i).removeListeners(); core.bulletholder.removeChild(bulletTarget); var boom:MovieClip = new explosion(); boom.x=x; boom.y=y; stage.addChild(boom); removeEventListener(Event.ENTER_FRAME, loop); core.removeChild(this); } } } public function removeListeners():void { removeEventListener(Event.ENTER_FRAME, loop); } } }

Blog Archive