Ejemplo n.º 1
0
        /// <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);
        }