public void SetWaitAction() { m_state = Cell_State.WaitAction; m_pSprite = m_pAction; isLastCell = true; //isFly = false; }
public void setBeginTouch() { if (m_state == Cell_State.NoTouch) { m_state = Cell_State.Touching; m_pSprite = m_pTouch; } }
public void setEndTouch(bool isEndTouch) { if (isEndTouch == false) { m_state = Cell_State.NoTouch; m_pSprite = m_pNoTouch; } if (m_state == Cell_State.Touching) { m_state = Cell_State.Action; m_pSprite = m_pAction; } }
public void Update(GameTime gameTime) { if (m_state == Cell_State.Die) { if (isLastCell == false) { m_grid.removeCell(this, false); } else { m_grid.removeCell(this, true); } return; } Vector2 _vectorDir = m_direction - m_position; if (m_state == Cell_State.Action)//if (m_isFly) { m_position += _vectorDir * 13 / gameTime.ElapsedGameTime.Milliseconds; if (Math.Abs(_vectorDir.X) < 1 && Math.Abs(_vectorDir.Y) < 1) { Global.isFly = false; m_position = m_direction; m_state = Cell_State.Die; //m_pSprite = m_pExplosion; } } if (m_state == Cell_State.Falling)//if (m_isFly) { m_position += _vectorDir * 25 / gameTime.ElapsedGameTime.Milliseconds; if (Math.Abs(_vectorDir.X) < 1 && Math.Abs(_vectorDir.Y) < 1) { Global.isFly = false; m_position = m_direction; m_indexI = m_tempIndexI; m_tempIndexI = 0; m_state = Cell_State.NoTouch; isLastCell = false; rect = new Rectangle((int)m_position.X, (int)m_position.Y, TILE, TILE); //m_pSprite = m_pExplosion; m_grid.m_countFalling--; } } if (m_state == Cell_State.WaitAction && Global.isFly == false) { m_state = Cell_State.Explosion; m_pSprite = m_pExplosion; m_position -= EXTRAPOS_EXPLOSION; } if (m_state == Cell_State.Explosion) { //if (m_pSprite.Loop >= 1) if (m_pSprite.CurentFrame == m_pSprite.LastFrame) { m_state = Cell_State.Die; } } if (m_state != Cell_State.Action) { m_pSprite.Update(gameTime); } }
private void boardContentInit() { int i = 0; while (i < numberOfWumpus) { int randI = UnityEngine.Random.Range(0, 10); int randJ = UnityEngine.Random.Range(0, 10); if (board[randI, randJ, 0] == 0) { gameObjects[randI, randJ] = Instantiate(wumpus, new Vector3(board[randI, randJ, 1], board[randI, randJ, 2], -1f), wumpus.transform.rotation); board[randI, randJ, 0] = Constant.WUMPUS; i++; for (int j = 0; j < 4; j++) { if (path[randI, randJ, j].row != -1) { if (board[path[randI, randJ, j].row, path[randI, randJ, j].col, 0] == 0) { board[path[randI, randJ, j].row, path[randI, randJ, j].col, 0] = Constant.STENCH; gameObjects[path[randI, randJ, j].row, path[randI, randJ, j].col] = Instantiate(stench, new Vector3(board[path[randI, randJ, j].row, path[randI, randJ, j].col, 1], board[path[randI, randJ, j].row, path[randI, randJ, j].col, 2], -1f), stench.transform.rotation); } else if (board[path[randI, randJ, j].row, path[randI, randJ, j].col, 0] == Constant.BREEZE) { board[path[randI, randJ, j].row, path[randI, randJ, j].col, 0] = Constant.BREEZE_STENCH; Destroy(gameObjects[path[randI, randJ, j].row, path[randI, randJ, j].col]); gameObjects[path[randI, randJ, j].row, path[randI, randJ, j].col] = Instantiate(breeze_stench, new Vector3(board[path[randI, randJ, j].row, path[randI, randJ, j].col, 1], board[path[randI, randJ, j].row, path[randI, randJ, j].col, 2], -1f), stench.transform.rotation); } } } } } i = 0; while (i < numberOfPit) { int randI = UnityEngine.Random.Range(0, 10); int randJ = UnityEngine.Random.Range(0, 10); if (board[randI, randJ, 0] == 0) { gameObjects[randI, randJ] = Instantiate(pit, new Vector3(board[randI, randJ, 1], board[randI, randJ, 2], -1f), wumpus.transform.rotation); board[randI, randJ, 0] = Constant.PIT; i++; for (int j = 0; j < 4; j++) { if (path[randI, randJ, j].row != -1) { if (board[path[randI, randJ, j].row, path[randI, randJ, j].col, 0] == 0) { board[path[randI, randJ, j].row, path[randI, randJ, j].col, 0] = Constant.BREEZE; gameObjects[path[randI, randJ, j].row, path[randI, randJ, j].col] = Instantiate(breeze, new Vector3(board[path[randI, randJ, j].row, path[randI, randJ, j].col, 1], board[path[randI, randJ, j].row, path[randI, randJ, j].col, 2], -1f), breeze.transform.rotation); } else if (board[path[randI, randJ, j].row, path[randI, randJ, j].col, 0] == Constant.STENCH) { board[path[randI, randJ, j].row, path[randI, randJ, j].col, 0] = Constant.BREEZE_STENCH; Destroy(gameObjects[path[randI, randJ, j].row, path[randI, randJ, j].col]); gameObjects[path[randI, randJ, j].row, path[randI, randJ, j].col] = Instantiate(breeze_stench, new Vector3(board[path[randI, randJ, j].row, path[randI, randJ, j].col, 1], board[path[randI, randJ, j].row, path[randI, randJ, j].col, 2], -1f), breeze.transform.rotation); } } } } } i = 0; while (i < numberOfGold) { int randI = UnityEngine.Random.Range(0, 10); int randJ = UnityEngine.Random.Range(0, 10); if (board[randI, randJ, 0] == 0) { gameObjects[randI, randJ] = Instantiate(gold, new Vector3(board[randI, randJ, 1], board[randI, randJ, 2], -1f), wumpus.transform.rotation); board[randI, randJ, 0] = Constant.GOLD; i++; } } //player while (true) { int randI = UnityEngine.Random.Range(0, 10); int randJ = UnityEngine.Random.Range(0, 10); if (board[randI, randJ, 0] == 0) { player_currentPosition[0] = randI; player_currentPosition[1] = randJ; Cell_State cell = new Cell_State(); cell.isSafe = true; cell.breeze = false; cell.stench = false; cell.pit = false; cell.wumpus = false; KB[randI, randJ] = cell; int[] node = { randI, randJ }; visited_cell_track.Push(node); // visited_cell[randI, randJ]= Instantiate(visited, new Vector3(board[randI, randJ, 1], board[randI, randJ, 2], -1f), visited.transform.rotation); updateKB(player_currentPosition, Constant.EMPTY); game_player = Instantiate(player, new Vector3(board[randI, randJ, 1], board[randI, randJ, 2], 0f), player.transform.rotation); anim = game_player.GetComponent <Animator>(); break; } } }
public void updateKB(int[] index, float type) { if (type == Constant.BREEZE) { KB[index[0], index[1]].breeze = true; KB[index[0], index[1]].isSafe = true; KB[index[0], index[1]].wumpus = false; KB[index[0], index[1]].pit = false; } else if (type == Constant.STENCH) { KB[index[0], index[1]].stench = true; KB[index[0], index[1]].isSafe = true; KB[index[0], index[1]].wumpus = false; KB[index[0], index[1]].pit = false; } else if (type == Constant.WUMPUS) { KB[index[0], index[1]].wumpus = true; KB[index[0], index[1]].breeze = false; KB[index[0], index[1]].stench = false; KB[index[0], index[1]].isSafe = false; } else if (type == Constant.PIT) { KB[index[0], index[1]].pit = true; KB[index[0], index[1]].stench = false; KB[index[0], index[1]].breeze = false; KB[index[0], index[1]].isSafe = false; } else if (type == Constant.EMPTY) { KB[index[0], index[1]].isSafe = true; KB[index[0], index[1]].breeze = false; KB[index[0], index[1]].wumpus = false; KB[index[0], index[1]].pit = false; KB[index[0], index[1]].stench = false; } else if (type == Constant.GOLD) { KB[index[0], index[1]].isSafe = true; KB[index[0], index[1]].wumpus = false; KB[index[0], index[1]].pit = false; KB[index[0], index[1]].breeze = false; KB[index[0], index[1]].stench = false; goldNum--; cost += 100; } KB[index[0], index[1]].visited = true; for (int i = 0; i < 4; i++) { int row = path[index[0], index[1], i].row; int col = path[index[0], index[1], i].col; if (row != -1) { Cell_State cell; if (KB[row, col] == null) { cell = new Cell_State(); } else { cell = KB[row, col]; } if (!cell.visited) { if (type == Constant.BREEZE) { cell.pit = true; cell.isSafe = false; } else if (type == Constant.STENCH) { cell.wumpus = true; cell.isSafe = false; } else if (type == Constant.WUMPUS) { cell.stench = true; cell.isSafe = true; } else if (type == Constant.PIT) { cell.breeze = true; cell.isSafe = true; } else if (type == Constant.EMPTY) { cell.isSafe = true; cell.pit = false; cell.wumpus = false; } else if (type == Constant.GOLD) { cell.isSafe = true; cell.pit = false; cell.wumpus = false; } KB[row, col] = cell; } } } }