Ejemplo n.º 1
0
    void Awake()
    {
        instance = this;

        deathScreen.gameObject.SetActive(false);

        List <Transform> walls = generateMapBounds();

        HumanTankController = Instantiate(humanTankContPrefab, tankRoot, false);
        HumanTankController.Init(
            new Vector3(300, -800, 0),
            0,
            PlayerManager.Instance.TankSchematic);

        Dictionary <string, object> data = DataPasser.Instance.RetrieveData();
        TankSchematic enemyTankSchem     = ((EnemyInfo)data["Opponent"]).TankSchem;

        AITankController = Instantiate(aiTankContPrefab, tankRoot, false);
        AITankController.Init(
            new Vector3(300, 800, 0),
            180f,
            enemyTankSchem,
            HumanTankController.SelfTank,
            walls);

        MainCamera.GetComponent <ObjectFollower>().SetObjToFollow(HumanTankController.SelfTank.gameObject);

        DisableMovement = false;
    }
Ejemplo n.º 2
0
        private List<Vector> GetPathToTarget(AITankController controller)
        {
            Map map = GameProcess.Current_Game.gameMap;

            Vector tCorner = map.GetSectorLocation(controller.Target.AbsoluteCenter);
            Vector pCorner = map.GetSectorLocation(GameProcess.Current_Game.Player.AbsoluteCenter);

            Point start = new Point((int)tCorner.X, (int)tCorner.Y);
            Point goal =  new Point((int)pCorner.X, (int)pCorner.Y);

            List<Point> path = AStarSearch.FindPath(map, start, goal);       

            if (path == null)
            {
                return null;
            }
            else
            {
                List<Vector> vPath = new List<Vector>();

                for (int i = 1; i < path.Count; i++)
                {
                    Vector v = new Vector(map.TileSize * (path[i].X + 0.5), map.TileSize * (path[i].Y + 0.5));
                    vPath.Add(v);
                }

                return vPath;
            }
        }
Ejemplo n.º 3
0
        protected bool IsAttackState(AITankController controller)
        {
            Vector distance = GameProcess.Current_Game.Player.AbsoluteCenter - controller.Target.Gun.AbsoluteCenter;

            if (distance.LengthSquared <= Math.Pow(controller.Target.Gun.MaxFireRange, 2))
            {
                return true;
            }

            return false;
        }
Ejemplo n.º 4
0
 public override void Update(AITankController controller, Int32 dt)
 {
     if (IsAttackState(controller))
     {
         Attack(controller, dt);
     }
     else
     {
         controller.CurrentState = new SearchState();
     }              
 }
Ejemplo n.º 5
0
        public override void Update(AITankController controller, Int32 dt)
        {
            if (!IsAttackState(controller))
            {
                List<Vector> path = GetPathToTarget(controller);

                if (path != null)
                    MoveObject(controller, path, dt);
                else return;
            }
            else
            {
                controller.CurrentState = new AttackState();
            }     
        }
Ejemplo n.º 6
0
        private void Attack(AITankController controller, Int32 dt)
        {
            //Look at situation when direction not updates
            controller.UpdateTargetDirection(new Vector(0, 0), dt);

            Vector direction = GameProcess.Current_Game.Player.AbsoluteCenter - controller.Target.Gun.AbsoluteCenter;
            direction.Normalize();

            controller.UpdateGunDirection(direction, dt);


            if (Math.Abs(controller.Target.Gun.AbsoluteAngle - Controller.DirectionToAngle(direction)) < 5)
                controller.Target.Fire();

           
        }
Ejemplo n.º 7
0
    void OnCollisionEnter2D(Collision2D col)
    {
        if (col.gameObject.tag != "Player")
        {
            if (impactEffect)
            {
                Instantiate(impactEffect, transform.position, transform.rotation);
            }

            UnityEngine.Object.Destroy(gameObject);
        }

        if (col.gameObject.tag == "Enemy")
        {
            AITankController ai = col.gameObject.GetComponent <AITankController>();
            ai.currentHitPoints = ai.currentHitPoints - damage;
        }
    }
Ejemplo n.º 8
0
        private void MoveObject(AITankController controller, List<Vector> path, Int32 dt)
        {
            Vector direction = GameProcess.Current_Game.Player.AbsoluteCenter - controller.Target.Gun.AbsoluteCenter;
            direction.Normalize();

            controller.UpdateGunDirection(direction, dt);

            Vector moveCommand = new Vector(0, 0);

            foreach (Vector pathNode in path)
            {
                Vector nearDistance = pathNode - controller.Target.AbsoluteCenter;

                if (nearDistance.LengthSquared > controller.Target.Engine.translateSpeed.LengthSquared)
                {
                    int delta_angle = (int)(controller.Target.AbsoluteAngle - Controller.DirectionToAngle(nearDistance));

                    if (Math.Abs(delta_angle) > 5)
                    {
                        moveCommand.X = Controller.CalculateRotateSign(delta_angle);
                    }
                    else
                    {
                        moveCommand.Y = 1;
                    }
  
                    controller.UpdateTargetDirection(moveCommand, dt);

                    return;
                }
                else
                {
                    continue;
                }
            } 
        }
Ejemplo n.º 9
0
 public GoInDirAction(Vector2 _requestDir, AITankController controller) : base(controller)
 {
     requestDir = _requestDir;
 }
Ejemplo n.º 10
0
 public RotateAction(Vector2 _alignAngle, Vector2 _requestDir, AITankController _controller) : base(_controller)
 {
     requestDir = _requestDir;
     alignAngle = _alignAngle;
 }
Ejemplo n.º 11
0
        private void OnTriggerEnter(Collider other)
        {
            Collider[] colliders = Physics.OverlapSphere(transform.position, explosionRadius, tankMask);

            // Go through all the colliders...
            for (int i = 0; i < colliders.Length; i++)
            {
                // ... and find their rigidbody.
                Rigidbody targetRigidbody = colliders[i].GetComponent <Rigidbody>();

                // If they don't have a rigidbody, go on to the next collider.
                if (!targetRigidbody)
                {
                    continue;
                }

                // Add an explosion force.
                targetRigidbody.AddExplosionForce(explosionForce, transform.position, explosionRadius);

                // Find the TankHealth script associated with the rigidbody.
                if (targetRigidbody.GetComponent <TankController>())
                {
                    TankController targetHealth = targetRigidbody.GetComponent <TankController>();

                    // Calculate the amount of damage the target should take based on it's distance from the shell.
                    float damage = CalculateDamage(targetRigidbody.position);
                    // Deal this damage to the tank.
                    targetHealth.HandleTakeDamage(damage);
                }
                else if (targetRigidbody.GetComponent <AITankController>())
                {
                    AITankController targetAI = targetRigidbody.GetComponent <AITankController>();

                    // Calculate the amount of damage the target should take based on it's distance from the shell.
                    float damage = CalculateDamage(targetRigidbody.position);
                    // Deal this damage to the tank.
                    targetAI.HandleTakeDamage(damage);
                }
                else
                {
                    // If there is no TankHealth script attached to the gameobject, go on to the next collider.
                    continue;
                }
            }

            if (explosionParticles)
            {
                // Unparent the particles from the shell.
                explosionParticles.transform.parent = null;

                // Play the particle system.
                explosionParticles.Play();
            }

            if (explosionAudio)
            {
                // Play the explosion sound effect.
                explosionAudio.Play();
            }

            if (explosionParticles)
            {
                // Once the particles have finished, destroy the gameobject they are on.
                ParticleSystem.MainModule mainModule = explosionParticles.main;
                Destroy(explosionParticles.gameObject, mainModule.duration);
            }


            // Destroy the shell.
            Destroy(gameObject);
        }
Ejemplo n.º 12
0
 public ManeuverGoal(AITankController _tankController) : base(_tankController)
 {
 }
Ejemplo n.º 13
0
 public AttackGoal(AITankController controller) : base(controller)
 {
 }
Ejemplo n.º 14
0
 public AIAction(AITankController _controller)
 {
     controller = _controller;
 }
Ejemplo n.º 15
0
 public Goal(AITankController _tankController)
 {
     Insistence = 0;
     controller = _tankController;
 }
Ejemplo n.º 16
0
        public virtual void Update(AITankController controller, Int32 dt)
        {

        }
Ejemplo n.º 17
0
 public JetInDirAction(Vector2 _dir, AITankController _controller) : base(_controller)
 {
     dir = _dir;
 }
Ejemplo n.º 18
0
 public DodgeGoal(AITankController _tankController) : base(_tankController)
 {
 }
Ejemplo n.º 19
0
 public FireWeaponAction(int _weaponIdx, AITankController _controller) : base(_controller)
 {
     weaponIdx = _weaponIdx;
 }