/// <summary> /// Respawns enemy ships according to the fleet of the player and the number of remaining enemy ships. /// </summary> // ReSharper disable once UnusedMember.Global private void RespawnShips() { if (GhostShip != null) { return; } var randomNumber = new Random(); var mapParts = RessourceManager.GetRessourceInt("mapParts"); if (mAiFisherShipList.Count < 12) { //spawn Fisherships until there are enough //random position var spawnPosition = new Vector2(randomNumber.Next(200, 5600), randomNumber.Next(200, 5600)); var cell = Game1.mMapScreen.mGridMap.GetCell(spawnPosition); if (cell.IsWalkable && !cell.Occupied && !VisibilityManager.IsVisible(spawnPosition)) { SpawnAiFisherShip(spawnPosition); } } if (mAiTradingShipList.Count < 7)//static number of tradingships { //spawn var spawnPosition = new Vector2(randomNumber.Next(300, 5600), randomNumber.Next(300, 5600)); var cell = Game1.mMapScreen.mGridMap.GetCell(spawnPosition); if (cell.IsWalkable && !cell.Occupied && !VisibilityManager.IsVisible(spawnPosition)) { SpawnAiTradingShip(spawnPosition); } } if (mAiBattleShipsList.Count < 2 + mapParts * 3)//by collecting more mapParts, the count of battleships increases { //spawn var spawnPosition = new Vector2(randomNumber.Next(400, 5600), randomNumber.Next(400, 5600)); var cell = Game1.mMapScreen.mGridMap.GetCell(spawnPosition); if (cell.IsWalkable && !cell.Occupied && !VisibilityManager.IsVisible(spawnPosition)) { SpawnAiBattleShip(spawnPosition); } } if (mAiFleetList.Count < mapParts - 2 && mAiFleetList.Count < 3)// only up to 3 fleets { //random SpawnPoint from List. var spawnPosition = mFleetSpawnPoints[randomNumber.Next(0, mFleetSpawnPoints.Count - 1)]; if (mapParts < 3) { SpawnAiFleet(spawnPosition, 2, 1); } else { SpawnAiFleet(spawnPosition, 3, 2);//increase strength of the fleets } } }
/// <summary> /// Renders every Ship. /// </summary> internal void Draw(SpriteBatch spriteBatch) { foreach (var s in mAllShipList) { var shipRect = new Rectangle( (int)(s.Position.X - s.mShipTexture.Width / 2f), (int)(s.Position.Y - s.mShipTexture.Height / 2f), s.mShipTexture.Width, s.mShipTexture.Height); #if DEBUG spriteBatch.DrawRectangle(shipRect, Color.Red, 2f); // Draw a Rectangle around the ship. #endif if (!VisibilityManager.IsVisible(shipRect)) { continue; // Skip not visible ships } // rotationstest; auswahl rechteck muss ersetzt werden, da es nicht rotiert werden kann!!elf var origin = new Vector2(s.mShipTexture.Width / 2f, s.mShipTexture.Height / 2f); spriteBatch.Draw(s.mShipTexture, new Rectangle((int)s.Position.X, (int)s.Position.Y, s.mShipTexture.Width, s.mShipTexture.Height), null, Color.White, s.Direction.ToAngle() - (MathHelper.Pi / 2), origin, SpriteEffects.None, 0f); if (s.Selected) { // livebar and selection circle. // Draw Circle when selected. var scaleRectangle = new Rectangle((int)s.Position.X - s.mShipTexture.Width / 2 - 10, (int)s.Position.Y - s.mShipTexture.Width / 2 - 10, s.mShipTexture.Width + 20, s.mShipTexture.Width + 20); spriteBatch.Draw(mSelectionCircle, scaleRectangle, s.Owned ? Color.Green : Color.Red); if (s.HealthBar == null) { s.HealthBar = new Bar(!s.Owned, s.Hp, s.MaxHp, LanguageManager.GetText("PSM_hp"), mSmolFont, (s.Position + new Vector2(40, -40)), new Rectangle(180, 577, 70, 16), true); s.HealthBar.HealthOrCrewBar = true; } else { s.HealthBar.Update(s.Hp, (s.Position + new Vector2(40, -40))); } s.HealthBar.Draw(spriteBatch); if (s.Owned && s.Moving && s.ShipPath.Length > 0) { // draw the destination of the Path. CircleF destCircleF = new CircleF(s.ShipPath.TargetNode.Cell.Center, 15f); spriteBatch.DrawCircle(destCircleF, 4, Color.Black, 5f); } } if (s.IsEntered) { if (s.CrewBar == null) { s.CrewBar = new Bar(!s.Owned, s.EnterAttackValue, s.MaxFreePirates, LanguageManager.GetText("PSM_crew"), mSmolFont, (s.Position + new Vector2(40, -60)), new Rectangle(180, 577, 70, 16), true); s.CrewBar.HealthOrCrewBar = true; } else { s.CrewBar.Update(s.EnterAttackValue); } s.CrewBar.Draw(spriteBatch); } var ship = s as BattleShip; var bShip = ship; if (bShip?.CurrentBState == BattleShip.ShipBattleState.Entering && bShip.Docking) { if (ship.CrewBar == null) { ship.CrewBar = new Bar(!bShip.Owned, ship.EnterAttackValue, ship.MaxFreePirates, LanguageManager.GetText("PSM_crew"), mSmolFont, (ship.Position + new Vector2(40, -60)), new Rectangle(180, 577, 70, 16), true); ship.CrewBar.HealthOrCrewBar = true; } else { ship.CrewBar.Update(ship.EnterAttackValue, ship.Position); } ship.CrewBar.Draw(spriteBatch); } if (DebugDrawPath) { DebugPathDraw(spriteBatch, s.ShipPath); } } }
/// <summary> /// Handle all Input /// </summary> internal void HandleInput() { //MouseState mouseState = Mouse.GetState(); // Calculate the mousePosition in the map //mMouseInWorldPosition = mCamera2D.ScreenToWorld(new Vector2(mouseState.X, mouseState.Y)); mMouseInWorldPosition = Game1.mMapScreen.GetWorldPosition(InputManager.MousePosition().ToVector2()); var range = ResolutionManager.Scale().X *20; // Some stuff only used for demonstration. // Spawn a battle Ship to the right of the flagship. if (InputManager.KeyDown(Keys.I)) { mAiShipManager.SpawnAiBattleShip(FlagShip.Position + 200 * Vector2.UnitX); } // Spawn the Admiral fleet. if (InputManager.KeyDown(Keys.K)) { Game1.mEventScreen.mEventManager.StartQuest3(); } // Spawn the GhostShip. if (InputManager.KeyDown(Keys.N)) { Game1.mMapScreen.mPlayerShipManager.mAiShipManager.SpawnGhostShip(new Vector2(4200, 860)); Game1.mEventScreen.mEventManager.mGhostShipinGame = true; } // Add KartenFragment if (InputManager.KeyDown(Keys.L)) { RessourceManager.AddRessource("mapParts", +1); } // Spawn own Battleship near us. if (InputManager.KeyDown(Keys.J)) { SpawnBattleShip(FlagShip.Position - 200 * Vector2.UnitX, true); } if (InputManager.LeftMouseButtonDown()) { //check if there are ships selected to sort out how the input should be processed. if (mSelectShipList.Count == 0) { //check for every Ship, if it is selected foreach (var ship in mAllShipList) { //testweise ein quadrat über die mitte des schiffs. var selectRange = new CircleF(ship.Position, range); if (!selectRange.Contains(mMouseInWorldPosition)) { continue; } if (VisibilityManager.IsVisible(mMouseInWorldPosition)) { ship.Selected = true; mSelectShipList.Add(ship); } break; //when the mouse was clicked, obviously one ship can be selected. } } else//unselect Ships { UnselectShips(); } } else if (InputManager.RightMouseButtonDown() && mSelectShipList.Count > 0) { if (InputManager.KeyPressed(InputManager.HotKey("Hk1")) || mShipState == ShipState.Attacking) { SetShipsAttacking(); } else if (InputManager.KeyPressed(InputManager.HotKey("Hk3")) || mShipState == ShipState.Defending) { SetShipsDefending(); } else if (InputManager.KeyPressed(InputManager.HotKey("Hk2")) || mShipState == ShipState.Boarding) { SetShipsBoarding(); } else { SetShipsMoving(); } } //Selectbox selecting if (InputManager.mSelectionBoxFinished) { InputManager.mSelectionBoxFinished = false; var selBoxOld = InputManager.SelectBox(); var shipsOwned = false; foreach (var ship in mAllShipList) { if (!selBoxOld.Contains(ship.Position)) { continue; } if (VisibilityManager.IsVisible(selBoxOld)) { ship.Selected = true; mSelectShipList.Add(ship); if (ship.Owned) { shipsOwned = true; } } } if (shipsOwned) { var actuallySelected = new List <AShip>(); foreach (var ship in SelectShipList) { if (ship.Owned) { actuallySelected.Add(ship); } else { ship.Selected = false; } } SelectShipList = actuallySelected; } } //check for repairing commands if (InputManager.KeyPressed(InputManager.HotKey("Hk4"))) { AddRepairingShips(); } else if (InputManager.KeyReleased(InputManager.HotKey("Hk5"))) // Rum { foreach (var ship in mSelectShipList) { if (RessourceManager.GetRessourceInt("rum") > 0) { Random random = new Random(); SoundManager.PlayEfx("efx/burping/" + random.Next(1, 7)); //increase crew if its the first rum if (ship.RumBuffDuration <= 0f) { ship.AttackValue += 5; ship.EnterAttackValue += 5; ship.RepairingValue += 5; ship.MovementSpeed += 0.1f; } //increase duration and rumCounter ship.RumDrunken++; ship.RumBuffDuration += 5; //ship.RumBuffDuration += 7; RessourceManager.AddRessource("rum", -1); } else { SoundManager.PlayAmb("No_Rum", false); } } } //Hud aufrufen /* if (mSelectShipList.Count >= 1) * { * HudScreen.HudScreenInstance.ShowShipControl(mSelectShipList); * } * else * { * HudScreen.HudScreenInstance.HideShipControl(); * }*/ }