private void CheckCollision(EnemyLogic me) { const int CheckNum = 4; Vector2Int[] offsets = new Vector2Int[CheckNum]; offsets[0] = new Vector2Int(1, 0); offsets[1] = new Vector2Int(-1, 0); offsets[2] = new Vector2Int(0, 1); offsets[3] = new Vector2Int(0, -1); 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(offsets[3]); 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 == (offsets[i] * -1))) { me.m_isDead = true; bullets[i].GetComponent <bullet>().BulletDestroy(); } } } }
public void ExecuteStep(GridNode cur_node, GridNode tar_node, EnemyLogic me, GameObject target) { MortarEnemy mortar_me = (MortarEnemy)me; mortar_me.state = MortarEnemy.State.IDLE; mortar_me.m_drawGizmos = false; }
private void Awake() { m_gridRef = GameObject.Find("Grid").GetComponent <TileGrid>(); m_brain = gameObject.GetComponent <EnemyLogic>(); GetComponent <SpriteRenderer>().sprite = Resources.Load <Sprite>("GFX/Enemies/" + m_brain.GetType().Name); }
public void ReflectIncoming(EnemyLogic me) { Vector2Int[] offsets = GetOffsets(); //Vector2Int[] offsets = new Vector2Int[CheckNum]; //offsets[0] = new Vector2Int( 1, 0); //offsets[1] = new Vector2Int(-1, 0); //offsets[2] = new Vector2Int( 0, 1); //offsets[3] = new Vector2Int( 0,-1); GridNode[] nodes = GetNodes(me.currentNode, 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(offsets[3]); GameObject[] bullets = new GameObject[CheckNum]; for (int i = 0; i < CheckNum; i++) { if (nodes[i].HasObjectOfType <bullet>(ref bullets[i])) { if (bullets[i] != null && (bullets[i].GetComponent <bullet>().m_direction == (offsets[i] * -1))) { bullets[i].GetComponent <bullet>().m_direction *= -1; } } } }
public void ExecuteStep(GridNode cur_node, GridNode tar_node, EnemyLogic me, GameObject target) { me.StartCoroutine(BlockColourFlash(me.gameObject, 0.1f)); //MoveAlongPathAction.GetDirection(me); //me.controller.CheckForCollisionsStationary(GetNodes(me.currentNode,GetOffsets()),GetDangerVectors(GetOffsets())); ReflectIncoming(me); //me.CheckTileForDanger(); }
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); } }
public void CalculateStep(GridNode cur_node, GridNode tar_node, EnemyLogic me, GameObject target) { me.direction = Vector2Int.zero; // Step 1: get direction of movement GetDirection(me); //Step 2: check if move is valid ValidateMove(me); }
public void CalculateStep(GridNode cur_node, GridNode tar_node, EnemyLogic me, GameObject target) { me.direction = Vector2Int.zero; GetDirection(me); CheckCollision(me); ValidateShoot(me); }
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; } }
private void ValidateShoot(EnemyLogic me) { if (!me.currentNode.GetNeighbour(me.direction).HasObjectOfType <bullet>()) { m_canShoot = true; } else { m_canShoot = false; } }
public void ExecuteStep(GridNode cur_node, GridNode tar_node, EnemyLogic me, GameObject target) { cur_node = me.currentNode; tar_node = cur_node.GetNeighbour(Vector2Int.RoundToInt(me.direction)); me.currentNode.RemoveObject(me.gameObject); me.currentNode = tar_node; me.currentNode.AddObject(me.gameObject); LeanTween.move(me.gameObject, GameObject.Find("Grid").GetComponent <TileGrid>().GridCoordToWorldCoord(me.currentNode.position), 0.1f); //me.direction = Vector2Int.zero; }
public static void GetDirection(EnemyLogic me) { if (me.position == me.currentNode.m_grid.GetNearestNode(me.path[(me.m_currentPathNode + 1) % me.path.Length]).position) { me.m_currentPathNode = (me.m_currentPathNode + 1) % me.path.Length; } float dirX = me.path[(me.m_currentPathNode + 1) % me.path.Length].x - me.path[me.m_currentPathNode % me.path.Length].x; float dirY = me.path[(me.m_currentPathNode + 1) % me.path.Length].y - me.path[me.m_currentPathNode % me.path.Length].y; me.direction = Vector2Int.RoundToInt((Mathf.Abs(dirX) > Mathf.Abs(dirY)) ? new Vector2(Mathf.Sign(dirX), 0) : new Vector2(0, Mathf.Sign(dirY))); }
public void ExecuteStep(GridNode cur_node, GridNode tar_node, EnemyLogic me, GameObject target) { if (!playerInRange) { return; } MortarEnemy Me = (MortarEnemy)me; Me.CreateIndicators(); Me.m_drawGizmos = true; Me.ShootProjectile(); }
public void CalculateStep(GridNode cur_node, GridNode tar_node, EnemyLogic me, GameObject target) { playerInRange = true; MortarEnemy Me = (MortarEnemy)me; if (!Me.PlayerInFiringRange()) { playerInRange = false; Me.state = MortarEnemy.State.IDLE; me.actionQueue.ResetQueue((int)MortarEnemy.State.FIRING); return; } Me.targetNode = Me.player.CurrentNode.position; }
public void CalculateStep(GridNode cur_node, GridNode tar_node, EnemyLogic me, GameObject target) { }
public void CalculateStep(GridNode cur_node, GridNode tar_node, EnemyLogic me, GameObject target) { me.direction = Vector2Int.zero; ReflectIncoming(me); }