Example #1
0
 public override void Attack(RTSObject enemy)
 {
     if (enemy != null && enemy.currentHP > 0 && !attack.IsAttack)
     {
         Enemy = enemy;
         attack.AttackEnemy(enemy);
     }
 }
Example #2
0
 private bool CompareSideUnits(RTSObject obj1, RTSObject obj2)
 {
     if (obj1.side == obj2.side)
     {
         return(true);
     }
     return(false);
 }
Example #3
0
        public Vector2 Separate(List <CollisionObject> collisions, RTSObject unit, float maxSpeed, Vector2 velocity, float maxForce, ref int count)
        {
            Vector2 sum = Vector2.zero;

            count = 0;
            bool storm = false;

            foreach (CollisionObject col in collisions)
            {
                if (col.GetType() != typeof(Maelstorm))
                {
                    float SoftSeparation = unit.SoftRadius + col.SoftRadius;
                    float HardSeparation = unit.HardRadius + col.HardRadius;

                    float d = Vector2.Distance(unit.ObjectTransform.position, col.ObjectTransform.position);

                    if (d > 0 && d <= SoftSeparation)
                    {
                        float force = 0.25f;
                        if (d <= HardSeparation)
                        {
                            unit.OnDead();
                            return(Vector2.zero);
                        }
                        Vector2 diff = unit.ObjectTransform.position - col.ObjectTransform.position;
                        diff.Normalize();
                        diff /= d;
                        diff *= force;
                        sum  += diff;
                        count++;
                    }
                }
                else
                {
                    storm = true;
                }
            }
            if (count > 0 || storm)
            {
                sum /= count;
                sum.Normalize();
                sum *= maxSpeed;
                Vector2 steer = sum - velocity;
                steer = Limited(steer, maxForce);
                return(steer);
            }
            else
            {
                return(Vector2.zero);
            }
        }
Example #4
0
        void StartShoot(RTSObject Enemy)
        {
            Vector3    startPosition  = new Vector3(rtsObject.ObjectTransform.position.x + rtsObject.HardRadius / 3, rtsObject.ObjectTransform.position.y + rtsObject.HardRadius / 3, -0.5f);         //стрелям с края борта
            CannonBall currentball    = cannonbal.Spawn(startPosition);
            Vector3    FinishPosition = new Vector3(Enemy.ObjectTransform.position.x + Random.Range(-Enemy.HardRadius / 2, Enemy.HardRadius / 2),
                                                    Enemy.ObjectTransform.position.y + Random.Range(-Enemy.HardRadius / 2, Enemy.HardRadius / 2), -0.5f);                                              //стреляем в случайное место на корабле

            Vector2 directionVector = FinishPosition - startPosition;
            float   angle           = Mathf.Atan2(directionVector.y, directionVector.x) * Mathf.Rad2Deg - 90;

            currentball.transform.rotation = Quaternion.AngleAxis(angle, Vector3.forward);

            currentball.Finish = FinishPosition;
        }
Example #5
0
 public override void Attack(RTSObject enemy)
 {
     attack.AttackEnemy(enemy);
 }
Example #6
0
 public void AttackEnemy(RTSObject enemy)
 {
     isAttack = true;
     Enemy    = enemy;
 }
Example #7
0
 public abstract void Attack(RTSObject enemy);