PDA

View Full Version : [AS3] shooting game help


ErikR
09-09-2009, 04:52 PM
Hello,

an italian guy here is asking for a massive help, I'm an absolute newbie to AS3 and to programming in general and I have to build a game for my work placement company. I know how to use Flash for animation and some basic(
REALLY basic) AS actions. Here is the point:

I'm working on a shooting game (laser gun game), I've read a good amount of articles and tutorials but I'm still struggling with it, often I don't even know how to start doing stuff, so I feel kind of lost. I tried to use different approaches but everything lead to nothing/nada/niente :mad:

- I have multiples MC (mcBandit) hidden behind other MC on the stage(trees, dunes and other stuff), those MC are animated, they just go up and then they come back down.

- If the player shoot at this mcBandit earn some points.

- Every mcBandit is on a separate layer, what I would like to do is trigger those MCs randomly like 2 or 3 at a time so that they start the animation and the player can shoot at them.

- I would like to add then another class of mcBandit that is faster and gives more point to the player in case he hit them. so the 2 different classes are together in the same level

- I made a clock-timer that last 30seconds after which the level has to end and then the player earn a score which will be added to the one he will earn beating the 2nd level and so on.

that's what I got so far (almost nothing, I know..), some of the tests that I've done are under comments tag:

//add bandit on stage
//var bandit1 = new Bandit();
// addChild (bandit1);
// bandit1.x = 100;
// bandit1.y = 200;
//
//mouse click the bandit
//bandit1.addEventListener(MouseEvent.CLICK, killed)
//
//kill the bandit
//function killed (e:MouseEvent);
//{
// removeChild (bandit1);
//}

var banditCaller:Timer;
var clockTimer:Timer = new Timer (1000, 30);
var cursor:MovieClip;
//var bandit1:MovieClip;
//var bandit2:MovieClip;
//var bandit3:MovieClip;
//var bandit4:MovieClip;
//var bandit5:MovieClip;
//var bandit6:MovieClip;
//var bandit7:MovieClip;


//var banditGroup:Array = new Array (bandit1, bandit2, bandit3, bandit4, bandit5, bandit6, bandit7);


//
//var kills:int = 0;
//function killEnemies(e:MouseEvent):void {
//kills += 1;
//killCount_txt.text = String(kills);
//}
//
//
//
//banditGroup.addEventListener(MouseEvent.CLICK, banditKill);
//
//function banditKill(e:MouseEvent);
//{
// if( )
// banditGroup.alpha = 0;
//}
//


function initializeGame():void
{
cursor = new Cursor();
addChild(cursor);
cursor.mouseEnabled = false;
Mouse.hide();
stage.addEventListener(MouseEvent.MOUSE_MOVE, dragCursor);

banditCaller.addEventListener(TimerEvent.TIMER,cre ateBandit);
banditCaller.start();
}

function banditCaller(event:TimerEvent):void
{
var bandit:MovieClip;
bandit = Math.random() * new Bandit;
addChild(bandit);

}

function dragCursor(event:MouseEvent):void
{
cursor.x = this.mouseX;
cursor.y = this.mouseY;
}

initializeGame();

//function banditCaller(event:TimerEvent):void
//{
// var bandit:MovieClip;
// bandit = Math.random() * new bandit;
// addChild(bandit);
//}

startButton.addEventListener(MouseEvent.CLICK, startTimer);

//CLOCK
clockTimer.addEventListener(TimerEvent.TIMER, moveLine);
clockTimer.addEventListener(TimerEvent.TIMER_COMPL ETE, endTimer);

function startTimer(e:MouseEvent):void
{
clockTimer.start();
trace("Timer Started");

startButton.visible = false;
}

function moveLine(e:TimerEvent):void
{
line.rotation = line.rotation + 12;
trace("Timer cycle Expired");
}

function endTimer(e:TimerEvent):void
{
trace("Timer finished")
}
//CLOCK END

Thanks guys even for reading this long and tedious post!