Trailer : Adobe flash cs4 Game tutorial Enemy Creation






main time linecode

var sfx_gun:Sound = new sfx();

var sp:MovieClip = new ship();

var tm:Timer = new Timer(1500);



tm.addEventListener(TimerEvent.TIMER, onstart);



var bulletholder:Sprite = new Sprite();



addChild(bulletholder);



addChild(sp);



addEventListener(Event.ENTER_FRAME,onenter);

stage.addEventListener(MouseEvent.CLICK,onclick);



tm.start();

function onstart(e:Event){





var em:Sprite = new enemy();

em.x= Math.random()*550;

addChild(em);





}





function onenter(e:Event):void {

sp.x-=(sp.x-mouseX)*.1;

sp.y-=(sp.y-350)*.2;

}



function onclick(e:Event) {

sfx_gun.play();

sp.y=365;

var bl:Sprite = new bullet();

bl.y=sp.y;

bl.x=sp.x;

bulletholder.addChild(bl);

}


Bullet Class

package {

import flash.display.Sprite;

import flash.events.Event;



public class bullet extends Sprite {



private var sw:Number;

private var sh:Number;

private const _SPEED:int=10;

private const _OFFSTAGE:int=-10;



public function bullet():void {

addEventListener(Event.ADDED_TO_STAGE,onadd);

}



private function onadd(e:Event):void {

sw=stage.stageWidth;

sh=stage.stageHeight;

addEventListener(Event.ENTER_FRAME,loop);

}



private function loop(e:Event):void {

if (y<_OFFSTAGE) { removeEventListener(Event.ENTER_FRAME,loop); parent.removeChild(this); } y-=_SPEED; } public function removeListeners():void { removeEventListener(Event.ENTER_FRAME,loop); } } }




Enemy Class

package {
import flash.events.Event;
import flash.display.MovieClip;
import flash.display.Sprite;
public class enemy extends Sprite {
private var core:Object;
public function enemy() {
addEventListener(Event.ADDED_TO_STAGE,onadd);
}


private function onadd(e:Event) {
core=MovieClip(root);
addEventListener(Event.ENTER_FRAME,loop);
}


private function loop(e:Event) {
y+=2;
for (var i:int = 0; i

Blog Archive