예제 #1
0
 public bool CheckCircle(BasicShipGameObject g, Vector2 StartPosition, Vector2 EndPosition, float LineWidth)
 {
     return(Logic.DistanceLineSegmentToPoint(StartPosition, EndPosition, g.getPosition()) < (g.getSize().X + AttackLineWidth) / 2);
 }
        public virtual void Collide(GameTime gameTime, BasicShipGameObject Other)
        {
            if (Other == null)
            {
                return;
            }

            if (!Dead && !Other.Dead && !Other.IsAlly(this) && FreezeTime < 0 && Other.GetType().IsSubclassOf(typeof(UnitBasic)))
            {
                UnitBasic u = (UnitBasic)Other;
                if (u.FreezeTime < 0)
                {
                    Vector3 Position3 = new Vector3((Position.X() + Other.Position.X()) / 2, Y, (Position.Y() + Other.Position.Y()) / 2);
                    if (CollisionSound.Equals("") && u.CollisionSound.Equals(""))
                    {
                        SoundManager.Play3DSound("CollisionImpact", Position3, 0.5f, 300, 2);
                    }
                    else
                    {
                        SoundManager.Play3DSound(CollisionSound.Equals("") ? u.CollisionSound : CollisionSound,
                                                 Position3, 0.5f, 300, 2);
                    }


                    Damage(Other.fieldState != FieldState.SpeedBoost || Other.FieldStateTime < 1 ? Other.CollisionDamage : Other.CollisionDamage * 1.25f
                           , 5, Position.get() - Other.Position.get(), Other, AttackType.Melee);

                    Other.Damage(fieldState != FieldState.SpeedBoost || FieldStateTime < 1 ? CollisionDamage : CollisionDamage * 1.25f
                                 , 5, Other.Position.get() - Position.get(), this, AttackType.Melee);

                    if (!GetType().IsSubclassOf(typeof(UnitBuilding)))
                    {
                        FreezeTime = Math.Max(FreezeTime, Other.CollisionFreezeTime);
                        StunState  = AttackType.Melee;
                    }
                    if (!u.GetType().IsSubclassOf(typeof(UnitBuilding)))
                    {
                        u.FreezeTime = Math.Max(u.FreezeTime, CollisionFreezeTime);
                        u.StunState  = AttackType.Melee;
                    }
                }
            }

            float MoveAmount = (Size.X() + Other.getSize().X) / 2 - Vector2.Distance(Other.Position.get(), Position.get());

            if (Other.Moveable)
            {
                CollisionIteration++;
                if (CollisionIteration > 10000)
                {
                    CollisionIteration = 0;
                }

                UnitBasic u = (UnitBasic)Other;
                if (Vector2.Distance(u.Position.get(), Position.get()) > 0.1f)
                {
                    u.Push(u.Position.get() + Vector2.Normalize(Other.Position.get() - Position.get()) * MoveAmount / 2, 0);
                    Push(Position.get() + Vector2.Normalize(Position.get() - Other.Position.get()) * MoveAmount / 2, 0);
                }
                else
                {
                    u.Push(u.Position.get() + Vector2.One * MoveAmount, 0);
                    Push(Position.get() - Vector2.One * MoveAmount, 0);
                }
            }
            else
            {
                if (Vector2.Distance(Other.Position.get(), Position.get()) > 0.1f)
                {
                    Push(Position.get() + Vector2.Normalize(Position.get() - Other.Position.get()) * MoveAmount, MoveAmount);
                }
                else
                {
                    Push(Position.get() + Vector2.One * MoveAmount * 2, MoveAmount * 2);
                }
            }
        }