Пример #1
0
 public void EDGECOLLISION(Particle thing, Rectangle bounds)
 {
     if (thing.Position.Y < bounds.Y)
     {
         thing.Position += new Vector2(0, bounds.Y - thing.Position.Y);
         thing.Velocity *= new Vector2(1, -f_EdgeDamper);
     }
     else if (thing.Position.Y > bounds.Y + bounds.Height)
     {
         thing.Position -= new Vector2(0, thing.Position.Y - (bounds.Y + bounds.Height));
         thing.Velocity *= new Vector2(1, -f_EdgeDamper);
     }
     if (thing.Position.X < bounds.X)
     {
         thing.Position += new Vector2(bounds.X - thing.Position.X, 0);
         thing.Velocity *= new Vector2(-f_EdgeDamper, 1);
     }
     else if (thing.Position.X > bounds.X + bounds.Width)
     {
         thing.Position -= new Vector2(thing.Position.X - (bounds.X + bounds.Width), 0);
         thing.Velocity *= new Vector2(-f_EdgeDamper, 1);
     }
 }
Пример #2
0
        public void COLLISION(Particle particleA, Particle particleB, bool fusion, Game1 game)
        {
            if (particleA.Rectangle.Intersects(particleB.Rectangle))
            {

                if (IntersectPixels(particleB.RectanglePosTransform,
                                    particleB.Texture.Width,
                                    particleB.Texture.Height,
                                    particleB.TextureData,
                                    particleA.RectanglePosTransform,
                                    particleA.Texture.Width,
                                    particleA.Texture.Height,
                                    particleA.TextureData))
                {
                    if (fusion == true)
                    {
                        ship.Tethering = false;
                        tetherState = TetherState.detethered;
                        particleA.ParticleState = Particle.PState.Colliding;
                        particleB.ParticleState = Particle.PState.Colliding;
                        game.soundBank.PlayCue("fusion");
                        particleA.FusionPosition = new Vector2((particleA.Position.X + ((particleB.Position.X - particleA.Position.X) / 2)), (particleA.Position.Y + ((particleB.Position.Y - particleA.Position.Y) / 2)));
                        particleB.FusionPosition = new Vector2((particleB.Position.X + ((particleA.Position.X - particleB.Position.X) / 2)), (particleB.Position.Y + ((particleA.Position.Y - particleB.Position.Y) / 2)));
                    }
                    else if (fusion == false)
                    {
                        Vector2 impactSpeed;
                        Vector2 impulse;
                        float resultantImpulse;

                        impactSpeed = particleB.Velocity - particleA.Velocity;
                        impulse = Vector2.Normalize(particleB.Position - particleA.Position);
                        resultantImpulse = Vector2.Dot(impulse, impactSpeed);
                        if (resultantImpulse < 0)
                        {
                            resultantImpulse *= -1;
                        }
                        impulse = impulse * (float)Math.Sqrt(resultantImpulse);

                        particleB.Velocity += impulse;
                        particleA.Velocity -= impulse;
                    }
                }
            }
        }
Пример #3
0
        public void COLLISION(Enemy enemy, Particle particle)
        {
            if (enemy.Rectangle.Intersects(particle.Rectangle))
            {

                if (IntersectPixels(particle.RectanglePosTransform,
                                    particle.Texture.Width,
                                    particle.Texture.Height,
                                    particle.TextureData,
                                    enemy.RectanglePosTransform,
                                    enemy.Texture.Width,
                                    enemy.Texture.Height,
                                    enemy.TextureData))
                {
                    if (enemy.closestParticle != null)
                    {
                        if (enemy.closestParticle == particle)
                        {
                            particle.BeingAttacked = true;
                            particle.Attacker = enemy;
                            enemy.attacking = true;
                        }
                    }
                    else
                    {

                        Vector2 impactSpeed;
                        Vector2 impulse;
                        float resultantImpulse;

                        impactSpeed = particle.Velocity - enemy.Velocity;
                        impulse = Vector2.Normalize(particle.Position - enemy.Position);
                        resultantImpulse = Vector2.Dot(impulse, impactSpeed);
                        if (resultantImpulse < 0)
                        {
                            resultantImpulse *= -1;
                        }
                        impulse = impulse * (float)Math.Sqrt(resultantImpulse);

                        particle.Velocity += impulse;
                        //enemy.Velocity -= impulse; //enemies aren't affected by particle collisions :P
                    }
                }
            }
        }
Пример #4
0
        public void COLLISION(Ship ship, Particle particle)
        {
            if (particle.IsTethered == true)
            {
                if (ship.BoundSphere.Intersects(new BoundingSphere(new Vector3(particle.Position, 0), (particle.Texture.Width / 2))))
                {
                    particle.Velocity *= -0.5f;
                }
            }
            else
            {
                if (ship.Rectangle.Intersects(particle.Rectangle))
                {
                    if (IntersectPixels(particle.RectanglePosTransform,
                                        particle.Texture.Width,
                                        particle.Texture.Height,
                                        particle.TextureData,
                                        ship.RotationTransform,
                                        ship.Texture.Width,
                                        ship.Texture.Height,
                                        ship.TextureData))
                    {
                        if (particle.BeingAttacked == false)
                        {
                            i_VibrateCounter++;

                            Vector2 impactSpeed;
                            Vector2 impulse;
                            float resultantImpulse;

                            impactSpeed = particle.Velocity - ship.Velocity;
                            impulse = Vector2.Normalize(particle.Position - ship.Position);
                            resultantImpulse = Vector2.Dot(impulse, impactSpeed);
                            if (resultantImpulse < 0)
                            {
                                resultantImpulse *= -1;
                            }
                            impulse = impulse * (float)Math.Sqrt(resultantImpulse);

                            particle.Velocity += impulse;
                        }
                    }
                }
            }
        }
Пример #5
0
        public void COLLISION(Bullet tether, Particle particle, int ID, bool isAPhoton, Game1 game)
        {
            if (tetherState == TetherState.shooting)
            {
                if (tether.Rectangle.Intersects(particle.Rectangle))
                {
                    if (IntersectPixels(particle.RectanglePosTransform,
                                        particle.Texture.Width,
                                        particle.Texture.Height,
                                        particle.TextureData,
                                        tether.RectanglePosTransform,
                                        tether.Texture.Width,
                                        tether.Texture.Height,
                                        tether.TextureData))
                    {
                        if (particle.ParticleState == Particle.PState.Alive && particle.BeingAttacked == false)
                        {
                            particle.Color = Color.Aqua;
                            ship.TetheredParticleID = ID;
                            ship.IsPhoton = isAPhoton;
                            ship.Tethering = true;
                            particle.IsTethered = true;
                            tether.Alive = false;
                            tetherState = TetherState.tethered;
                            game.soundBank.PlayCue("tethered");

                            if (particle.Attacker != null)
                            {
                                particle.Attacker.i_KillingCounter = 0;
                                particle.Attacker.f_colour = 1.0f;
                                particle.Attacker.attacking = false;
                                particle.Attacker.f_Rotation = 0;
                            }
                            particle.BeingAttacked = false;
                            particle.Attacker = null;
                            if (particle.IsTethered == false)
                            {
                                particle.Color = Color.White;
                            }
                        }
                    }
                }
            }
        }
Пример #6
0
 public void UpdateParticleKill(Vector2 collision, Particle particle, Enemy enemy)
 {
     enemy.ParticleKill.AddParticles((collision - new Vector2((particle.Texture.Width / 2), (particle.Texture.Width / 4))), new Vector2(0, 0), ship.Position, 0, true);
 }
Пример #7
0
 public void UpdateFusionEffect(Vector2 collision, Particle particle)
 {
     particle.Fusion.AddParticles((collision - new Vector2((particle.Texture.Width / 2), (particle.Texture.Width / 4))), new Vector2(0, 0), ship.Position, 0, true);
 }
Пример #8
0
        public void Update(GameTime gameTime, SoundBank soundBank, Game1 game)
        {
            if (game.gameState != State.Tutorial)
            {
                SegmentUpdate();

                if (Ambient.IsPlaying == false)
                {
                    Ambient.Play();
                }
                else if (Ambient.IsPaused == true)
                {
                    Ambient.Resume();
                }
                if (f_Fusions >= loadedLevel.levelData.i_TargetFusions)
                {
                    game.i_GameOverSel = 1;
                    game.f_LevelCompleteBonus = 500;
                    game.fd_Fader.BeginFadingToBlack(75, true, game);
                }
                if (dt_timer.Minute == 0 && dt_timer.Second == 0)
                {
                    game.fd_Fader.BeginFadingToBlack(75, true, game);
                }
                else
                {
                    dt_timer -= gameTime.ElapsedGameTime;
                }

                offset = ship.OffsetUpdate(offset);
                if (dead == true)
                {
                    UpdateExplosion(ship.Position);
                }
                #region Enemy Spawn and Update
                for (int i = 0; i < loadedLevel.levelData.i_MaxNumberEnemies; i++)
                {
                    if (enemies[i].EnemyCollision == true)
                    {
                        UpdateShieldSpark(enemies[i].EnemyCollisionPosition, enemies[i]);
                        enemies[i].ShieldSparkCounter++;
                        if (enemies[i].ShieldSparkCounter == 40)
                        {
                            enemies[i].EnemyCollision = false;
                            enemies[i].ShieldSparkCounter = 0;
                        }
                    }

                    if (enemies[i].IsParticleKill == true)
                    {
                        UpdateParticleKill(enemies[i].ParticleKillPosition, enemies[i].p_ParticleKilled, enemies[i]);
                        enemies[i].ParticleKillCounter++;
                        if (enemies[i].ParticleKillCounter == 40)
                        {
                            enemies[i].IsParticleKill = false;
                            enemies[i].ParticleKillCounter = 0;
                        }
                    }

                    if (enemies[i].Alive == true)
                    {
                        enemies[i].updatePosition((float)gameTime.ElapsedGameTime.TotalSeconds, f_Friction);
                    }
                    else if (enemies[i].SpawnTimer == loadedLevel.levelData.i_EnemySpawnRate)
                    {
                        enemies[i] = new Enemy(game, loadedLevel);
                        enemies[i].LoadTexture(game.Content);
                        enemies[i].Spawn(offset, loadedLevel.levelBounds);
                        enemies[i].SpawnTimer = 0;
                        enemies[i].Rectangle = new Rectangle(((int)enemies[i].Position.X - (enemies[i].Texture.Width / 2)), ((int)enemies[i].Position.Y - (enemies[i].Texture.Height / 2)), enemies[i].Texture.Width, enemies[i].Texture.Height);
                        enemies[i].TextureData = new Color[enemies[i].Texture.Width * enemies[i].Texture.Height];
                        enemies[i].Texture.GetData(enemies[i].TextureData);
                    }
                }
                for (int i = 0; i < loadedLevel.levelData.i_MaxNumberEnemies; i++)
                {
                    if (enemies[i].Alive == false)
                    {
                        enemies[i].SpawnTimer++;
                        break;
                    }
                }
                #endregion
                #region Particles Spawning

                for (int i = 0; i < Photons.Length; i++)
                {
                    if (Photons[i].ParticleState == Particle.PState.Fusing)
                    {
                        if (Photons[i].i_Fusing > 50)
                        {
                            Photons[i].ParticleState = Particle.PState.Dead;
                            Photons[i].i_Fusing = 0;
                        }
                        else
                        {
                            Photons[i].i_Fusing++;
                        }
                    }
                    else if (Photons[i].ParticleState == Particle.PState.Colliding)
                    {
                        Photons[i].Velocity = new Vector2((((Photons[i].FusionPosition.X - Photons[i].Position.X) / Vector2.Distance(Photons[i].Position, Photons[i].FusionPosition)) * 10), (((Photons[i].FusionPosition.Y - Photons[i].Position.Y) / Vector2.Distance(Photons[i].Position, Photons[i].FusionPosition)) * 10));
                        Photons[i].updatePosition((float)gameTime.ElapsedGameTime.TotalSeconds, f_Friction);
                        if (Photons[i].Position.X < (Photons[i].FusionPosition.X + 1) && Photons[i].Position.X > (Photons[i].FusionPosition.X - 1) && Photons[i].Position.Y < (Photons[i].FusionPosition.Y + 1) && Photons[i].Position.Y > (Photons[i].FusionPosition.Y - 1))
                        {
                            for (int j = 0; j < loadedLevel.levelData.i_MaxNumberFused; j++)
                            {
                                if (Fused[j].ParticleState == Particle.PState.Dead)
                                {
                                    Fused[j].ParticleState = Particle.PState.Spawning;
                                    Photons[i].ParticleState = Particle.PState.Fusing;
                                    Fused[j].Position = Photons[i].Position;
                                    break;
                                }
                            }
                        }
                    }
                    else if (Photons[i].ParticleState == Particle.PState.Alive)
                    {
                        if (Photons[i].IsTethered)
                        {
                            if (!ship.BoundSphere.Intersects(new BoundingSphere(new Vector3(Photons[i].Position, 0), (Photons[i].Texture.Width / 2))))
                            {
                                Vector2 distance = ship.Position - Photons[i].Position;
                                Photons[i].Velocity += Vector2.Normalize(distance) * 20;
                            }
                        }
                        else
                        {
                            Photons[i].Position -= new Vector2(0, 0.07f);
                        }
                        Photons[i].updatePosition((float)gameTime.ElapsedGameTime.TotalSeconds, f_Friction);
                    }
                    else if (Photons[i].ParticleState == Particle.PState.Spawning)
                    {
                        if (Photons[i].Scale > 1)
                        {
                            Photons[i].Scale = 1.0f;
                            Photons[i].ParticleState = Particle.PState.Alive;
                        }
                        else
                        {
                            Photons[i].Scale += 0.02f;
                        }
                    }
                    else if (Photons[i].SpawnTimer == loadedLevel.levelData.i_PhotonSpawnRate)
                    {
                        Photons[i] = new Particle(loadedLevel.levelBounds);
                        Photons[i].LoadTex(t_Photon);
                        Photons[i].ParticleState = Particle.PState.Spawning;
                        Photons[i].Spawn(offset, loadedLevel.levelBounds, true);
                        Photons[i].SpawnTimer = 0;
                        soundBank.PlayCue("photonPop");
                    }
                }

                for (int i = 0; i < Chlor.Length; i++)
                {
                    if (Chlor[i].ParticleState == Particle.PState.Fusing)
                    {
                        if (Chlor[i].i_Fusing > 50)
                        {
                            Chlor[i].ParticleState = Particle.PState.Dead;
                            Chlor[i].i_Fusing = 0;
                        }
                        else
                        {
                            Chlor[i].i_Fusing++;
                        }
                    }
                    else if (Chlor[i].ParticleState == Particle.PState.Colliding)
                    {
                        Chlor[i].Velocity = new Vector2((((Chlor[i].FusionPosition.X - Chlor[i].Position.X) / Vector2.Distance(Chlor[i].Position, Chlor[i].FusionPosition)) * 10), (((Chlor[i].FusionPosition.Y - Chlor[i].Position.Y) / Vector2.Distance(Chlor[i].Position, Chlor[i].FusionPosition)) * 10));
                        Chlor[i].updatePosition((float)gameTime.ElapsedGameTime.TotalSeconds, f_Friction);

                        if (Chlor[i].Position.X < (Chlor[i].FusionPosition.X + 1) && Chlor[i].Position.X > (Chlor[i].FusionPosition.X - 1) && Chlor[i].Position.Y < (Chlor[i].FusionPosition.Y + 1) && Chlor[i].Position.Y > (Chlor[i].FusionPosition.Y - 1))
                        {
                            Chlor[i].ParticleState = Particle.PState.Fusing;
                        }
                    }
                    else if (Chlor[i].ParticleState == Particle.PState.Alive)
                    {
                        if (Chlor[i].IsTethered)
                        {
                            if (!ship.BoundSphere.Intersects(new BoundingSphere(new Vector3(Chlor[i].Position, 0), (Chlor[i].Texture.Width / 2))))
                            {
                                Vector2 distance = ship.Position - Chlor[i].Position;
                                Chlor[i].Velocity += Vector2.Normalize(distance) * 20;
                            }
                        }
                        else
                        {
                            Chlor[i].Position += new Vector2(0, 0.07f);
                        }
                        Chlor[i].updatePosition((float)gameTime.ElapsedGameTime.TotalSeconds, f_Friction);
                    }
                    else if (Chlor[i].ParticleState == Particle.PState.Spawning)
                    {
                        if (Chlor[i].Scale > 1)
                        {
                            Chlor[i].Scale = 1.0f;
                            Chlor[i].ParticleState = Particle.PState.Alive;
                        }
                        else
                        {
                            Chlor[i].Scale += 0.02f;
                        }
                    }
                    else if (Chlor[i].SpawnTimer == loadedLevel.levelData.i_ChloroSpawnRate)
                    {
                        Chlor[i] = new Particle(loadedLevel.levelBounds);
                        Chlor[i].LoadTex(t_Chlor);
                        Chlor[i].ParticleState = Particle.PState.Spawning;
                        Chlor[i].Spawn(offset, loadedLevel.levelBounds, false);
                        Chlor[i].SpawnTimer = 0;
                        soundBank.PlayCue("chlorPop");
                    }
                }

                for (int i = 0; i < loadedLevel.levelData.i_MaxNumberPhotons; i++)
                {
                    if (Photons[i].ParticleState == Particle.PState.Dead)
                    {
                        Photons[i].SpawnTimer++;
                        break;
                    }
                }
                for (int i = 0; i < loadedLevel.levelData.i_MaxNumberChloro; i++)
                {
                    if (Chlor[i].ParticleState == Particle.PState.Dead)
                    {
                        Chlor[i].SpawnTimer++;
                        break;
                    }
                }
                #endregion
            }

            GamePlay(gameTime, game);
        }
Пример #9
0
        public void InitalizeLevel(Level level, Game1 game)
        {
            loadedLevel = level;

            f_Fusions = 0;
            i_ShieldPulseCounter = 0;
            i_shipAlpha = 0.5f;
            i_PulseRate = 60;

            enemies = new Enemy[loadedLevel.levelData.i_MaxNumberEnemies];
            for (int j = 0; j < loadedLevel.levelData.i_MaxNumberEnemies; j++)
            {
                enemies[j] = new Enemy(game, loadedLevel);
                enemies[j].LoadTexture(game.Content);
                enemies[j].Rectangle = new Rectangle(((int)enemies[j].Position.X - (enemies[j].Texture.Width / 2)), ((int)enemies[j].Position.Y - (enemies[j].Texture.Height / 2)), enemies[j].Texture.Width, enemies[j].Texture.Height);
                enemies[j].TextureData = new Color[enemies[j].Texture.Width * enemies[j].Texture.Height];
                enemies[j].Texture.GetData(enemies[j].TextureData);
                enemies[j].ShieldSpark = new ShieldSparkParticleSystem(game, 3);
                game.Components.Add(enemies[j].ShieldSpark);
                enemies[j].ParticleKill = new ParticleKillParticleSystem(game, 4);
                game.Components.Add(enemies[j].ParticleKill);
            }

            Fused = new Particle[loadedLevel.levelData.i_MaxNumberFused];
            for (int j = 0; j < loadedLevel.levelData.i_MaxNumberFused; j++)
            {
                Fused[j] = new Particle(loadedLevel.levelBounds);
                Fused[j].Fusion = new FusionParticleSystem(game, 20);
                game.Components.Add(Fused[j].Fusion);
                Fused[j].LoadTex(t_Fused);
            }

            Photons = new Particle[loadedLevel.levelData.i_MaxNumberPhotons];
            for (int j = 0; j < loadedLevel.levelData.i_MaxNumberPhotons; j++)
            {
                Photons[j] = new Particle(loadedLevel.levelBounds);
                Photons[j].LoadTex(t_Photon);
                Photons[j].Fusion = new FusionParticleSystem(game, 20);
                game.Components.Add(Photons[j].Fusion);
            }
            Chlor = new Particle[loadedLevel.levelData.i_MaxNumberChloro];
            for (int j = 0; j < loadedLevel.levelData.i_MaxNumberChloro; j++)
            {
                Chlor[j] = new Particle(loadedLevel.levelBounds);
                Chlor[j].LoadTex(t_Chlor);
                Chlor[j].Fusion = new FusionParticleSystem(game, 20);
                game.Components.Add(Chlor[j].Fusion);
            }

            bullets = new Bullet[i_BulletMax];
            tethers = new Bullet[i_BulletMax];
            for (int j = 0; j < i_BulletMax; j++)
            {
                bullets[j] = new Bullet(t_Bullet);
                tethers[j] = new Bullet(t_Tether);
            }
            stupidline = new Bullet[i_StupidLineMax];
            for (int j = 0; j < i_StupidLineMax; j++)
            {
                stupidline[j] = new Bullet(t_Tether);
            }

            ship = new Ship(500, 350, t_Ship);
            ship.Turret = game.Content.Load<Texture2D>("Ship//turret");
            tetherState = TetherState.shooting;

            offset = ship.OffsetUpdate(offset);
            engineSmoke = new EngineParticleSystem(game, 9);
            game.Components.Add(engineSmoke);
            shipExplosion = new ExplosionParticleSystem(game, 9);
            game.Components.Add(shipExplosion);
        }
Пример #10
0
        public void EnemyMovement(Ship ship, Engine engine)
        {
            if (ed_EnemyData.t_Type == EnemyData.Type.Normal)
            {
                MoveTowardsPlayer(ship);
            }
            else if (ed_EnemyData.t_Type == EnemyData.Type.Destroyer)
            {
                if (attacking == false)
                {
                    float currentDistance = 99999;
                    for (int i = 0; i < engine.Photons.Length; i++)
                    {
                        float distance = Vector2.Distance(engine.Photons[i].Position, Position);
                        if ((distance < currentDistance) && engine.Photons[i].BeingAttacked == false && engine.Photons[i].ParticleState == Particle.PState.Alive && engine.Photons[i].IsTethered == false)
                        {
                            currentDistance = distance;
                            closestParticle = engine.Photons[i];
                        }
                    }
                    for (int i = 0; i < engine.Chlor.Length; i++)
                    {
                        float distance = Vector2.Distance(engine.Chlor[i].Position, Position);
                        if (distance < currentDistance && engine.Chlor[i].BeingAttacked == false && engine.Chlor[i].ParticleState == Particle.PState.Alive && engine.Chlor[i].IsTethered == false)
                        {
                            currentDistance = distance;
                            closestParticle = engine.Chlor[i];
                        }
                    }

                    if (closestParticle != null)
                    {
                        vVelocity.X = (((closestParticle.Position.X - vPosition.X) / Vector2.Distance(vPosition, closestParticle.Position)) * ed_EnemyData.f_Speed);
                        vVelocity.Y = (((closestParticle.Position.Y - vPosition.Y) / Vector2.Distance(vPosition, closestParticle.Position)) * ed_EnemyData.f_Speed);
                    }
                    else
                    {
                        MoveTowardsPlayer(ship);
                    }
                }
                else if (attacking == true)
                {

                    vVelocity.X = (((closestParticle.Position.X - vPosition.X) / Vector2.Distance(vPosition, closestParticle.Position)) * ed_EnemyData.f_Speed);
                    vVelocity.Y = (((closestParticle.Position.Y - vPosition.Y) / Vector2.Distance(vPosition, closestParticle.Position)) * ed_EnemyData.f_Speed);

                    if (i_KillingCounter < 250)
                    {
                        f_Rotation += 0.15f;
                        i_KillingCounter++;
                        f_colour -= 0.004f;
                        closestParticle.Color = new Color(1.0f, f_colour, f_colour, 1.0f);
                    }
                    else
                    {
                        f_Rotation = 0;
                        i_KillingCounter = 0;
                        f_colour = 1.0f;
                        p_ParticleKilled = closestParticle;
                        ParticleKillPosition = closestParticle.Position + new Vector2((closestParticle.Texture.Width / 2), (closestParticle.Texture.Height / 2));
                        closestParticle.ParticleState = Particle.PState.Dead;
                        attacking = false;
                        IsParticleKill = true;
                    }
                }
            }
        }