// Update is called once per frame void Update() { // Update the counters if (humanSuspicionMeter != null) { humanSuspicionMeter.value = Player.thePlayer.fHumanSuspicion; } if (lizardInfiltrationMeter != null) { lizardInfiltrationMeter.value = Player.thePlayer.lizardsDisguisedAsHumans; } if (numMetal != null) { numMetal.text = "" + Player.thePlayer.metal; } if (numGems != null) { numGems.text = "" + Player.thePlayer.gems; } if (numMushrooms != null) { numMushrooms.text = "" + Player.thePlayer.mushrooms; } if (numMoney != null) { numMoney.text = "" + Player.thePlayer.money; } if (numDinosaurBones != null) { numDinosaurBones.text = "" + Player.thePlayer.dinosaurBones; } numBreeders.text = Core.theTM.GetNumBreeders() + "/" + Core.theTM.GetMaxNumBreeders(); numFarmers.text = Core.theTM.GetNumFarmers() + "/" + Core.theTM.GetMaxNumFarmers(); numTrappers.text = Core.theTM.GetNumTrappers() + "/" + Core.theTM.GetMaxNumTrappers(); numTailors.text = Core.theTM.GetNumTailors() + "/" + Core.theTM.GetMaxNumTailors(); numMisc.text = Core.theTM.GetNumMisc() + ""; nextTVBill.text = "Next TV Bill: $" + Mathf.FloorToInt(TVRoom.fTVBill); fTutorialTime += Time.deltaTime; float fscale = 1.0f + 0.5f * Mathf.Sin(fTutorialTime * 5.0f); tutorial.transform.localScale = new Vector3(fscale, fscale, fscale); // Update the mouse over text if (mouseOverElement != null) { mouseOverElement.enabled = showMouseOver; if (showMouseOver) { mouseOverElement.transform.position = Input.mousePosition; Text text = mouseOverElement.GetComponent <Text>(); text.text = mouseOverText; } } // Update the scroll prompt if (scrollPrompt != null) { bool bShow = (Camera.main.transform.position.y > 0.0f); scrollPrompt.enabled = bShow; fScrollPromptTime += Time.deltaTime * 5.0f; float scale = 1.0f + 0.1f * Mathf.Sin(fScrollPromptTime); scrollPrompt.transform.localScale = new Vector3(scale, scale, scale); } // Hide all highlights for (int ii = 0; ii < TileManager.width; ++ii) { for (int jj = 0; jj < TileManager.depth; ++jj) { TileBase thisTile = Core.theTM.tiles[ii, jj]; thisTile.bShouldBeHighlighted = false; } } if (isBuildingAThing || isDiggingATile || isFillingInATile || isMarkingATileAsPriority) { // Get the tile that the mouse is over (if any!) TileBase mousedOverTile = null; bool bHasClicked = (Input.GetAxis("Fire1") > 0.0f); Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit2D hit = Physics2D.Raycast(ray.origin, ray.direction, Mathf.Infinity); if (hit) { mousedOverTile = hit.collider.gameObject.GetComponent <TileBase>(); if (bHasClicked) { //Debug.Log("Clicked on " + hit.collider.gameObject.name); } } // Iterate through all tiles, check if they are valid for this action for (int ii = 0; ii < TileManager.width; ++ii) { for (int jj = 0; jj < TileManager.depth; ++jj) { TileBase thisTile = Core.theTM.tiles[ii, jj]; if ((isBuildingAThing && thisTile.CanBeBuiltOver() && thisTile.isConstructed && thisTile.replacingTile == null) || (isDiggingATile && thisTile.CanBeDug() && thisTile.replacingTile == null) || (isFillingInATile && thisTile.CanBeFilledIn() && thisTile.isConstructed) || (isMarkingATileAsPriority && thisTile.replacingTile != null && !thisTile.replacingTile.isConstructed)) { bool bValid = true; if (isBuildingAThing && thingToBuild == BUILD_ITEM.TRAP && thisTile.y > 0) { bValid = false; } // If digging a tile, also need to check the tile is adjacent to some other lizardy tile. if (isDiggingATile) { TileBase tileOnLeft = null; if (ii - 1 >= 0) { tileOnLeft = Core.theTM.tiles[ii - 1, jj]; } TileBase tileOnRight = null; if (ii + 1 < TileManager.width) { tileOnRight = Core.theTM.tiles[ii + 1, jj]; } TileBase tileAbove = null; if (jj - 1 >= 0) { tileAbove = Core.theTM.tiles[ii, jj - 1]; } TileBase tileBelow = null; if (jj + 1 < TileManager.depth) { tileBelow = Core.theTM.tiles[ii, jj + 1]; } if ((tileOnLeft == null || !tileOnLeft.IsLizardy() || !tileOnLeft.isConstructed) && (tileOnRight == null || !tileOnRight.IsLizardy() || !tileOnRight.isConstructed) && (tileAbove == null || !tileAbove.IsLizardy() || !tileAbove.isConstructed) && (tileBelow == null || !tileBelow.IsLizardy() || !tileBelow.isConstructed)) { bValid = false; } } if (bValid) { // Highlight tile. Also render extra highlight if moused-over. thisTile.bShouldBeHighlighted = true; // If we're mousing over this tile... if (mousedOverTile != null && mousedOverTile == thisTile) { // Render transparent version of some image to indicate mouse over //Instantiate<Sprite>(highlightSprite); // If we clicked on this tile, do the thing! if (bHasClicked) { if (isBuildingAThing) { //Debug.Log("Building a thing!"); int iMetalCost = 0; Resource.ResourceType type = Resource.ResourceType.METAL; TileBase.TileType eTileType = GetTileTypeAndCostToBuild(out iMetalCost, out type); TileBase newTile = null; switch (type) { case Resource.ResourceType.METAL: if (iMetalCost <= Player.thePlayer.metal) { //Player.thePlayer.metal -= iMetalCost; This gets done by lizards now! newTile = Core.theTM.RequestNewTile(thisTile.x, thisTile.y, eTileType, false, iMetalCost, type); } break; case Resource.ResourceType.GEMS: if (iMetalCost <= Player.thePlayer.gems) { //Player.thePlayer.metal -= iMetalCost; This gets done by lizards now! newTile = Core.theTM.RequestNewTile(thisTile.x, thisTile.y, eTileType, false, iMetalCost, type); } break; case Resource.ResourceType.BONES: if (iMetalCost <= Player.thePlayer.dinosaurBones) { //Player.thePlayer.metal -= iMetalCost; This gets done by lizards now! newTile = Core.theTM.RequestNewTile(thisTile.x, thisTile.y, eTileType, false, iMetalCost, type); } break; } if (newTile != null) { Plans p = Instantiate <Plans>(plansPrefab); p.x = thisTile.x; p.y = thisTile.y; p.sprite = newTile.GetComponent <SpriteRenderer>().sprite; p.InitSprites(); plans.Add(p); } else { TextTicker.AddLine("You can't build that. You need more " + (type == Resource.ResourceType.METAL ? "Metal" : (type == Resource.ResourceType.BONES ? "Bones" : "Gems"))); } } else if (isDiggingATile) { //Debug.Log("Digging a tile!"); TileBase.TileType eTileType = TileBase.TileType.EMPTY; TileBase newTile = Core.theTM.RequestNewTile(thisTile.x, thisTile.y, eTileType); Plans p = Instantiate <Plans>(plansPrefab); p.x = thisTile.x; p.y = thisTile.y; p.sprite = newTile.GetComponent <SpriteRenderer>().sprite; p.InitSprites(); plans.Add(p); } else if (isFillingInATile) { //Debug.Log("Filling in a tile!"); TileBase.TileType eTileType = TileBase.TileType.FILLED; Core.theTM.RequestNewTile(thisTile.x, thisTile.y, eTileType); Plans p = Instantiate <Plans>(plansPrefab); p.x = thisTile.x; p.y = thisTile.y; p.sprite = fillSprite; p.InitSprites(); plans.Add(p); } else if (isMarkingATileAsPriority) { //Debug.Log("Marking a tile as priority!"); if (thisTile.replacingTile != null) { thisTile.CancelBuild(); } } } } } } } } if (bHasClicked) { // When anything is clicked, return everything to the default state Reset(); } } }