Exemplo n.º 1
0
 public void RemoveFishingSpot(FishingSpot fish)
 {
     fishList.Remove(fish);
     objects.Remove(fish);
 }
Exemplo n.º 2
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
                Exit();

            #region Get all states
            KeyboardState key = Keyboard.GetState();
            mouseState = Mouse.GetState();
            mousePosition = new Point(mouseState.X, mouseState.Y);
            #endregion

            #region Loading in all things onscreen into objList
            objectList.Clear();
            foreach (Island isl in mapManager.Islands(currentRow, currentCol))
            {
                objectList.Add(isl as Island);
            }
            foreach (FishingSpot fsp in mapManager.FishingSpots(currentRow, currentCol))
            {
                objectList.Add(fsp as FishingSpot);
            }
            foreach (Storm vort in mapManager.Vortexes(currentRow, currentCol))
            {
                if (vort.Available)
                    objectList.Add(vort as Storm);
            }
            foreach (Pirate pete in mapManager.Pirates(currentRow, currentCol))
            {
                if (pete.Available)
                    objectList.Add(pete as Pirate);
            }
            #endregion

            #region TitleMenu GameState
            //check the gamestate
            if (gameState == States.titleMenu)
            {
                title.Play();
                //check if player is moving to the game
                IsMouseVisible = true;
                TitleUIManager.UpdateManager(mouseState, key, gameTime, play, ching);
                List<UI_Item> list = TitleUIManager.List;
                if (list[0].Pressed)
                {
                    gameState = States.map;
                    title.Stop();
                    list[0].Pressed = false;
                }

                if (list[1].Pressed)
                {
                    gameState = States.controls;
                    list[1].Pressed = false;
                }
                /*
                if (key.IsKeyDown(Keys.Enter))
                {
                    //move to the map
                    gameState = States.map;
                }
                */
            }
            #endregion
            #region GameOver GameState
            else if (gameState == States.gameOver)
            {
                surf.Stop();
                //check if player is restarting
                IsMouseVisible = true;
                OverUIManager.UpdateManager(mouseState, key, gameTime, play, ching);
                List<UI_Item> list = OverUIManager.List;
                if (list[0].Pressed)
                {
                    gameState = States.titleMenu;
                    list[0].Pressed = false;
                    ResetGame();
                }
                /*
                if (key.IsKeyDown(Keys.LeftControl) || key.IsKeyDown(Keys.RightControl))
                {
                    ResetGame();
                }
                */
            }
            #endregion
            #region Map GameState
            #region Update player location
            else if (gameState == States.map)
            {
                gameState = play.UpdateLocation(key, objectList, gameState);
                int tempRow = currentRow;
                int tempCol = currentCol;
                //check if player is moving beyond map
                if (play.Rekt.X <= -1)
                {
                    //going to assume we will loop the map for the moment (ie if i go to the farthest right ill pop up back on the farthest left

                    play.XPos = this.GraphicsDevice.Viewport.Width;

                    //check if the player is at a grid edge
                    if (currentCol == 0)
                    {
                        //move player to other side of map
                        currentCol = mapManager.Columns() - 1;
                    }
                    else
                    {
                        //move player to next grid area
                        currentCol -= 1;
                    }
                }
                else if (play.Rekt.Y <= -1)
                {
                    play.YPos = this.GraphicsDevice.Viewport.Height;

                    //check if the player is at a grid edge
                    if (currentRow == 0)
                    {
                        //move player to other side of map
                        currentRow = mapManager.Rows() - 1;
                    }
                    else
                    {
                        //move player to next grid area
                        currentRow -= 1;
                    }
                }
                else if (play.Rekt.X >= GraphicsDevice.Viewport.Width + 1)
                {
                    play.XPos = 0;

                    //check if the player is at a grid edge
                    if (currentCol == mapManager.Columns() - 1)    //if the current column is the last column
                    {
                        //move player to other side of map
                        currentCol = 0;
                    }
                    else
                    {
                        //move player to next grid area
                        currentCol += 1;
                    }
                }
                else if (play.Rekt.Y >= GraphicsDevice.Viewport.Height + 1)
                {
                    play.YPos = 0;

                    //check if the player is at a grid edge
                    if (currentRow == mapManager.Rows() - 1)
                    {
                        //move player to other side of map
                        currentRow = 0;      //double check if 0 refers to column or row
                    }
                    else
                    {
                        //move player to next grid area
                        currentRow += 1;
                    }
                }
                if (tempRow != currentRow || tempCol != currentCol)
                {
                    foreach (Storm vort in mapManager.Vortexes(tempRow, tempCol))
                    {
                        if (!vort.Available)
                        {
                            vort.Available = true;
                        }
                    }
                    foreach (Pirate pete in mapManager.Pirates(tempRow, tempCol))
                    {
                        if (!pete.Available)
                        {
                            pete.Available = true;
                        }
                    }
                }

            #endregion
                #region Move vortexes and pirates
                foreach (Storm vort in mapManager.Vortexes(currentRow, currentCol))
                {
                    vort.Move(GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height, play);
                }
                foreach (Pirate pete in mapManager.Pirates(currentRow, currentCol))
                {
                    pete.Move(play, new Random());
                }

                #endregion

                #region Check if player is dead
                if (play.Fuel <= 0)
                {
                    //change to game over screen
                    gameState = States.gameOver;
                    dead.Play();

                    //update method of death
                    Death.instance.die = Doom.noFuel;
                }
                else if (play.Health <= 0)
                {
                    //change to game over screen
                    gameState = States.gameOver;
                    dead.Play();

                    //update method of death
                    Death.instance.die = Doom.noHP;
                }
                else if (play.Crew <= 0)
                {
                    //change to game over screen
                    gameState = States.gameOver;
                    dead.Play();

                    //update method of death
                    Death.instance.die = Doom.noCrew;
                }
                #endregion
                // Enters inventory screen
                if (key.IsKeyDown(Keys.I))
                {
                    gameState = States.invent;
                }

                if (surf.State != SoundState.Playing)
                {
                    surf.Play();
                }
            }
            #endregion
            #region Docked GameState
            else if (gameState == States.docked)
            {
                surf.Stop();
                mart.Play();
                bool added = false;
                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;

                if (play.DockedIsland.inventory.ContainsKey("Orange"))
                {
                    Button orange = new Button("Orange : " + Inventory.orange.BuyPrice + " currency per unit", play, new Rectangle(width + halfWidth, height + heightAdj * 6, 370, 25), ShopUImanager.List[0].Texture, ChangeValue.inventoryBuy, Inventory.orange);
                    ShopUImanager.AddUIObject(orange);
                    added = true;
                }
                else if (play.DockedIsland.inventory.ContainsKey("Oil Barrel"))
                {
                    Button oil = new Button("Oil Barrel : " + Inventory.oilbarrel.BuyPrice + " currency per unit", play, new Rectangle(width + halfWidth, height + heightAdj * 6, 370, 25), ShopUImanager.List[0].Texture, ChangeValue.inventoryBuy, Inventory.oilbarrel);
                    ShopUImanager.AddUIObject(oil);
                    added = true;
                }

                ShopUImanager.UpdateManager(mouseState, key, gameTime, play, ching);
                IsMouseVisible = true;
                List<UI_Item> list = ShopUImanager.List;
                if (list[0].Pressed)
                {
                    mart.Stop();
                    gameState = States.map;
                    list[0].Pressed = false;
                    if (added)
                        ShopUImanager.List.RemoveAt(ShopUImanager.List.Count - 1);
                }

                if (key.IsKeyDown(Keys.Tab))
                {
                    mart.Stop();
                    gameState = States.map;
                    if (added)
                        ShopUImanager.List.RemoveAt(ShopUImanager.List.Count - 1);
                }
            }
            #endregion
            #region Fishing Gamestate
            else if (gameState == States.fishing)
            {
                IsMouseVisible = true;
                FishingUI.UpdateManager(mouseState, key, gameTime, play, ching);
                List<UI_Item> list = FishingUI.List;
                Random rando = new Random();
                FishingSpot fish = new FishingSpot(new Rectangle(1, 1, 1, 1), fishingImage);
                if (list[0].Pressed)
                {
                    gameState = States.map;
                    list[0].Pressed = false;
                }

                if (list[1].Pressed)
                {
                    fish.ResolveFishing(play, rando, Inventory.net, mouseState);
                    list[1].Pressed = false;
                }

                if (list[2].Pressed)
                {
                    fish.ResolveFishing(play, rando, Inventory.cage, mouseState);
                    list[2].Pressed = false;
                }

                if (list[3].Pressed)
                {
                    fish.ResolveFishing(play, rando, Inventory.harpoon, mouseState);
                    list[3].Pressed = false;
                }

                if (key.IsKeyDown(Keys.Tab))
                {
                    gameState = States.map;
                }
            }
            #endregion
            #region Controls Gamestate
            else if (gameState == States.controls)
            {
                //check if player is restarting
                IsMouseVisible = true;
                ControlUIManager.UpdateManager(mouseState, key, gameTime, play, ching);
                List<UI_Item> list = ControlUIManager.List;
                if (list[0].Pressed)
                {
                    gameState = States.titleMenu;
                    list[0].Pressed = false;
                }
            }
            #endregion
            #region Inventory Gamestate
            else if (gameState == States.invent)
            {
                IsMouseVisible = true;
                InventoryUIManager.UpdateManager(mouseState, key, gameTime, play, ching);
                List<UI_Item> list = InventoryUIManager.List;
                if (list[0].Pressed)
                {
                    gameState = States.map;
                    list[0].Pressed = false;
                }

                if (key.IsKeyDown(Keys.Tab))
                {
                    gameState = States.map;
                }
            }
            #endregion
            base.Update(gameTime);
        }
Exemplo n.º 3
0
        public void makeFishingSpots(Random rand)
        {
            int dimensions = rand.Next(25, 75);
            FishingSpot temp;

            for (int i = 0; i < fishNum; i++)
            {
                int num1 = rand.Next(0, screenWidth - fishImage.Width * 2);
                int num2 = rand.Next(0, screenHeight - fishImage.Height * 2);

                temp = new FishingSpot(new Rectangle(num1, num2, dimensions, dimensions), fishImage);

                fishList.Add(temp);
                
            }
            //---------------------------------------------------------------------------------------------------------------------------------->>CHECK THIS CODE LATER<<
            //This crazy bastard makes sure other objects onscreen don't overlap
            for (int j = 0; j < fishList.Count; j++)
            {
                for (int k = 0; k < objects.Count; k++)
                {
                    while (fishList[j].Rekt.Intersects(objects[k].Rekt))
                    {
                        fishList[j].Rekt = new Rectangle(rand.Next(0, screenWidth - fishList[j].Rekt.Width),
                                                        rand.Next(0, screenHeight - fishList[j].Rekt.Height),
                                                        dimensions,
                                                        dimensions);
                    }
                }
                objects.Add(fishList[j]);
            }
        }