Пример #1
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            surf = Content.Load<SoundEffect>("surf").CreateInstance();
            surf.Volume = .06f;
            surf.IsLooped = true;

            mart = Content.Load<SoundEffect>("shop").CreateInstance();
            mart.Volume = .06f;
            mart.IsLooped = true;

            dead = Content.Load<SoundEffect>("dead").CreateInstance();
            dead.Volume = .4f;

            title = Content.Load<SoundEffect>("menu").CreateInstance();
            title.Volume = .8f;
            title.IsLooped = true;

            ching = Content.Load<SoundEffect>("ching").CreateInstance();
            ching.Volume = .5f;

            bool newRow = true;

            #region Loading in images

            #region Loads in boat image(s)
            System.IO.Stream fs = TitleContainer.OpenStream("Content/Boat_Left.png");
            play.Image = Texture2D.FromStream(this.GraphicsDevice, fs);
            fs.Close();
            #endregion

            #region Loads in the MapNode image(s)
            //Load in the maps 
            System.IO.Stream mapStream = TitleContainer.OpenStream("Content/ocean.jpg");
            mapImage = Texture2D.FromStream(GraphicsDevice, mapStream);
            mapStream.Close();
            #endregion

            #region Loads in the island images
            //Load in all island images to islandImages -- make more efficient later
            System.IO.Stream islandStream = TitleContainer.OpenStream("Content/Island1.png");
            Texture2D loadedImages = Texture2D.FromStream(GraphicsDevice, islandStream);
            islandImages.Add(loadedImages);
            islandStream.Close();
            islandStream = TitleContainer.OpenStream("Content/Island2.png");
            loadedImages = Texture2D.FromStream(GraphicsDevice, islandStream);
            islandImages.Add(loadedImages);
            islandStream.Close();
            islandStream = TitleContainer.OpenStream("Content/Island3.png");
            loadedImages = Texture2D.FromStream(GraphicsDevice, islandStream);
            islandImages.Add(loadedImages);
            islandStream.Close();
            islandStream = TitleContainer.OpenStream("Content/Island4.png");
            loadedImages = Texture2D.FromStream(GraphicsDevice, islandStream);
            islandImages.Add(loadedImages);
            islandStream.Close();
            islandStream = TitleContainer.OpenStream("Content/Island5.png");
            loadedImages = Texture2D.FromStream(GraphicsDevice, islandStream);
            islandImages.Add(loadedImages);
            islandStream.Close();
            islandStream = TitleContainer.OpenStream("Content/Island6.png");
            loadedImages = Texture2D.FromStream(GraphicsDevice, islandStream);
            islandImages.Add(loadedImages);
            islandStream.Close();
            #endregion

            #region Loads in the Menu images
            System.IO.Stream menuStream;
            menuStream = TitleContainer.OpenStream("Content/Keys.png");
            keyImage = Texture2D.FromStream(GraphicsDevice, menuStream);

            menuStream = TitleContainer.OpenStream("Content/IKey.png");
            iKeyImage = Texture2D.FromStream(GraphicsDevice, menuStream);

            menuStream = TitleContainer.OpenStream("Content/Title.png");
            titleText = Texture2D.FromStream(GraphicsDevice, menuStream);

            menuStream = TitleContainer.OpenStream("Content/TitleScreen.png");
            titleImage = Texture2D.FromStream(GraphicsDevice, menuStream);

            menuStream = TitleContainer.OpenStream("Content/GameOver.png");
            gameOverImage = Texture2D.FromStream(GraphicsDevice, menuStream);

            menuStream = TitleContainer.OpenStream("Content/Menu Screen.png");
            shopMenu = Texture2D.FromStream(GraphicsDevice, menuStream);

            menuStream = TitleContainer.OpenStream("Content/Fishing Screen.png");
            fishingScreenImage = Texture2D.FromStream(GraphicsDevice, menuStream);

            menuStream = TitleContainer.OpenStream("Content/Empty.png");
            blankImage = Texture2D.FromStream(GraphicsDevice, menuStream);

            menuStream.Close();
            #endregion

            #region Loads in the font
            //load font
            this.font = Content.Load<SpriteFont>("Arial14");
            #endregion

            #endregion
            int width = GraphicsDevice.Viewport.Width / 7; //1600 / 8
            int halfWidth = GraphicsDevice.Viewport.Width / 2;
            int height = GraphicsDevice.Viewport.Height / 10; //900 / 10
            int heightAdj = height / 2;
            #region Creates and adds all UI items for the shops

            menuStream = TitleContainer.OpenStream("Content/Button.png");
            buttonImage = Texture2D.FromStream(GraphicsDevice, menuStream);
            menuStream.Close();

            //text box
            TextBox exit = new TextBox("Back to Map", new Rectangle(20, GraphicsDevice.Viewport.Height - 100, 300, 80), buttonImage);
            ShopUImanager.AddUIObject(exit);

            //all buy buttons
            Button fuel = new Button("Purchase Fuel: 1 currency per unit", play, new Rectangle(width + halfWidth, height, 370, 25), buttonImage, ChangeValue.fuel);
            Button repair = new Button("Repair Ship: 1 currency per unit", play, new Rectangle(width + halfWidth, height + heightAdj, 370, 25), buttonImage, ChangeValue.health);
            Button crew = new Button("Hire Crew Members: 1 currency per unit", play, new Rectangle(width + halfWidth, height + heightAdj * 2, 370, 25), buttonImage, ChangeValue.crew);
            Button net = new Button("Net: " + Inventory.net.BuyPrice + " currency per unit", play, new Rectangle(width + halfWidth, height + heightAdj * 3, 370, 25), buttonImage, ChangeValue.inventoryBuy, Inventory.net);
            Button harpoon = new Button("Harpoon : " + Inventory.harpoon.BuyPrice + " currency per unit", play, new Rectangle(width + halfWidth, height + heightAdj * 4, 370, 25), buttonImage, ChangeValue.inventoryBuy, Inventory.harpoon);
            Button cage = new Button("Cage : " + Inventory.cage.BuyPrice + " currency per unit", play, new Rectangle(width + halfWidth, height + heightAdj * 5, 370, 25), buttonImage, ChangeValue.inventoryBuy, Inventory.cage);

            ShopUImanager.AddUIObject(fuel);
            ShopUImanager.AddUIObject(repair);
            ShopUImanager.AddUIObject(crew);
            ShopUImanager.AddUIObject(net);
            ShopUImanager.AddUIObject(harpoon);
            ShopUImanager.AddUIObject(cage);

            //all sell buttons
            Button sellCrew = new Button("Sell Crew Members: 1 currency per unit", play, new Rectangle(width, height, 370, 25), buttonImage, ChangeValue.crew);
            Button sellNet = new Button("Sell Net: " + Inventory.net.SellPrice + " currency per unit", play, new Rectangle(width, height + heightAdj, 370, 25), buttonImage, ChangeValue.inventorySell, Inventory.net);
            Button sellHarpoon = new Button("Sell Harpoon : " + Inventory.harpoon.SellPrice + " currency per unit", play, new Rectangle(width, height + heightAdj * 2, 370, 25), buttonImage, ChangeValue.inventorySell, Inventory.harpoon);
            Button sellCage = new Button("Sell Cage : " + Inventory.cage.SellPrice + " currency per unit", play, new Rectangle(width, height + heightAdj * 3, 370, 25), buttonImage, ChangeValue.inventorySell, Inventory.cage);
            Button tuna = new Button("Sell Tuna : " + Inventory.tuna.SellPrice + " currency per unit", play, new Rectangle(width, height + heightAdj * 4, 370, 25), buttonImage, ChangeValue.inventorySell, Inventory.tuna);
            Button herring = new Button("Sell Herring : " + Inventory.herring.SellPrice + " currency per unit", play, new Rectangle(width, height + heightAdj * 5, 370, 25), buttonImage, ChangeValue.inventorySell, Inventory.herring);
            Button swordfish = new Button("Sell Swordfish : " + Inventory.swordfish.SellPrice + " currency per unit", play, new Rectangle(width, height + heightAdj * 6, 370, 25), buttonImage, ChangeValue.inventorySell, Inventory.swordfish);
            Button whale = new Button("Sell Whale : " + Inventory.whale.SellPrice + " currency per unit", play, new Rectangle(width, height + heightAdj * 7, 370, 25), buttonImage, ChangeValue.inventorySell, Inventory.whale);
            Button lobster = new Button("Sell Lobster : " + Inventory.lobster.sellPrice + " currency per unit", play, new Rectangle(width, height + heightAdj * 8, 370, 25), buttonImage, ChangeValue.inventorySell, Inventory.lobster);

            ShopUImanager.AddUIObject(sellCrew);
            ShopUImanager.AddUIObject(sellNet);
            ShopUImanager.AddUIObject(sellHarpoon);
            ShopUImanager.AddUIObject(sellCage);
            ShopUImanager.AddUIObject(tuna);
            ShopUImanager.AddUIObject(herring);
            ShopUImanager.AddUIObject(swordfish);
            ShopUImanager.AddUIObject(whale);
            ShopUImanager.AddUIObject(lobster);
            #endregion



            #region creates all gamestate buttons
            //create and add all title menu buttons
            TextBox startButton = new TextBox("Start", new Rectangle(GraphicsDevice.Viewport.Width / 2 - 125, GraphicsDevice.Viewport.Height / 2 + 70, 300, 80), buttonImage);
            TextBox controlButton = new TextBox("Controls", new Rectangle(GraphicsDevice.Viewport.Width / 2 - 125, GraphicsDevice.Viewport.Height / 2 + 150, 300, 80), buttonImage);
            TitleUIManager.AddUIObject(startButton);
            TitleUIManager.AddUIObject(controlButton);

            //create and add control screen buttons
            TextBox titleButton = new TextBox("To Title", new Rectangle(GraphicsDevice.Viewport.Width / 2 - 125, GraphicsDevice.Viewport.Height / 2 + 70, 300, 80), buttonImage);
            ControlUIManager.AddUIObject(titleButton);

            //create and add game over buttons
            TextBox overButton = new TextBox("To Title", new Rectangle(GraphicsDevice.Viewport.Width / 2 - 125, GraphicsDevice.Viewport.Height / 2 + 70, 300, 80), buttonImage);
            OverUIManager.AddUIObject(overButton);

            //fishing buttons
            TextBox tunaInvent = new TextBox(new Rectangle((int)Math.Floor(width * 5.5), height * 2, 250, 50), buttonImage, Inventory.tuna);
            TextBox herringInvent = new TextBox(new Rectangle((int)Math.Floor(width * 5.5), (int)Math.Ceiling(height * 3.5), 250, 50), buttonImage, Inventory.herring);
            TextBox lobsterInvent = new TextBox(new Rectangle((int)Math.Floor(width * 5.5), height * 5, 250, 50), buttonImage, Inventory.lobster);
            TextBox swordInvent = new TextBox(new Rectangle((int)Math.Floor(width * 5.5), (int)Math.Floor(height * 6.5), 250, 50), buttonImage, Inventory.swordfish);
            TextBox whaleInvent = new TextBox(new Rectangle((int)Math.Floor(width * 5.5), height * 8, 250, 50), buttonImage, Inventory.whale);

            TextBox useNet = new TextBox(new Rectangle(width * 4, height * 2, 250, 50), buttonImage, Inventory.net);
            TextBox useCage = new TextBox(new Rectangle(width * 4, height * 5, 250, 50), buttonImage, Inventory.cage);
            TextBox useHarp = new TextBox(new Rectangle(width * 4, height * 8, 250, 50), buttonImage, Inventory.harpoon);

            FishingUI.AddUIObject(exit);
            FishingUI.AddUIObject(useNet);
            FishingUI.AddUIObject(useCage);
            FishingUI.AddUIObject(useHarp);
            FishingUI.AddUIObject(tunaInvent);
            FishingUI.AddUIObject(herringInvent);
            FishingUI.AddUIObject(swordInvent);
            FishingUI.AddUIObject(whaleInvent);
            FishingUI.AddUIObject(lobsterInvent);

            //create and add inventory buttons    

            TextBox backgroundButton = new TextBox("", new Rectangle(GraphicsDevice.Viewport.Width - 580, -20, 650, 50), buttonImage);
            TextBox orange = new TextBox(new Rectangle(width * 4, (int)Math.Floor(height * 3.5), 250, 50), buttonImage, Inventory.orange);
            TextBox barrel = new TextBox(new Rectangle(width * 4, (int)Math.Floor(height * 6.5), 250, 50), buttonImage, Inventory.oilbarrel);
            InventoryUIManager.AddUIObject(exit);
            InventoryUIManager.AddUIObject(tunaInvent);
            InventoryUIManager.AddUIObject(herringInvent);
            InventoryUIManager.AddUIObject(lobsterInvent);
            InventoryUIManager.AddUIObject(swordInvent);
            InventoryUIManager.AddUIObject(whaleInvent);
            InventoryUIManager.AddUIObject(useNet);
            InventoryUIManager.AddUIObject(useCage);
            InventoryUIManager.AddUIObject(useHarp);
            InventoryUIManager.AddUIObject(orange);
            InventoryUIManager.AddUIObject(barrel);
            InventoryUIManager.AddUIObject(backgroundButton);
            #endregion


            //make temp variables for holding the info for inventory items
            String tempName;
            String tempDescrip;
            int tempNum;
            int tempMax;
            int tempBuy;
            int tempSell;
            List<InventoryItem> shopItems = new List<InventoryItem>();  //list of objects. each island will have this as a random item in their shop

            //load info from the file
            Stream fileStream = File.OpenRead("Content/shopInventory.bin");
            BinaryReader input = new BinaryReader(fileStream);

            //make a loop here
            while (input.PeekChar() != -1)
            {
                tempName = input.ReadString();
                tempDescrip = input.ReadString();
                tempNum = input.ReadInt32();
                tempMax = input.ReadInt32();
                tempBuy = input.ReadInt32();
                tempSell = input.ReadInt32();
                shopItems.Add(new InventoryItem(tempName, tempDescrip, tempNum, tempMax, tempBuy, tempSell));
            }

            #region Adds MapNodes to the MapManager
            //Adding MapNodes to the MapManager
            Random rand = new Random();
            int rows = rand.Next(6, 8);
            int cols = rand.Next(7, 9);
            Stream fishStream = File.OpenRead("Content/FishingSpot.png");
            fishingImage = Texture2D.FromStream(GraphicsDevice, fishStream);
            fishStream.Close();
            fishStream = File.OpenRead("Content/Vortex.png");
            stormImage = Texture2D.FromStream(GraphicsDevice, fishStream);
            fishStream.Close();
            fishStream = File.OpenRead("Content/Pirate.png");
            pirateImage = Texture2D.FromStream(GraphicsDevice, fishStream);
            fishStream.Close();


            for (int i = 1; i < rows; i++)
            {
                for (int j = 1; j < cols; j++)
                {
                    if (j > 1)
                        newRow = false;
                    mapManager.AddNode(newRow, mapImage, islandImages, fishingImage, stormImage, pirateImage, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height, shopItems, play);
                }
                newRow = true;
            }
            #endregion


        }
Пример #2
0
        public override void Draw(SpriteBatch spriteBatch, SpriteFont font, GraphicsDevice device, Color color)
        {
            Rectangle messageBox = new Rectangle(device.Viewport.Width / 2 - 125, device.Viewport.Height / 2 + 70, 260, 80);
            TextBox box = new TextBox("", messageBox, this.texture);

            spriteBatch.Draw(texture, rectangle, color);
            spriteBatch.DrawString(font, label, new Vector2(rectangle.X + rectangle.Width / 2 - (label.Length * 4) - 9, rectangle.Y + rectangle.Height / 10), new Color(Color.Black, .35f));
            spriteBatch.DrawString(font, label, new Vector2(rectangle.X + rectangle.Width/2 - (label.Length*4) - 10, rectangle.Y + (rectangle.Height / 10) -1), new Color(26/255,15/255,0));
            

            string error = "Insufficient Currency";
            if (Pressed == true)
			{
                string purchase = "Purchase How Much?";
                
                if (changeValue == ChangeValue.fuel)
                {
                    CurrentAmount = (float)Math.Truncate(play.Fuel);
                }
                if (changeValue == ChangeValue.health)
                {
                    CurrentAmount = (float)Math.Truncate(play.Health);
                }
                if (changeValue == ChangeValue.inventoryBuy)
                {
                    if(play.Inventory.GetItemOfType(inventoryItem.Name) != null)
                        CurrentAmount = play.Inventory.GetItemOfType(inventoryItem.Name).StackNum;
                    else
                        CurrentAmount = 0;
                }
                if (changeValue == ChangeValue.inventorySell)
                {
                    if (play.Inventory.GetItemOfType(inventoryItem.Name) != null)
                        CurrentAmount = play.Inventory.GetItemOfType(inventoryItem.Name).StackNum;
                    else
                        CurrentAmount = 0;

                    purchase = "Sell How Much?";
                    error = "Not Enough in Inventory";
                }
                if (changeValue == ChangeValue.crew)
                {
                    CurrentAmount = play.Crew;
                    if(this.label.Contains("Sell"))
                        purchase = "Sell How Much?";
                }
                numError = false;

                box.Draw(spriteBatch, font, device, color);
                
                string have = "You Currently Have : " + CurrentAmount;

                spriteBatch.DrawString(font, purchase, new Vector2(messageBox.X + messageBox.Width / 2 - (purchase.Length * 4) - 14, (messageBox.Y + messageBox.Height / 8) + 1), new Color(Color.Black, .35f));
                spriteBatch.DrawString(font, purchase, new Vector2(messageBox.X + messageBox.Width / 2 - (purchase.Length * 4) - 15, messageBox.Y + messageBox.Height / 8), new Color(26/255,15/255,0));

                spriteBatch.DrawString(font, have, new Vector2(messageBox.X + messageBox.Width / 2 - (have.Length * 4) - 4, messageBox.Y + messageBox.Height / 8 + 41), new Color(Color.Black, .35f));
                spriteBatch.DrawString(font, have, new Vector2(messageBox.X + messageBox.Width / 2 - (have.Length * 4) - 5, messageBox.Y + messageBox.Height / 8 + 40), new Color(26 / 255, 15 / 255, 0));

				try
				{
                    int.Parse(userInput);
				}
				catch (Exception e)
				{ 
                    userInput = "0"; 
                }
                if (int.Parse(userInput) >= 100)
                {
                    userInput = "100";
                }
                userInput = int.Parse(userInput).ToString();

                spriteBatch.DrawString(font, userInput, new Vector2(messageBox.X + messageBox.Width / 2 - (userInput.Length * 4) - 4, messageBox.Y + messageBox.Height / 8 + 21), new Color(Color.Black, .35f));
                spriteBatch.DrawString(font, userInput, new Vector2(messageBox.X + messageBox.Width / 2 - (userInput.Length * 4) - 5, messageBox.Y + messageBox.Height / 8 + 20), new Color(26 / 255, 15 / 255, 0));
			}                
                
            if(numError == true)
                {
                    box.Draw(spriteBatch, font, device, color);
                    spriteBatch.DrawString(font, error, new Vector2(messageBox.X + messageBox.Width / 2 - (error.Length * 4), messageBox.Y + messageBox.Height / 8 + 20), Color.Black);
                    userInput = "0";
                    Pressed = false;
                }
        }