private void checkPlayerMove() { //If it's not the player's turn, don't check movement if (playersTurn && this.gameState == GameManager.state_game) { int horizontal = 0; int vertical = 0; if (Input.GetMouseButtonDown(0)) { Vector3 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition); //convert to gametiles TileMapCoordinates mouseC = convertCoordinatesToTileMap(mousePos.x, mousePos.y); int px = (int)(this.player.transform.position.x / BoardManager.wMultiplier); int py = (int)(this.player.transform.position.y / BoardManager.hMultiplier); if (mouseC.x > px) { horizontal = BoardManager.wMultiplier; vertical = 0; } else if (mouseC.x < px) { horizontal = -BoardManager.wMultiplier; vertical = 0; } else if (mouseC.y > py) { vertical = BoardManager.hMultiplier; } else if (mouseC.y < py) { vertical = -BoardManager.hMultiplier; } } //we have movement, let the player itself figure out if he can move if (horizontal != 0 || vertical != 0) { this.player.PlayerMove(horizontal, vertical); } } }
//Call this to add the passed in Item to the List of Items. Also set its health public void AddItemToList(Item item) { if (this.gameState == GameManager.state_doing_setup) { TileMapCoordinates iC = convertCoordinatesToTileMap(item.transform.position.x, item.transform.position.y); this.itemMap[iC.x, iC.y] = item; this.declaredItems++; if (this.declaredItems == this.itemsOnBoard) { // all items accounted for. finish setup for (int i = 0; i < this.itemMap.GetLength(0); i++) { for (int j = 0; j < this.itemMap.GetLength(1); j++) { Item it = this.itemMap[i, j]; if (it != null) { it.finishFullInit(this.boardScript.monsterTiles, this.boardScript.itemTiles); } } } this.gameState = GameManager.state_setup_done; } } else { TileMapCoordinates iC = convertCoordinatesToTileMap(item.transform.position.x, item.transform.position.y); // sometimes multiple gameobjects get created @ the same location @ the same time, like the bushfire, bunny or treemonster if (this.itemMap[iC.x, iC.y] != null && ( item.type == 102 || item.type == 111 || item.type == 114 )) { Destroy(this.itemMap[iC.x, iC.y].gameObject); } this.itemMap[iC.x, iC.y] = item; } }
public void RemoveItemFromList(Item i) { TileMapCoordinates iC = convertCoordinatesToTileMap(i.transform.position.x, i.transform.position.y); this.itemMap[iC.x, iC.y] = null; }