Trailer : Adobe flash cs4 Game tutorial: shooting
Tutorial ini akan menunjukkan cara membuat game dengan penembakan fungsionalitas. Ini adalah hal yang sangat sederhana untuk membuat. Semua action script dalam timeline dan file bullet.as. Kami kami kelas peluru untuk mengendalikan peluru dalam permainan.
bullet.as
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); } } }
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); } } }
TimeLine
var sfx_gun:Sound = new sfx();
var sp:MovieClip = new ship();
var bulletholder:Sprite = new Sprite();
addChild(bulletholder);
addChild(sp);
addEventListener(Event.ENTER_FRAME,onenter);
stage.addEventListener(MouseEvent.CLICK,onclick);
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);
}
var sp:MovieClip = new ship();
var bulletholder:Sprite = new Sprite();
addChild(bulletholder);
addChild(sp);
addEventListener(Event.ENTER_FRAME,onenter);
stage.addEventListener(MouseEvent.CLICK,onclick);
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);
}