Exemplo n.º 1
0
        public override void Update(float dt)
        {
            if (Game.Player != null && Game.Player.HasPowerup(Powerup.FREEZE_TIME))
            {
                return;
            }

            if (Utils.CircleCircleCollision(Obj.Position, Obj.Model.Radius, Game.Hill.Position, Game.Hill.Radius))
            {
                // Reached Hill
                if (Game.Player != null)
                {
                    Game.Player.Damage(1);
                }
                Game.Player.Weapon.Explode(Game.Player.Position, 100f, true);

                return;
            }

            base.Update(dt);
        }
Exemplo n.º 2
0
        /// <param name="radius">If left at -1, will use ExplosionRadius.</param>
        /// <param name="directCall">If true, will not credit kill or activate pick-ups.</param>
        public override void Explode(Vector2f pos, float radius = -1, bool directCall = false)
        {
            if (radius == -1)
            {
                radius = ExplosionRadius;
            }
            // Collision
            bool hitSomething = false;
            int  numChildren  = Game.Layer_Objects.NumChildren;

            for (int i = 0; i < numChildren; i++)
            {
                dynamic obj = Game.Layer_Objects.GetChildAt(i);

                if (obj is PhysicalEntity && !obj.CanTakeDamage)
                {
                    continue;
                }
                if ((!(obj is CollisionEntity) || obj.Collision == null) && !Utils.InCircle(pos, radius, obj.Position)) // Collide with Position if obj is not a CollisionEntity or has no Collision
                {
                    continue;
                }
                if (obj.Collision is CircleShape && !Utils.CircleCircleCollision(pos, radius, obj.Position, obj.Collision.Radius))
                {
                    continue;
                }
                if (obj.Collision is RectangleShape && !Utils.CircleRectangleCollision(pos, radius, obj.Collision, obj.Rotation, obj.Position))
                {
                    continue;
                }

                if (obj is PhysicalEntity)
                {
                    // Damage
                    obj.Damage(Damage, 0, !directCall ? SourceObject : null);
                }
                else if (!directCall && obj is Pickup)
                {
                    // Pickup
                    obj.Activate(SourceObject);
                }

                // Removed?
                if (obj.Parent != Game.Layer_Objects && i <= numChildren - 1)
                {
                    i--;
                    numChildren--;
                }

                hitSomething = true;
            }

            if (hitSomething || Utils.InCircle(Game.Island, pos))
            {
                // Explosion
                Explosion explosion = new Explosion(Game, radius);
                explosion.Position = pos;
                Game.Layer_OtherAbove.AddChild(explosion);

                // Sound
                if (Utils.RandomInt() == 0)
                {
                    ExplosionSound1.Play();
                }
                else
                {
                    ExplosionSound2.Play();
                }
            }
            else
            {
                // Splash
                Explosion explosion = new Explosion(Game, 15);
                explosion.Position = pos;
                Game.Layer_OtherAbove.AddChild(explosion);

                // Sound
                if (Utils.RandomInt() == 0)
                {
                    SplashSound1.Play();
                }
                else
                {
                    SplashSound2.Play();
                }
            }


            if (directCall || Game.Player == null)
            {
                return;
            }
            if (hitSomething)
            {
                Game.Player.IncreaseScoreMultiplier();
            }
            else if (!Game.Player.HasPowerup(Powerup.TRIPLE_CANNON) && !Game.Player.HasPowerup(Powerup.OCTUPLE_CANNON))
            {
                Game.Player.ResetScoreMultiplier();
            }
        }