void removeShip() { if (ships.Count > 0) { FleetShip ship = ships[ships.Count - 1]; RemoveShip(ship); } }
// Update is called once per frame void Update() { if (player == null & Utilities.IsLevelLoaded() && !Utilities.IsGameOver()) { player = PlayerManager.GetControllablePlayer(); if (player != null) { networkedPlayer = player.GetComponent <NetworkedPlayer>(); playerScore = player.GetComponent <PlayerScore>(); } fleetShips = PlayerManager.GetOwnedFleetAI(); fleetShipToSpawn = GetFleetShipToSpawn(); } if (networkedPlayer != null) { if (networkedPlayer.IslandWithinRange != null) { nearbyIsland = networkedPlayer.IslandWithinRange.GetComponent <IslandDiscoveryTrigger>(); fleetButton.interactable = true; patrolButton.interactable = true; //TODO: Enable cannonButton once cannon upgrades have been implemented. //cannonButton.interactable = true; } else { nearbyIsland = null; fleetButton.interactable = false; patrolButton.interactable = false; cannonButton.interactable = false; } } if (fleetButton.IsInteractable() && Input.GetAxis("BuyFleetShip") == 1 && fleetButtonTimer >= buttonPressCooldown) { FleetButtonPress(); fleetButtonTimer = 0.0f; } if (patrolButton.IsInteractable() && Input.GetAxis("BuyPatrolShip") == 1 && patrolButtonTimer >= buttonPressCooldown) { PatrolButtonPress(); patrolButtonTimer = 0.0f; } //TODO: Add cannon upgrade button. if (fleetButtonTimer < buttonPressCooldown) { fleetButtonTimer += Time.deltaTime; } if (patrolButtonTimer < buttonPressCooldown) { patrolButtonTimer += Time.deltaTime; } }
void setSlot(FleetShip ship, int slotIndex) { Formation.Slot slot = formation.slots[slotIndex]; ship.target.x = slot.x; ship.target.z = slot.z; ship.fire = false; // Call updateFiring() ship.slot = slotIndex; slots[slotIndex] = ship; }
public void SetShipCount(int shipTypeID, int count) { var entry = FleetShips.SingleOrDefault(x => x.ShipTypeID == shipTypeID); if (entry == null) { entry = new FleetShip(); entry.ShipTypeID = shipTypeID; FleetShips.Add(entry); } entry.Count = count; if (count == 0) { FleetShips.Remove(entry); } }
/** * load Fleet ship prefabs */ void LoadFleetShips() { fleetShipPrefabs = new Dictionary <Tuple <Race, HullClass>, FleetShip>(); var objects = Resources.LoadAll("Fleet", typeof(GameObject)); foreach (GameObject obj in objects) { FleetShip ship = obj.GetComponent <FleetShip>(); if (ship != null) { Race race = (Race)ship.GetType().GetField("race").GetRawConstantValue(); HullClass hullClass = (HullClass)ship.GetType().GetField("hullClass").GetRawConstantValue(); fleetShipPrefabs.Add(new Tuple <Race, HullClass>(race, hullClass), ship); continue; } } }
/// <summary> /// add a new ship to this player's flotilla. /// </summary> public void AddShip(ShipData shipType) { FrameworkCore.PlayCue(sounds.Fanfare.ship); FleetShip ship = Helpers.AddFleetShip(FrameworkCore.players[0].campaignShips, shipType); //create popup. if (ship == null) { return; } ShipPopup popup = new ShipPopup(menuManager); popup.fleetShip = ship; menuManager.AddMenu(popup); }
public void RemoveShip(FleetShip ship) { // Remove ship from the list bool success = ships.Remove(ship); System.Diagnostics.Debug.Assert(success); if (!success) { return; } // If something was behind the ship, see if it can fire now slots[ship.slot] = null; int backward = formation.slots[ship.slot].backward; if (backward >= 0) { FleetShip backShip = slots[backward]; if (backShip != null) { int forward = formation.slots[ship.slot].forward; while (true) { if (forward == -1) { // Shot is clear backShip.fire = true; break; } else if (slots[forward] != null) { break; } forward = formation.slots[forward].forward; } } } // Destroy the ship GameObject.Destroy(ship.gameObject); }
void addShip() { if (ships.Count < MaxShips) { // Create the ship GameObject shipObj = GameObject.Instantiate(shipPrefab); FleetShip ship = shipObj.GetComponent <FleetShip>(); ship.fleet = this; ship.name = "Ship" + ships.Count; ship.transform.parent = transform; ships.Add(ship); // If there are any empty slots in the current formation, take the first one for (int i = 0; i < formation.slots.Length; i++) { if (slots[i] == null) { setSlot(ship, i); updateFiring(); return; } } // If no empty slot was found, choose a larger formation { formation = Formation.Get(formation.type, ships.Count); // Position the new ship setSlot(ship, formation.newSlot); // Re-position the old ships for (int i = 0; i < ships.Count - 1; i++) { setSlot(ships[i], formation.slots[ships[i].slot].newIndex); } } updateFiring(); } }
override protected Constellation Construct(ConstellationManifest conMf) { Constellation con; if (constellations.TryGetValue(conMf.position, out con)) { return(con); } con = Instantiate(constellationPrefab) as MapConstellation; con.Manifest = conMf; con.transform.localPosition = conMf.position; // stars foreach (var starMf in conMf.stars) { MapStar starPf = game.GetMapStarPrefab(starMf.color); MapStar star = Instantiate(starPf) as MapStar; star.manifest = starMf; star.constellation = con; con.Stars.Add(star); // universeBounds.Encapsulate(con.transform.position + starMf.position); } // Fleet foreach (var shipMf in conMf.fleet) { FleetShip shipPf = game.GetFleetShipPrefab(shipMf); FleetShip ship = Instantiate(shipPf) as FleetShip; ship.transform.parent = con.transform; ship.transform.localPosition = shipMf.position; ship.transform.localScale = new Vector3(3f, 3f, 3f); ship.manifest = shipMf; con.Fleet.Add(ship); } constellations.Add(con.Manifest.position, con); return(con); }
/// <summary> /// Returns an unpurchased FleetShip owned by the client that is ready to be spawned. /// </summary> /// <returns> /// A FleetShip ready to be spawned or null if there aren't any. /// </returns> private FleetShip GetFleetShipToSpawn() { FleetShip temp = null; if (fleetShips != null) { for (int i = 0; i < fleetShips.Length; ++i) { NetworkedAI ai = fleetShips[i].GetComponentInChildren <NetworkedAI>(); FleetAI fleet = fleetShips[i].GetComponentInChildren <FleetAI>(); if (ai != null && fleet != null) { if (!fleet.Purchased) { temp = new FleetShip(ai, fleet); break; } } } } return(temp); }
/// <summary> /// add a random ship to this player's flotilla. /// </summary> public void AddShip(ShipData[] shipType, bool chanceToUpgrade) { FrameworkCore.PlayCue(sounds.Fanfare.ship); ShipData shipToAdd = shipType[FrameworkCore.r.Next(shipType.Length)]; if (chanceToUpgrade) { shipToAdd = UpgradeShip(shipToAdd); } FleetShip ship = Helpers.AddFleetShip(FrameworkCore.players[0].campaignShips, shipToAdd); //create popup. if (ship == null) { return; } ShipPopup popup = new ShipPopup(menuManager); popup.fleetShip = ship; menuManager.AddMenu(popup); }
public void FleetButtonPress() { string failureMsg = string.Empty; bool success = false; fleetShipToSpawn = GetFleetShipToSpawn(); if (fleetShipToSpawn != null) { if (!fleetShipToSpawn.aiShip.Purchased) { if ((playerScore.RoundedScore - fleetShipCost) >= 0.0f) { if (fleetShipToSpawn.aiShip.AssignFormationPosition()) { fleetShipToSpawn.networkedAI.SetVisible(true, false); fleetShipToSpawn.aiShip.Purchased = true; playerScore.MinusScore(fleetShipCost); success = true; } else { success = false; failureMsg = "No formationPositions available."; } } else { success = false; failureMsg = "Player has insufficient coin to purchase a ship."; } } else { success = false; failureMsg = "Ship has already been purchased."; } } else { success = false; if (viewDebuggingInfo) { failureMsg = "The fleetShipToSpawn was null."; } } if (success) { //Play success noise / ship spawn noise. } else { Debug.Log(failureMsg); //Play failure noise. } //TODO: Remove once success and failure noises have been added. if (soundManager != null) { soundManager.PlaySound(SoundManager.SoundID.BUTTON_CLICK); } if (viewDebuggingInfo) { Debug.Log("FleetButtonPress."); } }
// Update is called once per frame void Update() { if (player == null & Utilities.IsLevelLoaded() && !Utilities.IsGameOver()) { player = PlayerManager.GetControllablePlayer(); if(player != null) { networkedPlayer = player.GetComponent<NetworkedPlayer>(); playerScore = player.GetComponent<PlayerScore>(); } fleetShips = PlayerManager.GetOwnedFleetAI(); fleetShipToSpawn = GetFleetShipToSpawn(); } if (networkedPlayer != null) { if (networkedPlayer.IslandWithinRange != null) { nearbyIsland = networkedPlayer.IslandWithinRange.GetComponent<IslandDiscoveryTrigger>(); fleetButton.interactable = true; patrolButton.interactable = true; //TODO: Enable cannonButton once cannon upgrades have been implemented. //cannonButton.interactable = true; } else { nearbyIsland = null; fleetButton.interactable = false; patrolButton.interactable = false; cannonButton.interactable = false; } } if (fleetButton.IsInteractable() && Input.GetAxis("BuyFleetShip") == 1 && fleetButtonTimer >=buttonPressCooldown) { FleetButtonPress(); fleetButtonTimer = 0.0f; } if (patrolButton.IsInteractable() && Input.GetAxis("BuyPatrolShip") == 1 && patrolButtonTimer >= buttonPressCooldown) { PatrolButtonPress(); patrolButtonTimer = 0.0f; } //TODO: Add cannon upgrade button. if (fleetButtonTimer < buttonPressCooldown) { fleetButtonTimer += Time.deltaTime; } if (patrolButtonTimer < buttonPressCooldown) { patrolButtonTimer += Time.deltaTime; } }
/// <summary> /// Returns an unpurchased FleetShip owned by the client that is ready to be spawned. /// </summary> /// <returns> /// A FleetShip ready to be spawned or null if there aren't any. /// </returns> private FleetShip GetFleetShipToSpawn() { FleetShip temp = null; if (fleetShips != null) { for (int i = 0; i < fleetShips.Length; ++i) { NetworkedAI ai = fleetShips[i].GetComponentInChildren<NetworkedAI>(); FleetAI fleet = fleetShips[i].GetComponentInChildren<FleetAI>(); if (ai != null && fleet != null) { if (!fleet.Purchased) { temp = new FleetShip(ai, fleet); break; } } } } return temp; }
private int DrawUpgrades(GameTime gameTime, FleetShip ship, Vector2 pos) { int lowestY = 0; pos.Y += Helpers.PopLerp(Transition, -100, 30, 0); Color whiteColor = Color.Lerp(OldXNAColor.TransparentWhite, Color.White, Transition); Vector2 boxPos = pos; for (int i = 0; i < ship.upgradeArray.Length; i++) { #if WINDOWS if (FrameworkCore.players[0].campaignShips.IndexOf(ship) == selectedIndex) { boxCenters[i] = boxPos; } #endif Color boxColor = new Color(64, 64, 64); if (ship.upgradeArray[i] != null) { boxColor = Helpers.ITEMCOLOR; } boxColor = Color.Lerp(Helpers.transColor(boxColor), boxColor, Transition); //THE SQUARE. FrameworkCore.SpriteBatch.Draw(FrameworkCore.hudSheet, boxPos, sprite.roundSquare, boxColor, 0, Helpers.SpriteCenter(sprite.roundSquare), 1, SpriteEffects.None, 0); if (selectedInventoryIndex == i) { Color selectColor = Color.Lerp(Helpers.transColor(Color.Orange), Color.Orange, Transition); selectColor = Color.Lerp(Helpers.transColor(selectColor), selectColor, ship.menuHoverTransition); float selectSize = (TopOfStack() ? (1.1f + Helpers.Pulse(gameTime, 0.05f, 8)) : (1.1f)); FrameworkCore.SpriteBatch.Draw(FrameworkCore.hudSheet, boxPos, sprite.roundSquareSelector, selectColor, 0, Helpers.SpriteCenter(sprite.roundSquareSelector), selectSize, SpriteEffects.None, 0); } Vector2 boxTextPos = boxPos; boxTextPos.X += sprite.roundSquare.Width / 2 + 16; boxTextPos.Y -= LINESIZE.Y; if (ship.upgradeArray[i] != null) { if (ship.upgradeArray[i].image != null) { FrameworkCore.SpriteBatch.Draw(FrameworkCore.hudSheet, boxPos, ship.upgradeArray[i].image, whiteColor, 0, Helpers.SpriteCenter(ship.upgradeArray[i].image), 0.9f, SpriteEffects.None, 0); } if (ship.upgradeArray[i].name != null) { FrameworkCore.SpriteBatch.DrawString(FrameworkCore.Serif, ship.upgradeArray[i].name, boxTextPos, whiteColor); } boxTextPos.Y += LINESIZE.Y; if (ship.upgradeArray[i].description != null) { Color descriptionColor = Color.Lerp(Helpers.transColor(Color.Gray), Color.Gray, Transition); FrameworkCore.SpriteBatch.DrawString(FrameworkCore.Serif, ship.upgradeArray[i].description, boxTextPos, descriptionColor); } } else { Color slotColor = Color.Lerp(new Color(80, 80, 80, 0), new Color(80, 80, 80), Transition); boxTextPos.Y += LINESIZE.Y / 2; FrameworkCore.SpriteBatch.DrawString(FrameworkCore.Serif, Resource.MenuSkirmishEmptySlot, boxTextPos, slotColor); } lowestY = (int)boxPos.Y; boxPos.Y += sprite.roundSquare.Height + 16; } return(lowestY); }