private void Update() { // controls for changing page float movement = Input.GetAxis("Horizontal"); if (movement > 0.8f) { if (!justChangedPage) { currentPage++; } justChangedPage = true; } else if (movement < -0.8f) { if (!justChangedPage) { currentPage--; } justChangedPage = true; } else { justChangedPage = false; } if (currentPage < 0) { currentPage = 2; } if (currentPage > 2) { currentPage = 0; } PageFuel.SetActive(currentPage == 0); PageCargo.SetActive(currentPage == 1); PageUpgrade.SetActive(currentPage == 2); switch (currentPage) { case 0: // fuel PageTitle.text = "Refuel"; float fuelMissing = plr.FuelMax - plr.Fuel; int fuelCost = Mathf.RoundToInt(fuelMissing * Tuning.COST_FUEL); if (fuelCost > plr.Money && plr.Money > 0) { fuelMissing = plr.Money / Tuning.COST_FUEL; fuelCost = plr.Money; FuelCostText.text = String.Format("Partially refuel {1:0} L for ${0:##,##0}?", fuelCost, fuelMissing); ConfirmText.color = blackColor; ConfirmText.text = "Refuel"; } else if (fuelMissing > 0.5f) { FuelCostText.text = String.Format("Buy {1:0} L of fuel for ${0:##,##0}?", fuelCost, fuelMissing); ConfirmText.color = fuelCost <= plr.Money ? blackColor : redColor; ConfirmText.text = fuelCost <= plr.Money ? "Refuel" : "Can't Afford"; } else { FuelCostText.text = "Your fuel tank is full."; ConfirmText.color = redColor; ConfirmText.text = "N/A"; } // Confirm key to get the fuel if (Input.GetButtonDown("Confirm") && fuelMissing > 0.5f) { if (fuelCost <= plr.Money) { plr.Fuel += fuelMissing; plr.Money -= fuelCost; gctl.SetShopOpen(false); } else { // cannot afford? // TODO: buzzer noise or something } } break; case 1: // cargo PageTitle.text = "Sell Cargo"; bool victory = false; StringBuilder sbLeft = new StringBuilder(); StringBuilder sbRight = new StringBuilder(); int cargoValue = 0; for (CargoType cargoType = CargoType.Iron; cargoType <= CargoType.Katanium; cargoType++) { var cargoTypeWrapper = cargoType; int cargoCount = plr.Cargo.Count(thing => thing == cargoTypeWrapper); if (cargoCount < 1) { continue; } // player wins by selling an unobtainium if (cargoType == CargoType.Unobtainium) { victory = true; } // total the value int thisCargoValue = Tuning.GetMineralStats(cargoType).Value *cargoCount; cargoValue += thisCargoValue; sbLeft.AppendLine(cargoType.ToString() + ":"); if (cargoCount == 1) { sbRight.AppendFormat("${0:##,##0}", thisCargoValue); } else { sbRight.AppendFormat("{0} x ${1:##,##0} = ${2:##,##0}", cargoCount, Tuning.GetMineralStats(cargoType).Value, thisCargoValue); } sbRight.AppendLine(); } if (cargoValue == 0) { sbLeft.AppendLine("You have nothing to sell."); ConfirmText.text = "N/A"; } else { sbLeft.AppendLine(); sbLeft.AppendFormat("Total: ${0:##,##0}", cargoValue); ConfirmText.text = "Sell All"; } CargoLeftText.text = sbLeft.ToString(); CargoRightText.text = sbRight.ToString(); ConfirmText.color = cargoValue > 0 ? blackColor : redColor; //String.Format("+${0:##,##0} / {1} items", cargoValue, plr.Cargo.Count); //int netValue = cargoValue - fuelCost; //TotalText.text = String.Format("= {0}${1:##,##0}", netValue < 0 ? "-" : "+", Mathf.Abs(netValue)); //TotalText.color = netValue < 0 ? redColor : blackColor; //bool canAfford = plr.Money + netValue >= 0; if (Input.GetButtonDown("Confirm") && cargoValue > 0) { plr.Money += cargoValue; plr.Cargo.Clear(); gctl.SetShopOpen(false); if (victory) { gctl.Victory = true; } } break; case 2: // upgrades PageTitle.text = "Upgrades"; float vertMove = Input.GetAxis("Vertical"); if (vertMove > 0.8f) { currentUpgrade = 0; } else if (vertMove < -0.8f) { currentUpgrade = 1; } UpgradeArrow.rectTransform.anchoredPosition = new Vector2(45f, -105f - 100f * currentUpgrade); StringBuilder sb = new StringBuilder(); sb.AppendLine("Fuel Tank:"); if (plr.LevelFuel < 7) { sb.AppendFormat("${0:##,##0} - {1:0} L", Tuning.GetUpgradeCost(plr.LevelFuel + 1), Tuning.GetFuelCapacity(plr.LevelFuel + 1)); sb.AppendLine(); } else { sb.AppendLine("Maxed!"); } sb.AppendLine(); sb.AppendLine("Cargo Bay:"); if (plr.LevelCargo < 7) { sb.AppendFormat("${0:##,##0} - {1:0} slots", Tuning.GetUpgradeCost(plr.LevelCargo + 1), Tuning.GetCargoCapacity(plr.LevelCargo + 1)); } else { sb.AppendLine("Maxed!"); } UpgradeText.text = sb.ToString(); int currentLevel = currentUpgrade == 0 ? plr.LevelFuel : plr.LevelCargo; int cost = Tuning.GetUpgradeCost(currentLevel + 1); bool canBuy = cost <= plr.Money && currentLevel < 7; ConfirmText.color = cost <= plr.Money ? blackColor : redColor; ConfirmText.text = currentLevel < 7 ? (cost <= plr.Money ? "Purchase" : "Can't Afford") : "Maxed"; if (Input.GetButtonDown("Confirm") && canBuy) { plr.Money -= cost; switch (currentUpgrade) { case 0: plr.LevelFuel++; plr.FuelMax = Tuning.GetFuelCapacity(plr.LevelFuel); plr.Fuel = plr.FuelMax; break; case 1: plr.LevelCargo++; plr.CargoCapacity = Tuning.GetCargoCapacity(plr.LevelCargo); break; default: Debug.LogError("bad currentUpgrade"); break; } gctl.SetShopOpen(false); } break; } if (Input.GetButtonDown("Cancel")) { gctl.SetShopOpen(false); Input.ResetInputAxes(); } }
public void PickUp() { Player plr = FindObjectOfType <Player>(); CargoType cargo = GetCargoType(type); if (cargo == CargoType.Invalid) { switch (type) { case TileType.Artifact: plr.Score += 10000; plr.Money += 5000; DoFloatyText("Ancient Artifact: $5,000"); return; case TileType.Fossil: plr.Score += 2500; plr.Money += 1000; DoFloatyText("Fossil: $1,000"); return; case TileType.Oil: plr.Score += 2500; plr.Fuel = Math.Min(plr.Fuel + 20f, plr.FuelMax); DoFloatyText("Oil: Restored Fuel"); return; default: // stone, probably plr.Score += 25; return; } } if (cargo == CargoType.Unobtainium) { plr.Score += 20000; } else { plr.Score += Tuning.GetMineralStats(cargo).Value * 4; } // specify mergeable minerals CargoType mergeRequire = CargoType.Invalid; CargoType mergeResult = CargoType.Invalid; if (cargo == CargoType.Tin) { mergeRequire = CargoType.Copper; mergeResult = CargoType.Bronze; } if (cargo == CargoType.Copper) { mergeRequire = CargoType.Tin; mergeResult = CargoType.Bronze; } if (cargo == CargoType.Iron) { mergeRequire = CargoType.Platinum; mergeResult = CargoType.Oragnium; } if (cargo == CargoType.Platinum) { mergeRequire = CargoType.Iron; mergeResult = CargoType.Oragnium; } if (cargo == CargoType.Adamantium) { mergeRequire = CargoType.Gold; mergeResult = CargoType.Katanium; } if (cargo == CargoType.Gold) { mergeRequire = CargoType.Adamantium; mergeResult = CargoType.Katanium; } // attempt to merge two cargo items if (mergeRequire != CargoType.Invalid) { int index = plr.Cargo.IndexOf(mergeRequire); if (index != -1) { if (!mergeTutorialShown) { // tutorial popup for combining minerals mergeTutorialShown = true; TutorialManager.QueueTutorial(3); } DoFloatyText(String.Format("{0} + {1} = {2}", cargo, mergeRequire, mergeResult)); plr.Cargo[index] = mergeResult; // replace the existing slot with the merged type return; } } if (plr.Cargo.Count >= plr.CargoCapacity && cargo != CargoType.Unobtainium) { DoFloatyText("CARGO FULL"); } else { DoFloatyText(type.ToString()); plr.Cargo.Add(cargo); } }
private void Start() { #if !UNITY_EDITOR Cursor.lockState = CursorLockMode.Confined; Cursor.visible = false; #endif GameOver = false; Transform cachedTransform = transform; for (int x = -15; x < Tuning.MAP_WIDTH + 15; x++) { for (int z = 1; z < 10; z++) { Vector3 pos = MapToWorld(x, 0); pos.z = z; GameObject tile = Instantiate(TilePrefab); tile.transform.position = pos; tile.transform.rotation = Quaternion.Euler(0f, 0f, Random.Range(0, 4) * 90f); // randomly rotate for variation tile.transform.SetParent(cachedTransform); tile.GetComponent <Tile>().type = TileType.Barrier; } } map = new GameObject[Tuning.MAP_WIDTH, Tuning.MAP_HEIGHT]; for (int y = 0; y < Tuning.MAP_HEIGHT + 8; y++) { for (int x = -10; x < Tuning.MAP_WIDTH + 10; x++) { GameObject tileBack = Instantiate(TileBackPrefab); tileBack.transform.localPosition = MapToWorld(x, y) + new Vector3(0, 0, 0.5f); tileBack.transform.rotation = Quaternion.Euler(0f, 0f, Random.Range(0, 4) * 90f); // randomly rotate for variation tileBack.transform.SetParent(cachedTransform); GameObject tile = Instantiate(TilePrefab); tile.transform.position = MapToWorld(x, y); tile.transform.rotation = Quaternion.Euler(0f, 0f, Random.Range(0, 4) * 90f); // randomly rotate for variation tile.transform.SetParent(cachedTransform); Tile tilescript = tile.GetComponent <Tile>(); TileType type; if (x >= 0 && x < Tuning.MAP_WIDTH && y < Tuning.MAP_HEIGHT) { map[x, y] = tile; if (y == 0 && x >= 9 && x <= 14) { type = TileType.Barrier; } else if (y >= Tuning.MAP_HEIGHT - 1) { type = TileType.Barrier; } else { type = TileType.Stone; } } else { type = TileType.Barrier; } tilescript.type = type; } } // now generate all minerals for (TileType block = TileType.Iron; block <= TileType.Unobtainium; block++) { CargoType cargo = Tile.GetCargoType(block); MineralStats stats = Tuning.GetMineralStats(cargo); while (stats.Density > 0) { int mx = Random.Range(0, Tuning.MAP_WIDTH); int my = Random.Range(stats.MinDepth, stats.MaxDepth - 1); if (map[mx, my] == null) { continue; } var script = map[mx, my].GetComponent <Tile>(); if (script.type != TileType.Boulder) { script.type = block; } stats.Density--; } } // and place special thingers for (TileType block = TileType.Artifact; block <= TileType.Boulder; block++) { int count; switch (block) { case TileType.Artifact: count = Random.Range(4, 7); break; case TileType.Boulder: count = Random.Range(100, 130); break; default: count = Random.Range(10, 15); break; } while (count > 0) { count--; int mx = Random.Range(0, Tuning.MAP_WIDTH); int my = Random.Range(30, Tuning.MAP_HEIGHT); if (map[mx, my] == null) { continue; } var script = map[mx, my].GetComponent <Tile>(); if (script.type == TileType.Stone) { script.type = block; } } } // place a few gaps int gaps = Random.Range(50, 75); while (gaps > 0) { gaps--; int mx = Random.Range(0, Tuning.MAP_WIDTH); int my = Random.Range(0, Tuning.MAP_HEIGHT); int gapsize = Random.Range(0, 5) - 2; if (gapsize <= 0) { // single dot if (mx < 0 || my < 1 || mx >= Tuning.MAP_WIDTH || my >= Tuning.MAP_HEIGHT - 1) { continue; } if (map[mx, my] == null) { continue; // cannot remove blocks that are already gone } if (map[mx, my].GetComponent <Tile>().type != TileType.Stone) { continue; // cannot overwrite minerals } Destroy(map[mx, my]); map[mx, my] = null; } else { // larger gap for (int x = mx - gapsize; x <= mx + gapsize; x++) { for (int y = my - gapsize; y <= my + gapsize; y++) { if (x < 0 || y < 1 || x >= Tuning.MAP_WIDTH || y >= Tuning.MAP_HEIGHT - 1) { continue; // in map bounds } if (Vector2.Distance(new Vector2(x, y), new Vector2(mx, my)) > gapsize) { continue; // make circles } if (map[x, y] == null) { continue; // cannot remove blocks that are already gone } if (map[x, y].GetComponent <Tile>().type != TileType.Stone) { continue; // cannot overwrite minerals } Destroy(map[x, y]); map[x, y] = null; if (Random.value > 0.8f) { gapsize = Mathf.Max(1, gapsize - 1); } } } } } //map[0, 0].GetComponent<Tile>().type = TileType.Unobtainium; }