A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: [RESOLVED] [Help] [AS3]: Point and click shooting game... a better way?

  1. #1
    Juvenile Delinquent CVO Chris's Avatar
    Join Date
    Jul 2002
    Location
    Ulster, UK
    Posts
    520

    resolved [RESOLVED] [Help] [AS3]: Point and click shooting game... a better way?

    Hi everyone. I have some AS3 experience but I'm no expert, probably just reaching intermediate.

    I'm creating my first game which is a standard point and click shooter but with additional elements like pressing space will throw a petrol bomb (like a smart bomb in the old spectrum shooters).

    Currently I'm using event listeners to hear for when the user clicks on an enemy or a pick up. Is this the best way to go? I can foresee a whole lot of instances and wondering about flash's performance. The game will run along the timeline as it's more of an interactive movie/animation than a single scene with random enemies popping out to be shot at.

    PHP Code:
    // sample of enemy getting shot at code:
    enemy14.addEventListener(MouseEvent.CLICK,enemyHit);

    function 
    enemyHit(event:MouseEvent):void
    {
        
    event.target.gotoAndPlay("hit");

    My main problem though is how would I code in the bomb function. Since this will not have a target movieclip it would need to apply to all enemy movieclips on stage. I envisage each enemy movieclip having a "hit" frame label and a "bomb" frame label which will differentiate between the enemy getting shot or bombed. Again, is this (frame labels) the best way to go?

    PHP Code:
    // sample of user using bomb code:
    stage.addEventListener(KeyboardEvent.KEY_DOWNonKeyPress);
    function 
    onKeyPress(e:KeyboardEvent):void{
        if (
    e.keyCode == Keyboard.SPACE) {
        
    ALL ENEMY MOVIE CLIPS??? .gotoAndPlay("bomb");
        }

    I have no OOP experience so I'm stuck with procedural programming techniques for now so classes etc are out of the question for me.

    EDIT - I've thought of 2 ways of doing the bomb. Upon creating an enemy add it's instance name to an array (and remove it from the array if the enemy dies). If user uses a bomb then cycle through the instance names in the array.
    The other way, if it's possible, is get all instances on stage and check for instances that begin with "enemy" then apply gotoAndPlay("bomb") to those instances. But again, is this the best way or am I missing something obvious?
    Last edited by CVO Chris; 01-14-2011 at 07:35 AM.

  2. #2
    Juvenile Delinquent CVO Chris's Avatar
    Join Date
    Jul 2002
    Location
    Ulster, UK
    Posts
    520
    Anyone know what do with this?

    PHP Code:
    function onKeyPress(e:KeyboardEvent):void{
    // THROW BOMB UPON PRESSING SPACE BAR
        
    if (e.keyCode == Keyboard.SPACE) {
        for (var 
    i:int 0bombArray.lengthi++) {
                   
    enemy14.gotoAndPlay("bomb"); // this works
                   
    bombArray[i].gotoAndPlay("bomb"); // this doesn't
                   
    }
        }

    When I trace bombArray I get enemy14. For some reason the code works if I use enemy14.gotoAndPlay("bomb"); but not if I use bombArray[i].gotoAndPlay("bomb"); (getting the error "TypeError: Error #1006: value is not a function.
    at Untitled_fla::MainTimeline/onKeyPress()")
    Last edited by CVO Chris; 01-14-2011 at 08:21 AM.

  3. #3
    Juvenile Delinquent CVO Chris's Avatar
    Join Date
    Jul 2002
    Location
    Ulster, UK
    Posts
    520
    Nevermind, got it. I was adding items to the array using:
    MovieClip(this.root).bombArray.push(this.name);
    Taking out the .name fixed the issue:
    MovieClip(this.root).bombArray.push(this);

    Tracing the Array I get [object_Enemy_1] rather than the instance name. For some reason you can write the instance name in the code and it works but not reference it through the array.

    As long as it works!

  4. #4
    Senior Member
    Join Date
    Apr 2009
    Posts
    138
    Was that all the help you needed? (that happens to me sometimes, you solve your problem quicker then you get a reply!)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center