/// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            player = new Player();
            // Use Viewport to get width and height of the screen
            viewport = GraphicsDevice.Viewport;
            player.Initialize(viewport.Width / 2, viewport.Height / 2, (float)-Math.PI / 2);

            Rectangle infoboxDimension = new Rectangle(viewport.Width - INFOBOXWIDTH, 0, INFOBOXWIDTH, viewport.Height);

            infobox = new InfoBox(infoboxDimension, player);
            input   = new InputHandler();

            // Populate world

            // Add agents
            Program.agents.Add(new Player());
            Program.agents.Add(new Player());
            Program.agents.Add(new Player());
            Program.agents[0].Initialize(50, 150, 0);
            Program.agents[1].Initialize(100, 20, 90);
            Program.agents[2].Initialize(200, 300, 90);

            // Add walls
            Program.walls.Add(new BoundingBox(new Vector3(20, 70, 0), new Vector3(260, 100, 0)));
            Program.walls.Add(new BoundingBox(new Vector3(470, 10, 0), new Vector3(510, 410, 0)));
            Program.walls.Add(new BoundingBox(new Vector3(40, 340, 0), new Vector3(390, 370, 0)));

            navMap = new PathGraph(viewport.Width - 240, viewport.Height);



            base.Initialize();
        }
Beispiel #2
0
        public void respondToInput(InputHandler input, PathGraph navMap)
        {
            // If the user clicked any of the toggle buttons, toggle their associated value
            for (int i = 0; i < toggleLinks.Length; i++)
            {
                if (input.mouseClicked(toggleLinks[i]))
                {
                    toggles[i] = !toggles[i];
                }
            }

            for (int i = 0; i < menuButtons.Count; i++)
            {
                if ((menu == (int)sideMenu.main || i == 0) && input.mouseClicked(menuButtons[i].bounds))
                {
                    resetState();
                    menu = i;
                }
            }

            //if (menu == (int)sideMenu.createMap && input.isMouseClicked())
            //{
            //    for (int i = 0; i < createMap.Count; i++ )
            //    {
            //        if (input.mouseClicked(createMap[i].bounds))
            //        {
            //            mapMode = i;
            //        }
            //    }
            //}

            // Add an enemy to the map with the coordinates of the mouse click
            if (addMode && input.mouseClicked(new Rectangle(0, 0, bounds.X, bounds.Height)))
            {
                var random    = new Random();
                int randomNum = random.Next(0, (int)(2 * Math.PI));
                Program.agents.Add(new Player());
                Program.agents[Program.agents.Count - 1].Initialize(input.mouseStateCurrent.X, input.mouseStateCurrent.Y, randomNum);
                addMode = false;
            }

            // Increment/Decrement the range if the user clicked the plus or minus button
            if (input.mousePressed(incRange))
            {
                player.range++;
            }
            if (input.mousePressed(decRange))
            {
                player.range--;
            }
            // If the user clicked the "add agent" button, set the flag
            if (input.mouseClicked(addAgent))
            {
                addMode = true;
            }
        }
        public List <Node> setPath(Node target, PathGraph navMap)
        {
            Node        closest      = getClosestNode(getAdjacentNodes(navMap.nodes));
            List <Node> tempShortest = navMap.getShortestPath(closest, target);

            shortestPath = new Stack <Node>();
            foreach (Node n in tempShortest)
            {
                shortestPath.Push(n);
            }
            return(tempShortest);
        }
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            state   = State.start;
            counter = 500;

            rnd = new Random();
            // Use Viewport to get width and height of the screen
            viewport = GraphicsDevice.Viewport;

            input         = new InputHandler();
            chests        = new List <Chest>();
            possibleItems = new List <Item>();
            possibleItems.Add(new Item(0, 0, 25, 25, 30, "strawberry"));
            possibleItems.Add(new Item(0, 0, 25, 25, 30, "cherry"));
            possibleItems.Add(new Item(0, 0, 25, 25, 30, "pineapple"));

            cam = new Camera(viewport, new Vector2(500, 500), new Rectangle(0, 0, 1000, 1000));

            player = new Player(1000, 1000, 20, 40, (float)-Math.PI / 2);

            for (int i = 0; i < 3; i++)
            {
                agents.Add(new Agent(0, 0, 23, 28, 0));
            }

            inventory = new Inventory(viewport);



            #region grass
            grass = new List <BoundingBox>();
            grass.Add(new BoundingBox(new Vector3(39, 284, 0), new Vector3(208, 360, 0)));
            grass.Add(new BoundingBox(new Vector3(16, 589, 0), new Vector3(107, 807, 0)));
            grass.Add(new BoundingBox(new Vector3(154, 487, 0), new Vector3(452, 567, 0)));
            grass.Add(new BoundingBox(new Vector3(303, 909, 0), new Vector3(544, 979, 0)));
            grass.Add(new BoundingBox(new Vector3(607, 704, 0), new Vector3(799, 781, 0)));
            grass.Add(new BoundingBox(new Vector3(860, 834, 0), new Vector3(954, 913, 0)));
            #endregion


            #region tree vectors
            trees = new List <Vector2>();
            trees.Add(new Vector2(480, 140));
            trees.Add(new Vector2(540, 140));
            trees.Add(new Vector2(600, 140));

            trees.Add(new Vector2(450, 165));
            trees.Add(new Vector2(510, 165));
            trees.Add(new Vector2(570, 165));
            trees.Add(new Vector2(630, 165));

            trees.Add(new Vector2(480, 190));
            trees.Add(new Vector2(540, 190));
            trees.Add(new Vector2(600, 190));

            trees.Add(new Vector2(600, 490));
            trees.Add(new Vector2(660, 490));
            trees.Add(new Vector2(600, 410));
            trees.Add(new Vector2(660, 410));

            trees.Add(new Vector2(690, 435));
            trees.Add(new Vector2(690, 485));
            trees.Add(new Vector2(690, 515));

            trees.Add(new Vector2(570, 435));
            trees.Add(new Vector2(570, 485));
            trees.Add(new Vector2(570, 515));

            trees.Add(new Vector2(630, 435));
            trees.Add(new Vector2(630, 485));
            trees.Add(new Vector2(630, 515));

            trees.Add(new Vector2(200, 205));

            trees.Add(new Vector2(300, 570));
            trees.Add(new Vector2(360, 570));

            trees.Add(new Vector2(620, 800));
            trees.Add(new Vector2(730, 800));
            trees.Add(new Vector2(675, 820));
            #endregion

            // Populate world

            // Add bounds
            #region Bounds
            walls.Add(new BoundingBox(new Vector3(0, 43, 0), new Vector3(303, 215, 0)));
            walls.Add(new BoundingBox(new Vector3(0, 0, 0), new Vector3(173, 43, 0)));
            walls.Add(new BoundingBox(new Vector3(833, 0, 0), new Vector3(1000, 114, 0)));
            walls.Add(new BoundingBox(new Vector3(736, 0, 0), new Vector3(837, 50, 0)));
            walls.Add(new BoundingBox(new Vector3(609, 0, 0), new Vector3(741, 27, 0)));
            walls.Add(new BoundingBox(new Vector3(857, 125, 0), new Vector3(967, 245, 0)));
            walls.Add(new BoundingBox(new Vector3(889, 218, 0), new Vector3(919, 349, 0)));
            walls.Add(new BoundingBox(new Vector3(889, 453, 0), new Vector3(919, 520, 0)));
            walls.Add(new BoundingBox(new Vector3(831, 512, 0), new Vector3(1000, 596, 0)));
            walls.Add(new BoundingBox(new Vector3(117, 829, 0), new Vector3(256, 945, 0)));
            // Trees
            walls.Add(new BoundingBox(new Vector3(512, 307, 0), new Vector3(657, 320, 0)));
            walls.Add(new BoundingBox(new Vector3(482, 279, 0), new Vector3(685, 297, 0)));
            walls.Add(new BoundingBox(new Vector3(600, 514, 0), new Vector3(745, 649, 0)));
            walls.Add(new BoundingBox(new Vector3(419, 667, 0), new Vector3(482, 708, 0)));
            walls.Add(new BoundingBox(new Vector3(232, 324, 0), new Vector3(258, 338, 0)));
            walls.Add(new BoundingBox(new Vector3(332, 689, 0), new Vector3(358, 703, 0)));
            walls.Add(new BoundingBox(new Vector3(392, 689, 0), new Vector3(418, 703, 0)));
            walls.Add(new BoundingBox(new Vector3(652, 919, 0), new Vector3(678, 933, 0)));
            walls.Add(new BoundingBox(new Vector3(762, 919, 0), new Vector3(788, 933, 0)));
            walls.Add(new BoundingBox(new Vector3(707, 939, 0), new Vector3(733, 953, 953)));

            walls.Add(new BoundingBox(new Vector3(933, 260, 0), new Vector3(965, 284, 0)));
            walls.Add(new BoundingBox(new Vector3(30, 883, 0), new Vector3(62, 907, 0)));
            walls.Add(new BoundingBox(new Vector3(310, 15, 0), new Vector3(342, 39, 0)));

            chests.Add(new Chest(933, 260, "Necklace of Vitality"));
            chests.Add(new Chest(30, 883, "Hat of Wisdom"));
            chests.Add(new Chest(310, 15, "Scroll of Truth"));
            #endregion



            navMap = new PathGraph(1000, 1000);

            setVariables();



            base.Initialize();
        }