Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 04-09-2008, 08:25 PM   #1
scott1969
Registered User
 
Join Date: Jan 2008
Posts: 17
Default [AS3] How do I Add a Energy Bar to my Shooter Game!

I am very new to AS3..

I am creating a kids game in AS3. There is a smile meter that goes up when you click on a good character and down when you click on a bad character. If you reach the top you win and if you reach the bottom you you lose.

What is the best way to achieve this? Attached is my Stage source code.
Any help would be greatly appreciated.

Thanks,
Scott

I asked the same question in the kirupa forum, but I cant seem to piece the code together correctly. Can anyone help? Here are my codes:


AS3 CODE ON FRAME 1:

var duckTimer:Timer = new Timer(2000, 1);
duckTimer.addEventListener(TimerEvent.TIMER, makeADuck);
duckTimer.start();


function makeADuck(evt:TimerEvent):void {

var newDuck:duck = new Duck();
var duckIndex:Number = this.getChildIndex(gdCheet1)+1;
addChildAt(newDuck, duckIndex);
newDuck.y = 204.8;
newDuck.swim();
newDuck.addEventListener(MouseEvent.CLICK, clickDuck);
}


var duckTimer2:Timer = new Timer(8000,1);
duckTimer2.addEventListener(TimerEvent.TIMER, makeADuck2);
duckTimer2.start();

function makeADuck2(evt:TimerEvent):void {

var newDuck:duck2 = new Duck2();
var duckIndex:Number = this.getChildIndex(duck2Fnl)+1;
addChildAt(newDuck, duckIndex);
newDuck.y = 178.6;
newDuck.swim();

}

var duckTimer3:Timer = new Timer(10000,1);
duckTimer3.addEventListener(TimerEvent.TIMER, makeADuck3);
duckTimer3.start();

function makeADuck3(evt:TimerEvent):void {

var newDuck:duck3 = new Duck3();
var duckIndex:Number = this.getChildIndex(bamboo1)+1;
addChildAt(newDuck, duckIndex);
newDuck.y = 100.0;
newDuck.swim();


}

var duckTimer4:Timer = new Timer(15000,1);
duckTimer4.addEventListener(TimerEvent.TIMER, makeADuck4);
duckTimer4.start();

function makeADuck4(evt:TimerEvent):void {

var newDuckuck4 = new Duck4();
var duckIndex:Number = this.getChildIndex(goodMnky2)+1;
addChildAt(newDuck, duckIndex);
newDuck.y = 147.6;
newDuck.swim();

}

var duckTimer5:Timer = new Timer(15000,1);
duckTimer5.addEventListener(TimerEvent.TIMER, makeADuck5);
duckTimer5.start();

function makeADuck5(evt:TimerEvent):void {

var newDuck:duck5 = new Duck5();
var duckIndex:Number = this.getChildIndex(goodMnky)+1;
addChildAt(newDuck, duckIndex);
newDuck.y = 58.1;
newDuck.swim();

}

var duckTimer6:Timer = new Timer(25000,1);
duckTimer6.addEventListener(TimerEvent.TIMER, makeADuck6);
duckTimer6.start();

function makeADuck6(evt:TimerEvent):void {

var newDuck:duck6 = new Duck6();
var duckIndex:Number = this.getChildIndex(goodMnky)+1;
addChildAt(newDuck, duckIndex);
newDuck.y = 389.6;
newDuck.swim();

}



var duckTimer7:Timer = new Timer(5000,1);
duckTimer7.addEventListener(TimerEvent.TIMER, makeADuck7);
duckTimer7.start();

function makeADuck7(evt:TimerEvent):void {

var newDuck:duck7 = new Duck7();
var duckIndex:Number = this.getChildIndex(bamboo1)+1;
addChildAt(newDuck, duckIndex);
newDuck.y = 374.6;
newDuck.swim();

}

var duckTimer8:Timer = new Timer(20000,1);
duckTimer8.addEventListener(TimerEvent.TIMER, makeADuck8);
duckTimer8.start();

function makeADuck8(evt:TimerEvent):void {

var newDuckuck8 = new Duck8();
var duckIndex:Number = this.getChildIndex(bamboo1)+1;
addChildAt(newDuck, duckIndex);
newDuck.y = 485.5;
newDuck.swim();

}

var duckTimer9:Timer = new Timer(2500,1);
duckTimer9.addEventListener(TimerEvent.TIMER, makeADuck9);
duckTimer9.start();

function makeADuck9(evt:TimerEvent):void {

var newDuckuck9 = new Duck9();
var duckIndex:Number = this.getChildIndex(goodMnky)+1;
addChildAt(newDuck, duckIndex);
newDuck.y = 385.4;
newDuck.swim();

}

var duckTimer10:Timer = new Timer(7000,1);
duckTimer10.addEventListener(TimerEvent.TIMER, makeADuck10);
duckTimer10.start();

function makeADuck10(evt:TimerEvent):void {

var newDuckuck10 = new Duck10();
var duckIndex:Number = this.getChildIndex(goodMnky)+1;
addChildAt(newDuck, duckIndex);
newDuck.y = 352.3;
newDuck.swim();

}

function clickDuck(evt:MouseEvent):void {
evt.target.hit();
}

Mouse.hide();
mTarget.mouseEnabled = false;
function moveTarget(evt:MouseEvent):void {
//target graphic = mTarget
mTarget.x = evt.stageX;
mTarget.y = evt.stageY;
}
stage.addEventListener(MouseEvent.MOUSE_MOVE,moveT arget);




AS3 EXTERNAL FILES



package {

import flash.display.MovieClip;
import fl.transitions.Tween;
import fl.transitions.easing.*;
import fl.motion.Animator;

public class Duck extends MovieClip {
var duckHit_animator:Animator;


function Duck():void {

}
public function swim():void {
var swimTween = new Tween(this, "x",None.easeNone,4.8,4.8, 5, true);

}
public function hit():void {
var duckHit_xml:XML = <Motion duration="10" xmlns="fl.motion.*" xmlns:geom="flash.geom.*" xmlns:filters="flash.filters.*">
<source>
<Source frameRate="12" x="-167.85" y="292.75" scaleX="1" scaleY="1" rotation="0" elementType="movie clip" symbolName="duckHit">
<dimensions>
<geom:Rectangle left="-85.65" top="-51" width="171.3" height="102"/>
</dimensions>
<transformationPoint>
<geom:Point x="0.5046701692936368" y="0.5"/>
</transformationPoint>
</Source>
</source>

<Keyframe index="0" tweenSnap="true" tweenSync="true">
<tweens>
<SimpleEase ease="0"/>
</tweens>
<filters>
<filters:GlowFilter blurX="0" blurY="0" color="0xFF0000" alpha="1" strength="0" quality="1" inner="false" knockout="false"/>
</filters>
</Keyframe>

<Keyframe index="4" tweenSnap="true" tweenSync="true">
<tweens>
<SimpleEase ease="0"/>
</tweens>
<filters>
<filters:GlowFilter blurX="45" blurY="45" color="0x3366FF" alpha="1" strength="1" quality="1" inner="false" knockout="false"/>
</filters>
</Keyframe>

<Keyframe index="9">
<filters>
<filters:GlowFilter blurX="0" blurY="0" color="0xFF0000" alpha="1" strength="0" quality="1" inner="false" knockout="false"/>
</filters>
</Keyframe>
</Motion>;

duckHit_animator = new Animator(duckHit_xml, this);
duckHit_animator.play();


}
}
}





SECOND AS3 FILE ect..

package{

import flash.display.MovieClip;
import fl.transitions.Tween;
import fl.transitions.easing.*;

public class Duck2 extends MovieClip {

function Duck2():void{

}
public function swim():void {
var swimTween = new Tween(this, "x",None.easeNone,302.4, 222, 4, true);

}

}
}
scott1969 is offline   Reply With Quote
Old 04-10-2008, 12:45 AM   #2
rrh
throw a trace() in there
 
Join Date: Dec 2006
Posts: 1,982
Default

For the sake of readability, surround code with [ as ] tags. And what was wrong with the advice you got on Kirupa?

http://www.kirupa.com/forum/showthread.php?t=294420
rrh is offline   Reply With Quote
Old 04-10-2008, 02:56 PM   #3
scott1969
Registered User
 
Join Date: Jan 2008
Posts: 17
Default

Nothing was wrong with the advice, it is my ability to apply it. I am not sure where to incorporate the code in my frame work. I just started learn AS3 and I am pretty much lost. I know I can figure it out, but time is of the essence..

Peace,
Scott
scott1969 is offline   Reply With Quote
Old 04-11-2008, 06:17 PM   #4
rrh
throw a trace() in there
 
Join Date: Dec 2006
Posts: 1,982
Default

I'm asking because they say basically the same thing I would say.

My standard question: What is it doing instead of working?

Maybe something they overlooked, if you access disposition from outside of the Duck class, it should be public:
ActionScript Code:
public var disposition:String;
rrh is offline   Reply With Quote
Old 02-24-2009, 09:52 PM   #5
tkalim
Registered User
 
Join Date: Feb 2009
Posts: 1
Default A nice tutorial

Hey there, I found a tutorial about this at freshnova. It helped me out, hope it helps you as well. http://www.freshnova.com/Flash-Tutor...flashgame.html.
tkalim is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
FlashGameLicense.com - virtual marketplace to connect game developers and buyers AdamSchroeder General Chat 0 12-18-2007 09:16 PM
double clicking the space bar seems to stop a movie clip in my game... Dave_H Gaming and Game Development 1 10-03-2007 10:58 AM
health bar for flash game problems scrumpyjack10 Gaming and Game Development 1 08-24-2007 03:33 PM
Rate My Game, plz fill the questioner UzumakiJr Site Check 0 12-16-2006 08:48 PM
[AS2] Shooter Game gabrielknight Gaming and Game Development 0 04-05-2005 11:15 PM


All times are GMT. The time now is 11:40 PM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.