/// <summary> /// This is called when the game should draw itself. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Draw(GameTime gameTime) { // trackers for statically drawn sprites as we move through draw order bool showCraftingMenu = false; bool showStorageMenu = false; ICraftingObject craftObj = null; Storage invStorage = null; Ship playerShip = gameState.player.playerOnShip; List <InventoryItem> invItemsPlayer = gameState.player.inventory; List <InventoryItem> invItemsShip = (gameState.player.playerOnShip == null) ? null : gameState.player.playerOnShip.actionInventory; if (gameState.player.onShip) { invItemsShip = gameState.player.playerOnShip.actionInventory; } // game menu before everything if (startingMenu.showMenu) { startingMenu.DrawInventory(spriteBatchStatic); return; } // draw the interior view if in interior if (gameState.player.playerInInterior != null) { gameState.player.playerInInterior.interiorObjects.Add(gameState.player); GraphicsDevice.SetRenderTarget(lightsTarget); GraphicsDevice.Clear(Color.Black); DrawUtility.DrawSpotLighting(spriteBatchView, this.camera, lightsTarget, gameState.player.playerInInterior.interiorObjects.ToList()); gameState.player.playerInInterior.Draw(spriteBatchView, this.camera, interiorScene); // lighting shader - for ambient day/night light and lanterns GraphicsDevice.SetRenderTarget(null); GraphicsDevice.Clear(Color.White); dayLight.Draw(spriteBatchStatic, interiorScene, lightsTarget); showCraftingMenu = gameState.player.playerInInterior.showCraftingMenu; showStorageMenu = gameState.player.playerInInterior.showStorageMenu; craftObj = gameState.player.playerInInterior.craftObj; invStorage = gameState.player.playerInInterior.invStorage; } // not in interior so draw the game scene else { // setup lightTarget for spot lights GraphicsDevice.SetRenderTarget(lightsTarget); GraphicsDevice.Clear(Color.Black); DrawUtility.DrawSpotLighting(spriteBatchView, this.camera, lightsTarget, DrawOrder); // draw map map.DrawMap(spriteBatchView, spriteBatchStatic, worldScene); // draw treasure locations if any spriteBatchView.Begin(this.camera); foreach (var map in BoundingBoxLocations.treasureLocationsList) { spriteBatchView.Draw(treasureXMark, map.digTileLoc, Color.White); } spriteBatchView.End(); // draw shadows and wakes foreach (var sprite in DrawOrder) { if (sprite is IShadowCaster) { sprite.DrawShadow(spriteBatchView, camera, WeatherState.sunAngleX, WeatherState.shadowTransparency); if (sprite.GetType().BaseType == typeof(Gusto.Models.Animated.Ship)) { Ship ship = (Ship)sprite; ship.shipSail.DrawShadow(spriteBatchView, this.camera, WeatherState.sunAngleX, WeatherState.shadowTransparency); } } if (sprite is IWakes) { IWakes waker = (IWakes)sprite; WakeParticleEngine wpe = waker.GetWakeEngine(); wpe.Draw(spriteBatchView, camera); } } List <Sprite> fliers = new List <Sprite>(); // draw any flyers on top of everything // sort sprites by y cord asc and draw DrawOrder.Sort((a, b) => a.GetBoundingBox().Bottom.CompareTo(b.GetBoundingBox().Bottom)); int i = 0; foreach (var sprite in DrawOrder) { if (sprite is IVulnerable) { IVulnerable v = (IVulnerable)sprite; v.DrawHealthBar(spriteBatchView, camera); } if (sprite is IInventoryItem) { InventoryItem item = (InventoryItem)sprite; if (!item.inInventory) { item.DrawPickUp(spriteBatchView, camera); } } if (sprite is ICraftingObject) { ICraftingObject tcraftObj = (ICraftingObject)sprite; tcraftObj.DrawCanCraft(spriteBatchView, camera); if (tcraftObj.GetShowMenu()) { showCraftingMenu = true; craftObj = tcraftObj; } } if (sprite is IPlaceable) { IPlaceable placeObj = (IPlaceable)sprite; placeObj.DrawCanPickUp(spriteBatchView, camera); } if (sprite is IStructure) { IStructure structure = (IStructure)sprite; structure.DrawNearInterior(spriteBatchView, camera); } if (sprite is IStorage) { Storage storage = (Storage)sprite; storage.DrawOpenStorage(spriteBatchView, camera); if (storage.storageOpen) { showStorageMenu = true; invStorage = storage; } } if (sprite.GetType().BaseType == typeof(Gusto.Models.Animated.Ship)) { Ship ship = (Ship)sprite; if (ship.sinking) { ship.DrawSinking(spriteBatchView, this.camera); ship.shipSail.DrawSinking(spriteBatchView, this.camera); } else { // Draw a ship before its sail and mount ship.Draw(spriteBatchView, this.camera); if (ship.mountedOnShip != null) { foreach (var shot in ship.mountedOnShip.Shots) { shot.Draw(spriteBatchView, this.camera); } if (ship.mountedOnShip.aiming) { ship.mountedOnShip.Draw(spriteBatchView, this.camera); if (ship.teamType == TeamType.Player) { ship.mountedOnShip.DrawAimLine(spriteBatchView, this.camera); } } } ship.shipSail.Draw(spriteBatchView, this.camera); } continue; } else if (sprite.GetType() == typeof(Gusto.AnimatedSprite.PiratePlayer)) { DrawUtility.DrawPlayer(spriteBatchView, this.camera, gameState.player); continue; } else if (sprite.GetType().BaseType == typeof(Gusto.Models.Animated.Npc)) { Npc npc = (Npc)sprite; // flying drawn after everything else if (npc.flying) { fliers.Add(npc); continue; } if (npc.swimming && !npc.onShip) { npc.DrawSwimming(spriteBatchView, this.camera); } else if (!npc.onShip) { npc.Draw(spriteBatchView, this.camera); } if (npc.dying) { npc.DrawDying(spriteBatchView, this.camera); } continue; } else if (sprite.GetType() == typeof(Gusto.AnimatedSprite.BaseTower)) { Tower tower = (Tower)sprite; sprite.Draw(spriteBatchView, this.camera); // draw any shots this tower has in motion foreach (var shot in tower.Shots) { shot.Draw(spriteBatchView, this.camera); } continue; } if (sprite.GetType() == typeof(Gusto.Models.Menus.Inventory) || sprite.GetType() == typeof(Gusto.Models.Menus.CraftingMenu)) { continue; // we handle this after everthing else } sprite.Draw(spriteBatchView, this.camera); } // draw fliers foreach (var flier in fliers) { flier.Draw(spriteBatchView, this.camera); } // draw weather weather.DrawWeather(spriteBatchStatic); // lighting shader - for ambient day/night light and lanterns GraphicsDevice.SetRenderTarget(null); GraphicsDevice.Clear(Color.White); dayLight.Draw(spriteBatchStatic, worldScene, lightsTarget); } // lightning is drawn after ambient light if (WeatherState.lightning) { weather.DrawLightning(spriteBatchStatic); } // draw static and menu sprites windArrows.Draw(spriteBatchStatic, null); if (gameState.player.onShip) { playerShip.DrawAnchorMeter(spriteBatchStatic, new Vector2(1660, 30), anchorIcon); playerShip.DrawRepairHammer(spriteBatchStatic, new Vector2(1600, 30), repairIcon); if (playerShip.msBoarding > 0) { playerShip.DrawBeingBoarded(spriteBatchStatic, new Vector2(1540, 30), boardingIcon); } if (gameState.player.playerInInterior != null) { invItemsShip = null; } } else { invItemsShip = null; } if (gameState.player.showInventory) { inventoryMenu.Draw(spriteBatchStatic, null); inventoryMenu.DrawInventory(spriteBatchStatic, invItemsPlayer, invItemsShip, null); } else if (showCraftingMenu) { craftingMenu.Draw(spriteBatchStatic, null); craftingMenu.DrawInventory(spriteBatchStatic, invItemsPlayer, craftObj); } else if (showStorageMenu) { inventoryMenu.Draw(spriteBatchStatic, null); inventoryMenu.DrawInventory(spriteBatchStatic, invItemsPlayer, invItemsShip, invStorage); } // fps var deltaTime = (float)gameTime.ElapsedGameTime.TotalSeconds; _frameCounter.Update(deltaTime); var fps = string.Format("FPS: {0}", _frameCounter.AverageFramesPerSecond); spriteBatchStatic.Begin(); spriteBatchStatic.DrawString(font, fps, new Vector2(10, 10), Color.Green); spriteBatchStatic.End(); base.Draw(gameTime); }
public void Draw(SpriteBatch sb, Camera cam, RenderTarget2D interiorScene) { // Draw the tileset Vector2 minCorner = new Vector2(cam.Position.X - (GameOptions.PrefferedBackBufferWidth / 2), cam.Position.Y - (GameOptions.PrefferedBackBufferHeight / 2)); Vector2 maxCorner = new Vector2(cam.Position.X + (GameOptions.PrefferedBackBufferWidth / 2), cam.Position.Y + (GameOptions.PrefferedBackBufferHeight / 2)); // setup drawing for interior on backbuffer _graphics.SetRenderTarget(interiorScene); _graphics.Clear(Color.Black); startDrawPoint = new Vector2(interiorForObj.location.X - (width / 2), interiorForObj.location.Y - (height / 2)); Vector2 drawPoint = startDrawPoint; interiorTiles.Clear(); for (int i = 0; i < rows; i++) { for (int j = 0; j < cols; j++) { TilePiece tile = interiorMap[((cols) * i) + j]; if (tile == null) { drawPoint.X += GameOptions.tileWidth * 2; continue; } tile.location = drawPoint; var loc = tile.location; tile.location += speed; tile.inInteriorId = interiorId; // TODO: need to move setting of InteriorId to constructor, but this screws up serialization interiorTiles.Add(tile); if (tile.groundObjects != null) { foreach (var groundObject in tile.groundObjects) { groundObject.location = loc; } } // draw if in viewporit if ((loc.X >= minCorner.X && loc.X <= maxCorner.X) && (loc.Y >= minCorner.Y && loc.Y <= maxCorner.Y)) { tile.Draw(sb, cam); } drawPoint.X += GameOptions.tileWidth * 2; } drawPoint.Y += GameOptions.tileHeight * 2; drawPoint.X = startDrawPoint.X; } // reset these menu trackers showCraftingMenu = false; showStorageMenu = false; craftObj = null; invStorage = null; List <Sprite> drawOrder = interiorObjects.ToList(); drawOrder.Sort((a, b) => a.GetBoundingBox().Bottom.CompareTo(b.GetBoundingBox().Bottom)); // Draw any interior objs foreach (var obj in drawOrder) { // npcs always have random loc set when entering interior, other objects are randomly set initially, unless coming from a save if ((!tilesSet && !(obj is IPlayer) && !interiorWasLoaded) || (obj is INPC && !showingInterior)) { obj.location = RandomInteriorTile().location; } // special draw for player if (obj is IPlayer) { DrawUtility.DrawPlayer(sb, cam, (PiratePlayer)obj); continue; } obj.Draw(sb, cam); if (obj is IVulnerable) { IVulnerable v = (IVulnerable)obj; v.DrawHealthBar(sb, cam); } if (obj is IInventoryItem) { InventoryItem item = (InventoryItem)obj; if (!item.inInventory) { item.DrawPickUp(sb, cam); } } if (obj is IPlaceable) { IPlaceable placeObj = (IPlaceable)obj; placeObj.DrawCanPickUp(sb, cam); } if (obj is ICraftingObject) { ICraftingObject tcraftObj = (ICraftingObject)obj; tcraftObj.DrawCanCraft(sb, cam); if (tcraftObj.GetShowMenu()) { showCraftingMenu = true; craftObj = tcraftObj; } } if (obj is IStorage) { Storage storage = (Storage)obj; storage.DrawOpenStorage(sb, cam); if (storage.storageOpen) { showStorageMenu = true; invStorage = storage; } } } tilesSet = true; showingInterior = true; }