Exemplo n.º 1
0
        public States UpdateLocation(KeyboardState keyboard, List<Object> objects, States currentState)
        {
            idle = true;
            objList = objects;
            bool collided = false;
            Rectangle rectangle = rekt;


            foreach (Storm storm in objects.OfType<Storm>())
            {
                if (this.rekt.Intersects(storm.Rekt))
                {
                    storm.ResolveStorm(this, new Random());
                }
            }

            foreach (Pirate pirate in objects.OfType<Pirate>())
            {
                if (this.rekt.Intersects(pirate.Rekt))
                {
                    pirate.ResolvePirate(this);
                }
            }

            #region If the player has fuel
            if (fuel > 0)
            {
                //check if the keyboard will move the player
                #region Going left (Keys.A)
                if (keyboard.IsKeyDown(Keys.A))
                {
                    rekt.X -= speed;
                    direction = Directions.left;
                    idle = false;
                }
                #endregion
                #region Going right (Keys.D)
                if (keyboard.IsKeyDown(Keys.D))
                {
                    rekt.X += speed;
                    direction = Directions.right;
                    idle = false;
                }
                #endregion
                #region Going up (Keys.W)
                if (keyboard.IsKeyDown(Keys.W))
                {
                    rekt.Y -= speed;
                    idle = false;
                }
                #endregion
                #region Going down (Keys.S)
                if (keyboard.IsKeyDown(Keys.S))
                {
                    rekt.Y += speed;
                    idle = false;
                }
                #endregion
            #endregion
                if (!idle)
                {
                    changeFuel(-.025f);
                }
            }

            for (int i = 0; i < objects.Count; i++)
            {
                //check if picking up the player himself
                if (objects[i] != this)
                {
                    //check if intersection is occuring
                    if (this.rekt.Intersects(objects[i].Rekt))
                    {
                        //check if the object is an island
                        if (objects[i].Type == ObjectType.island)
                        {
                            currentState = States.docked;
                            collided = true;
                            dockedIsland = (objects[i] as Island);
                        }
                        else if (objects[i].Type == ObjectType.fishingSpot)
                        {
                            currentState = States.fishing;
                            collided = true;
                        }
                    }
                }
                if (collided)
                    rekt = rectangle;
            }
            return currentState;
        }
Exemplo n.º 2
0
        public Player(String name, Rectangle rect)
            : base(rect)
        {
            this.name = name;
            docked = true;
            fuel = 100f;
            health = 100f;
            currency = 50;
            crew = 5;
            inventory = new Inventory();
            this.image = null;
            rand = new Random();
            objList = new List<Object>();
            idle = false;
            direction = Directions.left;
            dockedIsland = null;

            //initialize enum
            type = ObjectType.player;

            //add starting items to inventory
            inventory.AddItem(Inventory.harpoon, 5);
            inventory.AddItem(Inventory.cage, 5);
            inventory.AddItem(Inventory.net, 5);
        }
Exemplo n.º 3
0
        //Creates the island (if there is one) on the map
        //places in a random location with a random size
        public void makeIslands(Random rand, Player play)
        {
            List<int> removedindexes = new List<int>();
            
            Island tempIsland;
            Texture2D islImage;

            for (int i = 0; i < islandNum; i++)
            {
                //Makes sure no islands have the same image on screen
                int num0 = rand.Next(0, islandImages.Count);
                while(removedindexes.Contains(num0))
                {
                    num0 = rand.Next(0, islandImages.Count);
                }
                islImage = islandImages[num0]; 
                removedindexes.Add(num0);

                //Creates the parameters for the new islands
                int num1 = rand.Next(0, screenWidth - islImage.Width - 50);
                int num2 = rand.Next(0, screenHeight - islImage.Height - 50);
                int num3 = rand.Next(50, 150);
                int num4 = rand.Next(50, 150);

                //Creates the island / adds them to the island and object lists
                tempIsland = new Island(num1, num2, num3, num3, islImage);

                islandList.Add(tempIsland);
                objects.Add(tempIsland);
            }
            
            //This crazy bastard makes sure islands don't overlap
            for(int j = 0; j < islandList.Count; j++)
            {
                for(int k = 0; k < islandList.Count; k++)
                {
                    rand = new Random();
                    while(j!=k && (islandList[j].Rekt.Intersects(islandList[k].Rekt) || islandList[k].Rekt.Intersects(play.Rekt)))
                    {
                        islandList[k].Rekt = new Rectangle(rand.Next(0, screenWidth - islandList[k].Rekt.Width),
                                                        rand.Next(0, screenHeight - islandList[k].Rekt.Height),
                                                        rand.Next(50, islandList[k].Rekt.Width),
                                                        rand.Next(50, islandList[k].Rekt.Height));
                    }
                }
            }
                   
        }