Esempio n. 1
0
    // A world can be advanced without the players being advanced too. If this is the case
    // then projectile collision boundaries are enlarged automatically to account for
    // lack of knowledge about where players are
    virtual public void Advance(List <WorldAction> actions, bool advancePlayers, bool spawnPowerups)
    {
        // Advance players
        if (advancePlayers)
        {
            Player1.Advance(actions);
            Player2.Advance(actions);
        }

        // Advance spawn timer and spawn powerups
        if (spawnPowerups)
        {
            spawnTimer -= 1;
            if (spawnTimer <= 0 && powerups.Count < 64)
            {
                Powerup.SpawnRandom(this);
                spawnTimer = spawnTimerMax;
            }
        }

        // Advance powerups
        foreach (Powerup powerup in powerups)
        {
            powerup.Advance(null);
        }

        // Advance projectiles
        int len = projectiles.Count;

        for (int i = len - 1; i >= 0; i--)
        {
            Projectile projectile = projectiles[i];

            if (projectile.Type == WeaponType.Minions)
            {
                // Destroy if marked for deletion with a HACK
                if (projectile.Type == WeaponType.None)
                {
                    destroyProjectile(projectile);

                    // Collide with all other projectiles (that are minions)
                }
                else if (i != 0)
                {
                    for (int j = i - 1; j >= 0; j--)
                    {
                        Projectile other      = projectiles[j];
                        bool       didCollide = projectile.CollideWith(other);
                        if (didCollide)
                        {
                            // Destroy both parties involved
                            destroyProjectile(projectile);
                            other.Type = WeaponType.None;                             // Mark other for deletion
                        }
                    }
                }
            }

            // In an AI situation, enlarge players
            bool enlarge = advancePlayers == false;
            projectile.Advance(null, enlarge);
        }

        postUpdate();
    }