/// <summary> /// Unlock a new plane slot (allowing the player to take one more plane into battle). /// </summary> private void UnlockSlot(object sender, EventArgs empty) { HangarLayer.UnlockedPlaneSlots++; // show the unlock message State = WreckageState.SLOT_UNLOCK; var popUp = PopUp.ShowPopUp(GUILayer, PopUp.Enum.TRIGGERED_SLOTUNLOCK); popUp.ClickedEvent += (sender2, args) => { State = WreckageState.CAROUSEL; }; }
internal void CheckForWelcome() { // show the welcome message if (PopUp.TriggeredWreckLayer == false && Wrecks.Any()) { State = WreckageState.WELCOME; var popUp = PopUp.ShowPopUp(GUILayer, PopUp.Enum.TRIGGERED_WRECKAGELAYER); popUp.ClickedEvent += (sender, args) => { var popUp2 = PopUp.ShowPopUp(GUILayer, PopUp.Enum.TRIGGERED_WRECKAGELAYER2); popUp2.ClickedEvent += (sender2, args2) => { State = WreckageState.CAROUSEL; }; }; } }
internal void StartPlanningPhase(bool suppressZoomPopup = false) { State = GameState.PLANNING; if (!PopUp.TriggeredZoom && !suppressZoomPopup) { PopUp.ShowPopUp(GUILayer, PopUp.Enum.TRIGGERED_ZOOM); } // find all active chunks // for that first find the player chunks and then grow around them // also calculate the new camera boundaries based on the plane positions float minX = float.PositiveInfinity; float minY = float.PositiveInfinity; float maxX = float.NegativeInfinity; float maxY = float.NegativeInfinity; var activeChunksBefore = new CCPointI[ActiveChunks.Count]; ActiveChunks.CopyTo(activeChunksBefore); ActiveChunks.Clear(); foreach (var aircraft in PlayerAircrafts) { if (aircraft.Position.X < minX) { minX = aircraft.Position.X; } if (aircraft.Position.X > maxX) { maxX = aircraft.Position.X; } if (aircraft.Position.Y < minY) { minY = aircraft.Position.Y; } if (aircraft.Position.Y > maxY) { maxY = aircraft.Position.Y; } var aircraftChunk = PosToWorldChunk(aircraft.Position); for (int dx = -1; dx <= 1; dx++) { for (int dy = -1; dy <= 1; dy++) { var activeChunk = aircraftChunk + new CCPointI(dx, dy); if (!ActiveChunks.Contains(activeChunk)) { ActiveChunks.Add(activeChunk); } } } } var noLongerActiveChunks = new List <CCPointI>(); foreach (CCPointI chunkPoint in activeChunksBefore) { if (!ActiveChunks.Contains(chunkPoint)) { noLongerActiveChunks.Add(chunkPoint); } } const float BORDER = 5500f; CameraSpace = new CCRect(minX - BORDER, minY - BORDER, maxX - minX + BORDER * 2, maxY - minY + BORDER * 2); // check if there are any new chunks // if there are generate their contents (i.e. the enemies that are supposed to be there) foreach (var chunkPoint in ActiveChunks) { if (!KnownChunks.Contains(chunkPoint)) { InitiateChunk(chunkPoint); } } // prepare the squadrons // also find all currently active squadrons and aircrafts ActiveAircrafts.Clear(); ActiveSquadrons.Clear(); foreach (var squadron in Squadrons) { var chunkPoint = PosToWorldChunk(squadron.Position); if (ActiveChunks.Contains(chunkPoint)) { squadron.PrepareForPlanningPhase(this); // add the squadron and the aircrafts to the active lists ActiveSquadrons.Add(squadron); foreach (var aircraft in squadron.AircraftsWithRelPositions.Keys) { ActiveAircrafts.Add(aircraft); } } else if (noLongerActiveChunks.Contains(chunkPoint)) { foreach (var aircraft in squadron.AircraftsWithRelPositions.Keys) { aircraft.PrepareForStandby(); } } } // prepare the player-aircrafts foreach (var aircraft in PlayerAircrafts) { aircraft.PrepareForPlanningPhase(); } // only go back to normal if the player is still alive if (PlayerIsAlive) { // make the ExecuteOrderButton visible again GUILayer.ExecuteOrdersButton.Visible = true; } else { ExecuteOrders(); //AddAction(new CCSequence(new CCDelayTime(0.25f), new CCCallFunc( () => ExecuteOrders() ))); } }
public override void Update(float dt) { base.Update(dt); switch (State) { case GameState.PLANNING: break; case GameState.EXECUTING_ORDERS: { TimeLeftExecutingOrders -= dt; if (Aircraft.CloudFrameCountdown != 0) { Aircraft.CloudFrameCountdown--; } else { Aircraft.CloudFrameCountdown = Aircraft.CLOUD_FRAME_COUNTDOWN; } if (powerUpCheckCountDown != 0) { powerUpCheckCountDown--; } else { powerUpCheckCountDown = PU_CHECK_COUNTDOWN; // check if any powerup is close enough to be picked up foreach (var aircraft in PlayerAircrafts) { if (aircraft.MyState == Aircraft.State.SHOT_DOWN) { continue; } CCPoint aPos = aircraft.Position; foreach (var powerUp in PowerUps) { // only pick up power-ups that are close in x-y but also in z direction if (powerUp.VertexZ > -10f && CCPoint.Distance(powerUp.Position, aPos) < PowerUp.PICKUP_DISTANCE) { // pick up the powerup if (!PopUp.TriggeredPowerUp) { PopUp.ShowPopUp(GUILayer, PopUp.Enum.TRIGGERED_POWERUP); } powerUp.StartPickupAnimation(); aircraft.ChangePowerUpCount(powerUp.Power, 1); PowerUps.Remove(powerUp); break; } } } } // DEBUG: Console.WriteLine("EXECUTING ORDERS; dt: " + dt); // go through all aircrafts and let them execute their orders List <Aircraft> aircraftToBeRemoved = new List <Aircraft>(); // first the enemies (organized into squadrons) foreach (var aircraft in ActiveAircrafts) { aircraft.ExecuteOrders(dt); if (aircraft.ToBeRemoved) { aircraftToBeRemoved.Add(aircraft); } } // then the player aircrafts foreach (var aircraft in PlayerAircrafts) { aircraft.ExecuteOrders(dt); if (aircraft.ToBeRemoved) { aircraftToBeRemoved.Add(aircraft); } } // remove aircrafts that have to be removed foreach (var aircraft in aircraftToBeRemoved) { if (!aircraft.ControlledByPlayer) { // add a powerup if ((new Random()).Next(3) < 2) { var powerUp = aircraft.GeneratePowerUp(); if (powerUp != null) { powerUp.Position = aircraft.Position; AddPowerUp(powerUp); } } } // add an explosion var cloudNode = new CloudTailNode(); cloudNode.AddCloud(new CircleCloud(aircraft.Position, 0, CCColor4B.White, true, aircraft.ContentSize.Width * 16, 6f)); ExplosionNodes.Add(cloudNode); // if the aircraft is not completely made up of scrap parts add it to the salvageable wrecks foreach (var part in aircraft.TotalParts) { if (!(part is BodyScrap) && !(part is DoubleWingScrap) && !(part is RotorScrap) && !(part is RudderScrap) && !(part is WeaponScrap)) { DownedAircrafts.Add(aircraft); break; } } RemoveAircraft(aircraft); } // go through all projectiles and let them advance // check whether a projectile needs to be removed List <Projectile> projectilesToBeRemoved = new List <Projectile>(); foreach (var projectile in Projectiles) { projectile.Advance(dt); if (projectile.CanBeRemoved()) { projectilesToBeRemoved.Add(projectile); } } // go through all clouds that are directly bounds to you List <CloudTailNode> cloudsToBeRemoved = new List <CloudTailNode>(); foreach (var cloudNode in ExplosionNodes) { cloudNode.Advance(dt); if (!cloudNode.HasClouds()) { cloudsToBeRemoved.Add(cloudNode); } } foreach (var cloudNode in cloudsToBeRemoved) { ExplosionNodes.Remove(cloudNode); } UpdateDrawNodes(); if (TimeLeftExecutingOrders <= 0) { StartPlanningPhase(); } } break; } }
internal void InitPlayerAircrafts(List <Aircraft> playerAircrafts) { const float BORDER = 50f; const float theta = (float)Math.PI / 4; // add the aircrafts foreach (var aircraft in playerAircrafts) { aircraft.Team = PlayerTeam; aircraft.ControlledByPlayer = true; aircraft.Scale = Constants.STANDARD_SCALE; AddAircraft(aircraft); aircraft.PartsChanged(true); } PlayerAircrafts = playerAircrafts; // place the aircrafts in "v"-formation if (playerAircrafts.Count() % 2 == 1) { // v with pointy head (1 aircrafts) var pos = CCPoint.Zero; playerAircrafts[0].Position = pos; float y = playerAircrafts[0].ScaledContentSize.Height / 2 + BORDER; var upPos = new CCPoint(-(float)Math.Sin(theta) * y, y); var downPos = new CCPoint(upPos.X, -upPos.Y); bool upside = new Random().NextBoolean(); for (int i = 1; i < playerAircrafts.Count; i++) { var aircraft = playerAircrafts[i]; if (upside) { y = aircraft.ScaledContentSize.Height / 2; upPos += new CCPoint(-(float)Math.Sin(theta) * y, y); aircraft.Position = upPos; y += BORDER; upPos += new CCPoint(-(float)Math.Sin(theta) * y, y); if (upPos.X < downPos.X) { upside = false; } } else { y = aircraft.ScaledContentSize.Height / 2; downPos += new CCPoint(-(float)Math.Sin(theta) * y, -y); aircraft.Position = downPos; y += BORDER; downPos += new CCPoint(-(float)Math.Sin(theta) * y, -y); if (downPos.X < upPos.X) { upside = true; } } } } else { // v with dull head (2 aircrafts) float y = playerAircrafts[0].ScaledContentSize.Height / 2 + BORDER / 2; var upPos = new CCPoint(-(float)Math.Sin(theta) * y, y); playerAircrafts[0].Position = upPos; y += playerAircrafts[0].ScaledContentSize.Height / 2 + BORDER; upPos = new CCPoint(-(float)Math.Sin(theta) * y, y); y = playerAircrafts[1].ScaledContentSize.Height / 2 + BORDER / 2; var downPos = new CCPoint(-(float)Math.Sin(theta) * y, -y); playerAircrafts[1].Position = downPos; y += playerAircrafts[1].ScaledContentSize.Height / 2 + BORDER; downPos = new CCPoint(-(float)Math.Sin(theta) * y, -y); bool upside = new Random().NextBoolean(); for (int i = 2; i < playerAircrafts.Count; i++) { var aircraft = playerAircrafts[i]; if (upside) { y = aircraft.ScaledContentSize.Height / 2; upPos += new CCPoint(-(float)Math.Sin(theta) * y, y); aircraft.Position = upPos; y += BORDER; upPos += new CCPoint(-(float)Math.Sin(theta) * y, y); if (upPos.X < downPos.X) { upside = false; } } else { y = aircraft.ScaledContentSize.Height / 2; downPos += new CCPoint(-(float)Math.Sin(theta) * y, -y); aircraft.Position = downPos; y += BORDER; downPos += new CCPoint(-(float)Math.Sin(theta) * y, -y); if (downPos.X < upPos.X) { upside = true; } } } } CameraPosition = -(CCPoint)CameraSize / 2; UpdateCamera(); // show the welcome message if (!PopUp.TriggeredPlayLayer) { PopUp.ShowPopUp(GUILayer, PopUp.Enum.TRIGGERED_PLAYLAYER); // also remove all power-ups from the aircrafts since this is the first time the player is playing foreach (var aircraft in PlayerAircrafts) { aircraft.ResetPowerUps(); } } StartPlanningPhase(true); }