private void InitializePathFinding(IPathFinding <IGraphicsComponent> pathFinder) { pathFinder.InitialUnit = Player; pathFinder.ArrayGrid3D = gameMesh; pathFinder.ObstaclesAddAll(GetAllItemsWithTags(BlockType.Wall, BlockType.Water, BlockType.Edge).ToArray()); pathFinder.TargetsAddAll(GetAllItemsWithTags(FruitType.Apple, FruitType.Banana, FruitType.Pineapple, FruitType.Watermelone, CharacterType.Enemy, BlockType.FinishLocked).ToArray()); }
public void Start() { PathFinding = new AStar(GameFieldManager.Grid); _playerPosition = Player.transform.position; _botPosition = Bot.transform.position; StartGame(); }
private void Start() { //get the animator animator = GetComponent <Animator>(); //get interfaces _vision = GetComponent <IVision>(); _health = GetComponent <IHealth>(); _sfxController = GetComponent <ISfxController>(); _pathFinding = GetComponent <IPathFinding>(); _movement = GetComponent <IMovement>(); _rotation = GetComponent <IRotation>(); _simpleDamageDisplayManager = GetComponent <IDamageDisplayManager>(); //initial properties _normalSpeed = _movement.GetSpeed(); //initial states _isAgro = false; _isAttacking = false; _isAttackCoolingDown = false; invisible = false; //register event listener EventSystem.Current.RegisterEventListener <BulletHitCtx>(OnBulletHit); }
private void Start() { //get interfaces _vision = GetComponent <IVision>(); _health = GetComponent <IHealth>(); _sfxController = GetComponent <ISfxController>(); _pathFinding = GetComponent <IPathFinding>(); _movement = GetComponent <IMovement>(); _rotation = GetComponent <IRotation>(); _damageDisplayManager = GetComponent <IDamageDisplayManager>(); //get the animator if (animator == null) { animator = GetComponent <Animator>(); } //initial properties _lastSeenPlayerPos = new Vector3(); //initial _isAgro = false; _hasLastPlayerPos = false; _isAttacking = false; _isAttackCoolingDown = false; invisible = false; //register event listener EventSystem.Current.RegisterEventListener <BulletHitCtx>(OnBulletHit); }
private void Start() { PathFinding = GetComponent <IPathFinding>(); EnemyAttack = GetComponent <IEnemyAttack>(); Player = FindObjectOfType <PlayerController>(); LevelRules.Instance.AddEnemy(); }
// Use this for initialization public virtual void Init(GameObject gObject) { gameScene = GameApp.GetInstance().GetGameScene(); player = gameScene.GetPlayer(); enemyObject = gObject; enemyTransform = enemyObject.transform; animation = enemyObject.GetComponent <UnityEngine.Animation>(); aimedTransform = enemyTransform.Find(BoneName.ENEMY_AIMED_PATH); rigidbody = enemyObject.GetComponent <Rigidbody>(); //collider = enemyObject.transform.Find(BoneName.ENEMY_BODY).collider; collider = enemyObject.transform.GetComponent <Collider>(); //sceneGUI = GameObject.Find("SceneGUI").GetComponent<SceneGUI>(); rConfig = GameApp.GetInstance().GetResourceConfig(); gConfig = GameApp.GetInstance().GetGameConfig(); controller = enemyObject.GetComponent <Collider>() as CharacterController; detectionRange = 150.0f; attackRange = 1.5f; minRange = 1.5f; lootCash = 0; criticalAttacked = false; spawnCenter = enemyTransform.position; target = GameObject.Find("Player").transform; //rigidbody.centerOfMass = Vector3.up; audio = new AudioPlayer(); Transform audioFolderTrans = enemyTransform.Find("Audio"); audio.AddAudio(audioFolderTrans, "Attack"); audio.AddAudio(audioFolderTrans, "Walk"); audio.AddAudio(audioFolderTrans, "Dead"); audio.AddAudio(audioFolderTrans, "Special"); audio.AddAudio(audioFolderTrans, "Shout"); hitBloodObjectPool = GameApp.GetInstance().GetGameScene().HitBloodObjectPool; pathFinding = new GraphPathFinding(); animation.wrapMode = WrapMode.Loop; animation.Play(AnimationName.ENEMY_IDLE); state = IDLE_STATE; lastUpdateTime = Time.time; lastPathFindingTime = Time.time; idleStartTime = -2; enemyObject.GetComponent <UnityEngine.Animation>()[AnimationName.ENEMY_ATTACK].wrapMode = WrapMode.ClampForever; path = GameApp.GetInstance().GetGameScene().GetPath(); }
public void SetAIPathSource(PathFindingWays choice) { pathFindingChoice = choice; if (choice == PathFindingWays.DijkstraAI) { _iPath = _dijkstraAI; } else { _iPath = _aStarAI; } }
protected Enemy(IPathFinding pathFinder, IWeapon weapon, IPlayer player, double lifePoints, Vector2 position, Texture2D texture, IActionState state, IMap map) { PathFinder = pathFinder; Weapon = weapon; LifePoints = lifePoints; Position = position; Texture = texture; CurrentState = state; _player = player; Map = map; _player.AttachObserver(this); Alive = true; Send(EnemySpawned); }
public override Enemy CreateEnemy(IPathFinding pathFinder, EnemyType type, IWeapon weapon, IPlayer player, double lifePoints, Vector2 position, Texture2D texture, IActionState state, IMap map) { switch (type) { case EnemyType.Small: return(new EnemyA(pathFinder, weapon, player, lifePoints, position, texture, state, map)); case EnemyType.Big: return(new EnemyB(pathFinder, weapon, player, lifePoints, position, texture, state, map)); case EnemyType.Boss: return(new Boss(pathFinder, weapon, player, lifePoints, position, texture, state, map)); default: return(null); } }
public void SetPathFindingGrid(IGrid pGrid, bool showGrid) { pathFind = new PathFinding(pGrid); if (showGrid) { for (int row = 0; row < pGrid.grid.GetLength(0); row++) { for (int column = 0; column < pGrid.grid.GetLength(1); column++) { sceneManager.Spawn((iEntity)pathFind.mGrid.grid[row, column]); if (GraphicsDevice != null) { sceneManager.LoadResource((iEntity)pathFind.mGrid.grid[row, column]); } } } } }
public EnemyB(IPathFinding pathFinder, IWeapon weapon, IPlayer player, double lifePoints, Vector2 position, Texture2D texture, IActionState state, IMap map) : base(pathFinder, weapon, player, lifePoints, position, texture, state, map) { }
public abstract Enemy CreateEnemy(IPathFinding pathFinder, EnemyType type, IWeapon weapon, IPlayer player, double lifePoints, Vector2 position, Texture2D texture, IActionState state, IMap map);
/// <summary> /// Controller constructor, get injection /// </summary> /// <param name="pathFinding">Path finding service</param> public SolvroCityController(IPathFinding pathFinding) { this.pathFinding = pathFinding; }
public static List <INode> FindPath(this IPathFinding _this, INode startNode, INode targetNode, PathFindingSettings _settings) { List <INode> openSet = new List <INode>(); HashSet <INode> closedSet = new HashSet <INode>(); openSet.Add(startNode); // Ciclo la collezione open fino a quando ha elementi e scelgo quello con il costo minore per avanzare con la ricerca while (openSet.Count > 0) { INode node = openSet[0]; for (int i = 1; i < openSet.Count; i++) { if (openSet[i].F_Cost < node.F_Cost || openSet[i].F_Cost == node.F_Cost) { if (openSet[i].H_Cost < node.H_Cost) { node = openSet[i]; } } } openSet.Remove(node); closedSet.Add(node); // se il nodo attuale è uguale al target, ho raggiunto il target, ho terminato. if (node == targetNode) { return(RetracePath(startNode, targetNode)); } List <INode> nNodes = _this.GetNeighboursStar(node); // --------------------------------- // --------- Settings Eval --------- //if (!_settings.CanJump) { // nNodes = nNodes.Where(n => n.ContainsTag("walkable")).ToList<INode>(); //} // --------------------------------- foreach (INode neighbour in nNodes) { //if (!neighbour.isTraversable && !_settings.IgnoreObstacles || closedSet.Contains(neighbour)) { // continue; //} if (closedSet.Contains(neighbour)) { continue; } if (neighbour.isTraversable == false && neighbour != targetNode && _settings.IgnoreObstacles) { continue; } int newCostToNeighbour = node.G_Cost + GetDistance(node, neighbour, _settings); if (newCostToNeighbour < neighbour.G_Cost || !openSet.Contains(neighbour)) { neighbour.G_Cost = newCostToNeighbour; neighbour.H_Cost = GetDistance(neighbour, targetNode, _settings); neighbour.parent = node; if (!openSet.Contains(neighbour)) { openSet.Add(neighbour); } } } } return(new List <INode>()); }
/// <summary> /// trova il percorso dallo startNode al lastNode /// </summary> /// <param name="_this"></param> /// <param name="startNode"></param> /// <param name="lastNode"></param> public static List <INode> Find_(this IPathFinding _this, INode startNode, INode lastNode, bool ignoreTraversable = false) { List <INode> Open = new List <INode>(); List <INode> Closed = new List <INode>(); INode current; List <INode> path = new List <INode>(); Open.Add(startNode); do { //assegna a current l'INode con f cost più basso INode lower = null; foreach (var item in Open) { if (lower == null) { lower = item; } else { if (item.F_Cost < lower.F_Cost) { lower = item; } } } // mette current nella lista dei già analizzati e lo rimuove dai disponibili current = lower; Open.Remove(current); Closed.Add(current); //controllo se il currentNode è uguale al lastNode if (current == lastNode) { path.Add(lastNode.parent); while (path[path.Count - 1] != startNode) { path.Add(path[path.Count - 1].parent); } return(path); } if (current == null) { Debug.Log("Path non trovato"); return(path); } List <INode> neighboursNodes = current.GetNeighbours(); foreach (var neighbour in neighboursNodes) { // if ((!neighbour.isTraversable && !ignoreTraversable) || Closed.Contains(neighbour)) { //if (!neighbour.isTraversable || Closed.Contains(neighbour)) { // continue; //} if (Closed.Contains(neighbour)) { continue; } if (!neighbour.isTraversable && !ignoreTraversable) { continue; } //neighbour.SetCost(startNode, lastNode); if (!Open.Contains(neighbour)) { neighbour.parent = current; Open.Add(neighbour); } else { for (int i = 0; i < Open.Count; i++) { if (Open[i].GetGridPosition() == neighbour.GetGridPosition()) { int newCost = current.G_Cost + current.CalculateCost(current, neighbour); if (newCost < Open[i].G_Cost) { Open[i].parent = current; Open[i].G_Cost = newCost; Open[i].H_Cost = Open[i].CalculateCost(Open[i], lastNode); //Open[i].G_Cost = neighbour.G_Cost; //Open[i].H_Cost = neighbour.H_Cost; } } } } } }while (current != lastNode); return(path); }
public Boss(IPathFinding pathFinder, IWeapon weapon, IPlayer player, double lifePoints, Vector2 position, Texture2D texture, IActionState state, IMap map) : base(pathFinder, weapon, player, lifePoints, position, texture, state, map) { minions = new List <Enemy>(); BaseDamage = 20; }
public IEnumerable <Route> Solve(IPathFinding algorithm) { return(algorithm.Solve(Graph, Graph.GetByName(From), Graph.GetByName(To))); }
public void injectPathFinding(IPathFinding pPathFinder, iEntity pStar) { pathFinder = pPathFinder; Star = pStar; }
/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. _weaponTextures = new Dictionary <string, Texture2D>(); _spriteBatch = new SpriteBatch(GraphicsDevice); // TODO: use this.Content to load your game content here _backgroundTexture = Content.Load <Texture2D>("background"); _playerTexture = Content.Load <Texture2D>("player"); _enemyATexture = Content.Load <Texture2D>("enemyA"); _enemyBTexture = Content.Load <Texture2D>("enemyB"); _bossTexture = Content.Load <Texture2D>("boss"); foreach (var weapon in Enum.GetValues(typeof(WeaponName))) { _weaponTextures.Add(weapon.ToString(), Content.Load <Texture2D>(weapon.ToString())); } _wallTexture = Content.Load <Texture2D>("wall"); _player = new Player1(Vector2.Zero, _playerTexture); _map = new Map(GameSettings.MapSize, GameSettings.MapSize) { BackgroundTexture = _backgroundTexture }; _map.AddMapObject(_player); _pathFinder = new PathFindingAdapter(_map); var enemyState = new EnemyStateFactory(); var enemiesFactory = new EnemiesConcreteFactory(); _enemies = new List <Enemy> { enemiesFactory.CreateEnemy(_pathFinder, EnemyType.Small, new Bazooka(), _player, 100, new Vector2(5 * GameSettings.TileSize, 5 * GameSettings.TileSize), _enemyATexture, enemyState.GetState("Moving"), _map), enemiesFactory.CreateEnemy(_pathFinder, EnemyType.Big, new Pistol(), _player, 100, new Vector2(3 * GameSettings.TileSize, 5 * GameSettings.TileSize), _enemyBTexture, enemyState.GetState("Moving"), _map), enemiesFactory.CreateEnemy(_pathFinder, EnemyType.Boss, new Pistol(), _player, 500, new Vector2(1 * GameSettings.TileSize, 1 * GameSettings.TileSize), _bossTexture, enemyState.GetState("Moving"), _map), enemiesFactory.CreateEnemy(_pathFinder, EnemyType.Boss, new Pistol(), _player, 250, new Vector2(1 * GameSettings.TileSize, 2 * GameSettings.TileSize), _bossTexture, enemyState.GetState("Moving"), _map) }; Boss boss = (Boss)_enemies[2]; boss.AddMinion(_enemies[0]); boss.AddMinion(_enemies[1]); boss.AddMinion(_enemies[3]); foreach (Enemy minion in boss.GetMinions()) { _map.AddMapObject(minion); } var clonedEnemies = new List <Enemy> { _enemies[0].DeepCopy(), _enemies[0].DeepCopy(), _enemies[1].DeepCopy(), _enemies[1].DeepCopy() }; clonedEnemies[0].Position = new Vector2(7 * GameSettings.TileSize, 5 * GameSettings.TileSize); clonedEnemies[1].Position = new Vector2(5 * GameSettings.TileSize, 9 * GameSettings.TileSize); clonedEnemies[2].Position = new Vector2(2 * GameSettings.TileSize, 4 * GameSettings.TileSize); clonedEnemies[3].Position = new Vector2(5 * GameSettings.TileSize, 1 * GameSettings.TileSize); _enemies.Add(clonedEnemies[0]); _enemies.Add(clonedEnemies[1]); _enemies.Add(clonedEnemies[2]); _enemies.Add(clonedEnemies[3]); Boss boss2 = (Boss)_enemies[3]; boss2.AddMinion(_enemies[4]); _walls = new List <Wall> { new Wall { Position = new Vector2(10 * GameSettings.TileSize, 10 * GameSettings.TileSize), Texture = _wallTexture }, new Wall { Position = new Vector2(11 * GameSettings.TileSize, 10 * GameSettings.TileSize), Texture = _wallTexture }, new Wall { Position = new Vector2(12 * GameSettings.TileSize, 10 * GameSettings.TileSize), Texture = _wallTexture }, new Wall { Position = new Vector2(13 * GameSettings.TileSize, 10 * GameSettings.TileSize), Texture = _wallTexture }, new Wall { Position = new Vector2(14 * GameSettings.TileSize, 10 * GameSettings.TileSize), Texture = _wallTexture }, new Wall { Position = new Vector2(15 * GameSettings.TileSize, 10 * GameSettings.TileSize), Texture = _wallTexture } }; _weapons = new List <Weapon>(); foreach (var enemy in _enemies) { _map.AddMapObject(enemy); } foreach (var wall in _walls) { _map.AddMapObject(wall); } foreach (var weapon in _weapons) { _map.AddMapObject(weapon); } }