dcsimg
A Flash Developer Resource Site

Results 1 to 9 of 9

Thread: Dire need of help with my Flash Game

Hybrid View

  1. #1
    Junior Member
    Join Date
    May 2005
    Posts
    4

    Dire need of help with my Flash Game

    Allright, heres the sich, I'm working on a space side scroller called "Exciting Fun X-Wing shooting Adventure!" Catchy huh? Anyway, the way it works is theres the menu, you choose your difficulty, then it goes to the game. But heres my conflict. Whenever you goto anouther scene, the Tie Fighters are still going across the screen. The TIEs are made with a "Duplicate" method in which its ment to keep them comming, my problem is that I'm trying to figure out how to get them to stop. If anyone can help I would be eternally greatful.

    For some info, heres my code for all the key parts.

    (((The X-Wing)))
    onClipEvent(load){

    moveSpeed=10;
    _root.laser._visible=false;
    laserCounter=1;
    scrollx=_root.mainGround.ground._width/3;
    scrollStart=false;
    maxLasers=4;
    depthCounter=1;

    }




    onClipEvent (enterFrame) {

    if (Key.isDown(Key.SHIFT) and (laserCounter<=maxLasers)) {

    laserCounter++;
    _root.laser.duplicateMovieClip( "laser"+depthCounter, depthCounter );
    _root["laser"+depthCounter]._visible=true;
    depthCounter++;
    if (depthCounter>maxLasers){
    depthCounter=1;
    }
    }

    if (Key.isDown(Key.RIGHT)) {
    if (this._x<scrollx){
    this._x+=moveSpeed;

    } else {
    scrollStart=true;
    }

    } else if (Key.isDown(Key.LEFT)and this._x>0) {

    this._x-=moveSpeed;
    }

    if (Key.isDown(Key.DOWN)and this._y<380) {
    this._y+=moveSpeed;
    } else if (Key.isDown(Key.UP)and this._y>0) {
    this._y-=moveSpeed;
    }

    }


    onClipEvent (keyUp) {
    if (Key.getCode() == Key.RIGHT) {
    scrollStart=false;
    }
    }


    (((TIE Fighter)))
    onClipEvent (load) {

    function reset(){
    this._x=550;
    this._y=random(200)+100;
    enemySpeed=random(4)+1+S;
    this.gotoAndStop(1);
    }

    reset();

    }

    onClipEvent (enterFrame) {

    if (_root.spaceship.scrollStart){
    this._x-=enemySpeed+_root.mainGround.groundSpeed;
    } else {
    this._x-=enemySpeed;
    }
    if (this._x<50) {
    reset();
    }

    if (this.hitTest( _root.spaceship ) ){
    _root.gotoAndStop ( "gameOver" );
    _root["enemy"+i].gotoAndStop(5);
    _root.removeMovieClip(["enemy"+i])
    "enemy"+i.unloadMovie();



    }


    }


    (((The Control)))

    numEnemy=D;
    g=1

    for (i=2; i<=numEnemy; i++){
    enemy1.duplicateMovieClip("enemy"+i, i+100 );

    }

    score=0;

  2. #2
    Say hello to Bob Kakihara's Avatar
    Join Date
    Jul 2004
    Location
    kent, England
    Posts
    1,067
    easiest way would be to get all the xwings to 'kill' themselves, so create a variable in the main timeline with your control bit, call it playing and set it to true, now when the ship collides with an xwing im guessing thats game over right? if so you should set the _root.playing=false. Then what you want is a piece of code in the xwing on enter frame, put an if statment saying that if _root.playing==false then this.removeMovieClip or whatever you are using to remove an enemy once it has collided with the ship, this will remove all of your enemies.

    Then to stop them being created just put your chunk of code that is creating enemies inside an if statement that says if playing ==true.

    You will probably need to place that code on a _root.onenterframe function in your main timeline.

    Hopethat helps, if you cant do what ive said then post the flash and ill try and update it for you.
    If our body is a clock ticking away and if while we experience all that this world has to offer time has still continued to pass, are we living or just experiencing a slow death?

  3. #3
    Junior Member
    Join Date
    May 2005
    Posts
    4
    I tried several things but none really seemed to work from my attempts (I'm very much a novice at flash so bare witn me, heh). So I'll just post the fla file. Note this is the file before adding any playing functions.

    And just so you know... there are a few inside jokes in this game so, bare with xD.
    Attached Files Attached Files

  4. #4
    Junior Member
    Join Date
    May 2005
    Posts
    4
    (Removed for double post)

  5. #5
    I tried... dbarbarian's Avatar
    Join Date
    Aug 2003
    Location
    Berkeley, California, USA
    Posts
    678
    I would highly recommend removing the enterFrame on every single TIE fighter MC. This is extremely inefficient and will cause extreme slowdown in the game when you decide to add more stuff to it. Instead, have each TIE fighter be put into an array, or a container clip.

    Persoanlly, i use the array mehtod (for which reason i dont know).

    First, you need to create a new array:
    code:
     _root.tieFighterArray = new Array(); 


    Then, when you are creating a TIE fighter, add that instance into the array using the push method:
    code:
     _root.tieFighterArray.push(duplicated movie clip instance name); 



    Then, create a function that will scroll through this array:
    PHP Code:
     _root.tieFighterMove = function() {
        
    //Optimize by making _root a var
        
    var _root;

        
    //use a while funtion to loop through the array. I prefer to loop from the last element, this gets rid of the hassle of sorting the elements when something is removed
        
    var r.tieFighterArray.length-1;
        
    //remember, the r stands for _root
        
    while (i>=0) {

            
    //this gets you the instance name of the duplicated tie fighter movie clip
            
    var name r.tieFighterArray[i];
            
    //remember, the r stands for _root

            //Moving code, collision code, and all other TIE fighter related codes go in here

            
    i--;
        }

    All you need now is one movie clip that contains all the enterFrame commands. In that movie clip, call the function _root.tieFighterMove every frame by
    code:
     _root.tieFighterMove(); 



    Now that you have the array and movement set up, all you need is a clean code that removes all the elements in the tie fighter array when you need.
    PHP Code:
     _root.clean = function() {
        var 
    _root;

        var 
    r.tieFighterArray.lenght-1;
        while(
    i>=0) {

            
    //this gets you the instance name of the duplicated tie fighter movie clip
            
    var name r.tieFighterArray[i];
            
    //remember, the r stands for _root

            //This removes the movie clip
            
    name.removeMovieClip();

            
    //This removes the element from the array
            
    r.tieFighterArray.splice(name,1);
            
    //The instance name (_root.tieFighterArray[i]) is removed from the array and onle 1 element is removed from that point

            
    i--;
        }

    Now all you need to do is call the clean function by using
    code:
    _root.clean();

    to remove all the tie fighters.


    I hope this is not too confusing. I typed this code up from scratch, so i cant guarantee a bug free code, you might need to edit some syntax, but the basic idea is there. I would recommend changing some function and variable names to shorter stuff to optimize even more. Also, i would also recommend this approach with the bullets.
    For more help, look up arrays and array functions in flash help.

    Post here if you have any more questions, hope this helps =)


    On another note, I dont think the actionscipt or php code thing is working properly. It's not inserting the tabs in the functions or loops automatically. Maybe its just because there is a syntax, or is anyone else noticing this. I had to space the lines myself.

    Testing:
    code:
     if (variable>number) {
    variable = number;
    }

    Last edited by dbarbarian; 06-01-2005 at 01:40 PM.

  6. #6
    Junior Member
    Join Date
    May 2005
    Posts
    4
    I get the basic idea of all the code, I'm just a bit unsure on where to put what. (Sorry I'm very much a, n00b when it comes to actionscript as this is my first real attempt at something like this)

  7. #7
    Banned
    Join Date
    May 2005
    Posts
    36
    i dont work

  8. #8
    Hype over content... Squize's Avatar
    Join Date
    Apr 2001
    Location
    Lost forever in a happy crowd...
    Posts
    5,928
    I try not to as well

    Squize.

  9. #9
    I tried... dbarbarian's Avatar
    Join Date
    Aug 2003
    Location
    Berkeley, California, USA
    Posts
    678
    Quote Originally Posted by pkmnpeter
    i dont work
    Quote Originally Posted by Squize
    I try not to as well

    Squize.


    Edit: Nevermind, i get what you're saying squize.

    Still not sure what pkmnpeter is trying to say...

    As to the code, the array codes, the functions, etc, all go on a frame. The moving function is called on a enter frame on a movie clip so it moves the tie fighter every frame.. The clean function is put wherever you want to clean the code.
    Hope that helps.

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