protected void EndSwitch() { MazeManager.NextSwitch(); player.enabled = true; Destroy(this); }
protected virtual bool ChasePlayer() { Tile nextTile = ClosestToPlayer(); if (nextTile != null) { Vector2 nextPosition; if (nextTile == character.currentTile) { nextPosition = Player.instance.transform.position; } else { nextPosition = (Vector2)MazeManager.TileToWorldPos(nextTile.coordinates) + new Vector2(0, Tile.size / 2); } character.TurnTo(nextPosition); character.MoveTo(nextPosition, true); return(true); } else { return(false); } }
public void update() { Vector2 car_world = new Vector2(c.transform.position.x, c.transform.position.z); current_grid = MazeManager.world_to_grid(car_world); // Debug.Log(current); }
void Break() { SoundManager.GlassBreak(); Player.instance.canMove = true; sr.sprite = broken; MazeManager.GetTile((Vector2)transform.position - new Vector2(Tile.size / 2, Tile.size / 2)).obstacle = "obstacle5"; }
public virtual void InitialDirection() { Vector2 offset = Vector2.zero; int x = currentTile.x; int y = currentTile.y; if (MazeManager.maze.tiles [x, y + 1].isWall) // Virado para baixo { Vector3 wpos = MazeManager.TileToWorldPos(new Vector2(x, y - 1)) + new Vector3(0, Tile.size / 2, 0); TurnTo(new Vector2(wpos.x, wpos.y)); offset.y += (Tile.size - boxCollider.size.y) / 2; } else if (MazeManager.maze.tiles [x + 1, y].isWall) // Virado para a esquerda { Vector3 wpos = MazeManager.TileToWorldPos(new Vector2(x - 1, y)) + new Vector3(0, Tile.size / 2, 0); TurnTo(new Vector2(wpos.x, wpos.y)); offset.x += (Tile.size - boxCollider.size.x) / 2; } else if (MazeManager.maze.tiles [x - 1, y].isWall) // Virado para a direita { Vector3 wpos = MazeManager.TileToWorldPos(new Vector2(x + 1, y)) + new Vector3(0, Tile.size / 2, 0); TurnTo(new Vector2(wpos.x, wpos.y)); offset.x -= (Tile.size - boxCollider.size.x) / 2; } else if (MazeManager.maze.tiles [x, y - 1].isWall) // Virado para cima { Vector3 wpos = MazeManager.TileToWorldPos(new Vector2(x, y + 1)) + new Vector3(0, Tile.size / 2, 0); TurnTo(new Vector2(wpos.x, wpos.y)); offset.y -= (Tile.size - boxCollider.size.y) / 2; } currentTile = currentTile; transform.Translate(offset.x, offset.y, offset.y); }
void Eat() { Item fruitEquiped = SaveManager.currentSave.bag.selectedItem; if (fruitEquiped != null && fruitEquiped is Fruit) { Fruit f = (Fruit)fruitEquiped; Player.instance.ConsumeItem(); if (f.number == SaveManager.currentSave.currentFruit) { SaveManager.currentSave.currentFruit++; SoundManager.Coin(); } else { SaveManager.currentSave.currentFruit = 0; Attack(); } } else { Attack(); } if (SaveManager.currentSave.currentFruit == 6) { Vector2 pos = MazeManager.WorldToTilePos(transform.position); MazeManager.maze.tiles [(int)pos.x, (int)pos.y].obstacle = ""; GameObject r = Instantiate(rose) as GameObject; r.transform.position = transform.position; Destroy(gameObject); } }
public IEnumerator ChaseItemOld() { Tile objTile = MazeManager.GetTile(transform.position - new Vector3(0, Tile.size / 2, 0)); Tile playerTile = Player.instance.character.currentTile; GridPath path = PathFinder.FindPath(objTile, playerTile, moveDistance); if (path != null) { path = path.PreviousSteps; while (path != null) { if (!Player.instance.canMove || Player.instance.character.damaging) { break; } Tile t = path.LastStep; Vector2 nextPosition = (Vector2)MazeManager.TileToWorldPos(t.coordinates) + new Vector2(0, Tile.size / 2); Player.instance.character.TurnTo(nextPosition); yield return(Player.instance.character.MoveTo(nextPosition, true)); path = path.PreviousSteps; } } }
void OnTriggerEnter2D(Collider2D other) { if (state == 2 && other.CompareTag("Player")) { StartCoroutine(Player.instance.Fall(MazeManager.GetTile(transform.position).transition)); } }
private void Push(FlexNode node = null) { if (m_Flexs == null) { m_Flexs = new Dictionary <int, FlexNode>(); } if (m_FlexGOParent == null) { m_FlexGOParent = new GameObject("Flexs"); } if (m_GizmosGO == null) { m_GizmosGO = MazeMapGizmos.instance.gameObject; m_GizmosGO.name = "Maze Maker Gizmos"; } OnFlexChange(true, node); OnOtherFlexChange(); var flexType = (FlexType)m_SelectFlexTypeIdx; var n = node ?? new FlexNode(m_Flexs.Count, flexType, m_FlexTime); var info = new FlexGOInfo(n, m_FlexPosition, m_FlexForwardDir); var flexGO = MazeManager.CreateFlex(info); flexGO.transform.localScale = Vector3.one * m_Scale; flexGO.transform.SetParent(m_FlexGOParent.transform); m_Flexs.Add(flexGO.transform.GetSiblingIndex(), n); UpdateGizmos(); SaveToEditorPrebs(); }
protected virtual Tile ClosestToPlayer() { if (Player.visible) { Tile playerTile = Player.instance.character.currentTile; Tile myTile = character.currentTile; if (PathFinder.EstimateCost(myTile, playerTile) >= vision) { return(null); } if (!playerTile.isWalkable) { Vector2 playerPos = Player.instance.transform.position; Vector2 tileCenter = MazeManager.TileToWorldPos(playerTile.coordinates) + new Vector3(0, Tile.size / 2, 0); Vector2 d = playerPos - tileCenter; if (Mathf.Abs(d.x) > Mathf.Abs(d.y)) { int dx = d.x > 0 ? 1 : -1; playerTile = MazeManager.maze.tiles[playerTile.x + dx, playerTile.y]; } else { int dy = d.y > 0 ? 1 : -1; playerTile = MazeManager.maze.tiles[playerTile.x, playerTile.y + dy]; } } GridPath path = PathFinder.FindPath(playerTile, myTile, vision); if (path == null) { float best = vision + 1; GridPath bestp = null; foreach (Tile n in myTile.GetNeighbours4Walkeable()) { path = PathFinder.FindPath(n, playerTile, vision - 1); if (path != null && path.TotalCost < best) { best = path.TotalCost; bestp = path; } } path = bestp; } if (path != null) { if (path.PreviousSteps != null && path.PreviousSteps.LastStep.isWalkable) { return(path.PreviousSteps.LastStep); } else { return(path.LastStep); } } } return(null); }
private void SetNewPosition(Vector2 newPosition) { // Check if we are not going out the map fist if (newPosition.x < 0 || newPosition.y < 0 || newPosition.x > Columns - 1 || newPosition.y > Rows - 1) { return; } // Check for the right or left wall switch ((int)Position.x - (int)newPosition.x) { case -1: if (MazeCells.ElementAt((int)(Position.x + Position.y * Columns)).Value.GetWallStatus(Cell.CellWalls.RightWall)) { return; } break; case 1: if (MazeCells.ElementAt((int)(Position.x + Position.y * Columns)).Value.GetWallStatus(Cell.CellWalls.LeftWall)) { return; } break; } // Check for the top or bottom wall switch ((int)Position.y - (int)newPosition.y) { case -1: if (MazeCells.ElementAt((int)(Position.x + Position.y * Columns)).Value.GetWallStatus(Cell.CellWalls.TopWall)) { return; } break; case 1: if (MazeCells.ElementAt((int)(Position.x + Position.y * Columns)).Value.GetWallStatus(Cell.CellWalls.BottomWall)) { return; } break; } Position = newPosition; transform.position = new Vector2(newPosition.x * Width + (Width / 2), newPosition.y * Height + (Height / 2)); // Show the menu when we reach the end of the maze if (Position == new Vector2(Columns - 1, 0)) { MazeManager.ShowMenu(); } nextMove = Time.time + moveInterval; }
private void Start() { portal = GetComponent <Portal>(); manager = GetComponentInParent <MazeManager>(); maze = GetComponentInParent <Maze>(); portal.Port += Shuffle; }
public Car(GameObject c, List <Vector2Int> goals_) { this.c = c; Vector2 car_world = new Vector2(c.transform.position.x, c.transform.position.z); current_grid = MazeManager.world_to_grid(car_world); goals = goals_; }
private void OnOtherFlexChange(bool add = true) { if (m_Flexs.Count < 1) { return; } if (m_OtherFlexIdxs == null) { m_OtherFlexIdxs = new List <int[]>(); } if (add) { var preFlexGO = m_FlexGOParent.transform.GetChild(m_Flexs.Keys.ToList()[m_Flexs.Count - 1]).gameObject; var startPos = preFlexGO.transform.position; var endPos = m_FlexPosition; var dir = m_FlexForwardDir; var offsetNum = Vector3.Distance(startPos, endPos) / m_Scale; var num = Mathf.CeilToInt(offsetNum); var rest = offsetNum - num; rest = rest > 0 ? rest : 1 + rest; var goIdxs = new int[num - 1]; for (int i = 0; i < goIdxs.Length; i++) { var scale = m_Scale; var pos = startPos + (i + 1) * dir * scale; if (i == goIdxs.Length - 1) { scale = m_Scale * rest; pos -= dir * (1 - scale) / 2; } var info = new FlexGOInfo(new FlexNode(), pos, dir); var flexGO = MazeManager.CreateFlex(info); flexGO.transform.SetParent(m_FlexGOParent.transform, false); flexGO.transform.localScale = new Vector3(flexGO.transform.localScale.x * m_Scale, flexGO.transform.localScale.y * m_Scale, flexGO.transform.localScale.z * scale); goIdxs[i] = flexGO.transform.GetSiblingIndex(); } m_OtherFlexIdxs.Add(goIdxs); } else { if (m_OtherFlexIdxs.Count > 0) { var goIdxs = m_OtherFlexIdxs[m_OtherFlexIdxs.Count - 1]; var goToRemove = new List <GameObject>(); foreach (var i in goIdxs) { var go = m_FlexGOParent.transform.GetChild(i).gameObject; goToRemove.Add(go); } foreach (var go in goToRemove) { MazeManager.DestroyFlex(go); } m_OtherFlexIdxs.Remove(goIdxs); } } }
// Verifica se o player chegou nem tile que tem uma transição void CheckTransition() { Tile tile = character.currentTile; if (tile.transition != null && tile.transition.instant) { MazeManager.GoToMaze(tile.transition); } }
// Start is called before the first frame update void Start() { currentNumberOfBombs = maxNumberOfBombs; MazeManager = GameObject.FindObjectOfType <MazeManager>(); canvas = GameObject.FindObjectOfType <Canvas>(); gameOverScreen = canvas.GetComponentInChildren <Image>().gameObject; gameOverScreen.SetActive(false); sound = GetComponent <AudioSource>(); }
// Called during initialization private void GetObjects() { startCanvas = GameObject.Find("Start Canvas"); updateCanvas = GameObject.Find("Update Canvas"); nameInput = GameObject.FindWithTag("playerName"); minimapCamera = GameObject.Find("Minimap Camera"); colorPicker = GameObject.Find("Color Picker").GetComponent <ColorPicker>(); mazeManager = GetComponent <MazeManager>(); }
void RandomMove() { List <Tile> possibleTiles = character.currentTile.GetNeighbours4Walkeable(); Tile t = possibleTiles[Random.Range(0, possibleTiles.Count)]; Vector2 nextPosition = (Vector2)MazeManager.TileToWorldPos(t.coordinates) + new Vector2(0, Tile.size / 2); character.TurnTo(nextPosition); character.MoveTo(nextPosition, true); }
void Die() { Vector2 iniPosTile = MazeManager.WorldToTilePos(iniPos - new Vector3(0, Tile.size / 2, 0)); MazeManager.maze.tiles [(int)iniPosTile.x, (int)iniPosTile.y].obstacle = ""; GameObject obj = Instantiate(rose) as GameObject; obj.transform.position = iniPos; Destroy(gameObject); }
private void Start() { componentRigidbody = GetComponent <Rigidbody2D>(); inventar = FindObjectOfType <Inventar>(); mazeManager = FindObjectOfType <MazeManager>(); //hels = maxHels; LvlUp(0); }
void OnTriggerEnter2D(Collider2D other) { if (other.CompareTag("Player")) { Item item = Item.DB [9]; SoundManager.Rose(); SaveManager.currentSave.bag.Add(item); Vector3 pos = MazeManager.WorldToTilePos(transform.position - new Vector3(0, Tile.size, 0)); MazeManager.maze.tiles [(int)pos.x, (int)pos.y].objectName = ""; Destroy(gameObject); } }
public virtual void Awake() { slime = Resources.Load("Slize") as GameObject; animator = GetComponent <Animator>(); player = FindObjectOfType <PlayerControls>(); rigidbody = GetComponent <Rigidbody2D>(); mazeManager = FindObjectOfType <MazeManager>(); maxFierRate = FierRate; damage += mazeManager.enamyDamage; Hels += mazeManager.enamyHels; maxHels = Hels; }
protected override void OnDie() { MazeManager.maze.tiles [originalTile.x, originalTile.y].objectName = ""; if (PickItem.golemCount == 4 && !SaveManager.currentSave.golemRose) { GameObject obj = Instantiate(rose) as GameObject; int width = MazeManager.maze.width; int height = MazeManager.maze.height; obj.transform.position = MazeManager.TileToWorldPos(MazeManager.maze.tiles [width / 2, height - 2].coordinates); SaveManager.currentSave.golemRose = true; } base.OnDie(); }
protected virtual bool RunFromPlayer() { Tile nextTile = FarestFromPlayer(); if (nextTile != null && nextTile.isWalkable) { Vector2 nextPosition = (Vector2)MazeManager.TileToWorldPos(nextTile.coordinates) + new Vector2(0, Tile.size / 2); character.TurnTo(nextPosition); character.MoveTo(nextPosition, true); return(true); } else { return(false); } }
private void SetDropDown(GenerateView generateView, MazeManager mazeManager) { // Create dropdown options. generateView.GenerationDropdown.ClearOptions(); optionsCache.Clear(); MazeGenerator[] mazeGenerators = mazeManager.GetMazeGenerators(); for (int i = 0; i < mazeGenerators.Length; i++) { optionsCache.Add(mazeGenerators[i].GenerationStrategyType.ToString()); } generateView.GenerationDropdown.AddOptions(optionsCache); generateView.GenerationDropdown.value = mazeManager.GetCurrentGeneratorIndex(); }
// Use this for initialization void Awake() { instance = this; foreach (Switch mazeSwitch in GetComponentsInChildren <Switch>()) { mazeSwitches.Add(mazeSwitch); } foreach (Switch mazeSwitch in mazeSwitches) { mazeSwitch.gameObject.SetActive(false); } mazeSwitches[0].gameObject.SetActive(true); }
public void SetUp() { GameObject managerGO = GameObject.Instantiate(Resources.Load("Prefabs/GameManager")) as GameObject; mazeManager = managerGO.GetComponent <MazeManager>(); GameObject playerGO = GameObject.Instantiate(Resources.Load("Prefabs/Player")) as GameObject; player = playerGO.GetComponent <Player>(); player.mazeManager = Mock.Of <MazeManager>( mm => mm.GetPassableDirections(It.IsAny <Vector2Int>()) == new List <Vector3>() { new Vector3(1, 0, 0), new Vector3(-1, 0, 0) }); gameManager = managerGO.GetComponent <GameManager>(); }
void Update() { Tile t = MazeManager.GetTile((Vector2)transform.position - new Vector2(0, Tile.size)); if (t == null || t.isWall) { Destroy(gameObject); } else { Vector3 pos = transform.position; pos.x += moveVector.x * 60 * Time.deltaTime; pos.y += moveVector.y * 60 * Time.deltaTime; pos.z += moveVector.y * 60 * Time.deltaTime; transform.position = pos; } }
void Start() { mazeManager = GameObject.Find("Maze").GetComponent <MazeManager> (); mob = GetComponent <NavMeshAgent> (); mob.speed = walkSpeed; animator.SetBool("Patrol", true); lastMaze = mazeManager.currentMaze; player = GameObject.FindWithTag("Player").GetComponent <BasicCharacter>(); SetAllPaths(); currentPatrolPath = GetPatrolPath(); senseCollider = GetComponent <SphereCollider> (); GotoNextPoint(); }
// Update is called once per frame void Update() { Tile t = MazeManager.GetTile((Vector2)transform.position - new Vector2(0, Tile.size)); if (t == null || !t.isWalkable || lifeTime <= 0) { Destroy(gameObject); } else { Vector3 pos = transform.position; pos.x += moveVector.x * 60 * Time.deltaTime + Random.Range(-2, 3); pos.y += moveVector.y * 60 * Time.deltaTime; pos.z += moveVector.y * 60 * Time.deltaTime; transform.position = pos; } }