mardi 21 juin 2016

How to give differents directions of bullets on one array?

im very new on javascript, i was doing a ship gaming that you have to kill some asteroids, and when you take some differents of "objects" on the screen we expand our number of bullets. Okey, going to the point i could get 3 bullets on the screen when you take diffirents objects, but now i want to give 2 of that 3 bullets of the array different directions. When i tried, i have the problem that i give the 3 bullets the same direction, i know why but im for at least 5hrs trying to fix this and i cant.

Im programming on Flash Builder 4.7 with different classes, i ll give the code of the array who is in the main, and the bullet class so as the hero class too.

Main Array

public function evUpdateBullet():void//here execute update of my class Bullets
    {
        var i:int;
        for(i=myBullets.length-1; i >= 0; i--)
        {
            if(myBullets != null) //to be ?
            {
                if(myBullets[i].isDestroyed) //is destroyed Bullets?
                {
                    myBullets[i] = null;
                    myBullets.splice(i, 1); //deleted elements.
                }else
                {

                    myBullets[i].evUpdate();





                }
            }
        }
    }

here i push the array and create the bullet, remember myBullets is the name of the array.

public function evShoot(posX:int, posY:int):void//here create the bullet and push in the array
    {
        attack1 = new Bullet;
        attack1.Spawn(posX, posY);
        myBullets.push(attack1);

}

here i show the Hero code, where i define the position of the bullet is going to spawn on the screen.

if (isPressing_Shoot && !isDestroyed)// Here execute the event shoot without power
        {
            Main.instace.evShoot(model.x, model.y);


            isPressing_Shoot = false;
            canShoot = false;

        }


        evDestroyed();
    }

here is the code from Bullet class

first the spawn

public function Spawn(posX:int, posY:int):void
    {
        isDestroyed = false;//first parameter of my bullet

        model = new MCbullet;
        Main.layer1.addChild(model);//painting the hero in the stage
        model.x = posX;//position in the stage wiht the hero
        model.y = posY;
        model.tigger.visible = false;

    }

then the Update

public function evUpdate():void//here conect with update general
    {
        if (model != null)//to be?
        {

            model.y -= 12;//move of my bullet
            //model.x -= 12;





            if (model.y <= 0 )
            {
                evDestroyed();
            }
        }

    }

in this update i set the movement of y, so i can shoot vertically, but.. when i try to add an x.move, i do for the all array, so i want to know how i can give different move, for differents bullets of the same array.

Aucun commentaire:

Enregistrer un commentaire