Exemple #1
0
 public void ExecuteStep(GridNode cur_node, GridNode tar_node, EnemyLogic me, GameObject target)
 {
     me.CheckTileForDanger();
     if (m_canShoot == true)
     {
         GameObject bullet = GameObject.Instantiate(Resources.Load <GameObject>("Prefabs/bullet"), Vector3.zero, Quaternion.identity);
         bullet.GetComponent <bullet>().createBullet(me.currentNode.GetNeighbour(me.direction), me.direction);
     }
 }
Exemple #2
0
        private void ValidateMove(EnemyLogic me)
        {
            bool moveSafe = true;

            me.CheckTileForDanger();

            const int CheckNum = 4;

            // get node offsets
            Vector2Int[] offsets = new Vector2Int[CheckNum - 1];

            offsets[0] = new Vector2Int(me.direction.x - me.direction.y, me.direction.x + me.direction.y);
            offsets[1] = new Vector2Int(me.direction.x * 2, me.direction.y * 2);
            offsets[2] = new Vector2Int(me.direction.x + me.direction.y, me.direction.y - me.direction.x);

            // get nodes at offsets
            GridNode[] nodes = new GridNode[CheckNum];

            nodes[0] = me.currentNode.GetNeighbour(offsets[0]);
            nodes[1] = me.currentNode.GetNeighbour(offsets[1]);
            nodes[2] = me.currentNode.GetNeighbour(offsets[2]);
            nodes[3] = me.currentNode.GetNeighbour(me.direction);

            // get danger vectors for each node
            Vector2Int[] dangerVectors = new Vector2Int[CheckNum];

            dangerVectors[0] = new Vector2Int(me.direction.y, -me.direction.x);
            dangerVectors[1] = new Vector2Int(-me.direction.x, -me.direction.y);
            dangerVectors[2] = new Vector2Int(-me.direction.y, me.direction.x);
            dangerVectors[3] = dangerVectors[1];

            // check nodes for bullets with certain velocity
            GameObject[] bullets = new GameObject[CheckNum];

            for (int i = 0; i < CheckNum; i++)
            {
                if (nodes[i] != null && nodes[i].HasObjectOfType <bullet>(ref bullets[i]))
                {
                    if (bullets[i] != null && bullets[i].GetComponent <bullet>().m_direction != null && (bullets[i].GetComponent <bullet>().m_direction == dangerVectors[i]))
                    {
                        moveSafe = false;
                        bullets[i].GetComponent <bullet>().BulletDestroy();
                    }
                }
            }

            // determine whether move is safe
            if (!moveSafe)
            {
                me.controller.Hit(null, 1);
                //if (me.hp <= 0)
                //    me.m_isDead = !moveSafe;
            }
        }