public Actor CheckTarget(Vector2 target) { GameData data = Application.GetData(); Actor actor = new Actor(); bool targetExists = false; for (int i = 0; i < data.collision.Count; i++) { if (data.collision[i].position.x == target.x && data.collision[i].position.y == target.y) { if ((ConsolePseudoRaycast.CastRay(new Vector2(data.player.position.x, data.player.position.y), new Vector2(target.x, target.y)))) { return(null); } /**/ targetExists = true; actor = data.collision[i]; } } if (targetExists) { return(actor); } return(null); }
public void Execute() { GameData data = Application.GetData(); List <Actor> enemies = data.level.enemies; Direction dir; bool hit = false; bool random = false; Vector2 p_pos = new Vector2(data.player.position.x, data.player.position.y); for (int i = 0; i < enemies.Count; i++) { //melee if (enemies[i].type == "melee_calm") { random = false; hit = false; if (Vector2.Distance(new Vector2(enemies[i].position.x, enemies[i].position.y), p_pos) <= 5) { if ((ConsolePseudoRaycast.CastRay(new Vector2(enemies[i].position.x, enemies[i].position.y), new Vector2(p_pos.x, p_pos.y)))) { //ConsoleView.errorMessage = "target obscured (RayCast)"; hit = true; random = true; } if (!hit) { Direction[] dirArray = new Direction[2]; dirArray = enemies[i].DirectionTowards(p_pos); if (Vector2.Distance(new Vector2(enemies[i].position.x, enemies[i].position.y), p_pos) <= enemies[i].Weapon.content.range) { enemies[i].Weapon.content.Attack(data.player.position); } else { if (!DirectionMove(dirArray, enemies[i])) { random = true; } } } else { random = true; } } else { random = true; } if (random == true) { int counter = 0; while (counter < 100) { counter++; if (RandomMove(enemies[i])) { break; } } } } // ranged if (enemies[i].type == "ranged") { random = false; hit = false; if (Vector2.Distance(new Vector2(enemies[i].position.x, enemies[i].position.y), p_pos) <= enemies[i].Weapon.content.range + aggro) { if ((ConsolePseudoRaycast.CastRay(new Vector2(enemies[i].position.x, enemies[i].position.y), new Vector2(p_pos.x, p_pos.y)))) { //ConsoleView.errorMessage = "target obscured (RayCast)"; hit = true; random = true; } if (!hit) { Direction[] dirArray = new Direction[2]; bool moved = false; if (Vector2.Distance(new Vector2(enemies[i].position.x, enemies[i].position.y), p_pos) <= enemies[i].Weapon.content.range) { enemies[i].Weapon.content.Attack(data.player.position); aggro = 3; } else { DirectionMove(dirArray, enemies[i]); if (!moved) { random = true; } } } else { random = true; } } else { random = true; } if (random == true) { int counter = 0; while (counter < 100) { counter++; if (RandomMove(enemies[i])) { break; } } } } // melee boss if (enemies[i].type == "melee_aggressive") { hit = false; random = false; if (Vector2.Distance(new Vector2(enemies[i].position.x, enemies[i].position.y), p_pos) <= 10) { if ((ConsolePseudoRaycast.CastRay(new Vector2(enemies[i].position.x, enemies[i].position.y), new Vector2(p_pos.x, p_pos.y)))) { //ConsoleView.errorMessage = "target obscured (RayCast)"; hit = true; random = true; } if (!hit) { Direction[] dirArray = new Direction[2]; dirArray = enemies[i].DirectionTowards(p_pos); if (Vector2.Distance(new Vector2(enemies[i].position.x, enemies[i].position.y), p_pos) <= enemies[i].Weapon.content.range) { enemies[i].Weapon.content.Attack(data.player.position); } else { if (DirectionMove(dirArray, enemies[i])) { random = true; } } } else { random = true; } } else { random = true; } if (random == true) { int counter = 0; while (counter < 100) { counter++; if (RandomMove(enemies[i])) { break; } } } } End(); } }