Exemplo n.º 1
0
        protected override void Update(GameTime gameTime)
        {
            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
            {
                this.Exit();
            }

            //player movement: read keyboard
            KeyboardState keyState   = Keyboard.GetState();
            Coord2        currentPos = new Coord2();

            currentPos = player.GridPosition;
            if (keyState.IsKeyDown(Keys.Up))
            {
                currentPos.Y -= 1;
                player.SetNextLocation(currentPos, level);
                level.dijkstra.Build(level, bot, player);
            }
            else if (keyState.IsKeyDown(Keys.Down))
            {
                currentPos.Y += 1;
                player.SetNextLocation(currentPos, level);
                level.dijkstra.Build(level, bot, player);
            }
            else if (keyState.IsKeyDown(Keys.Left))
            {
                currentPos.X -= 1;
                player.SetNextLocation(currentPos, level);
                level.dijkstra.Build(level, bot, player);
            }
            else if (keyState.IsKeyDown(Keys.Right))
            {
                currentPos.X += 1;
                player.SetNextLocation(currentPos, level);
                level.dijkstra.Build(level, bot, player);
            }
            // INITIATE THE DIJKSTRA ALGORITHM PATHFINDING
            else if (keyState.IsKeyDown(Keys.D))
            {
                level.dijkstra.Build(level, bot, player);
            }
            // INITIATE ASTAR ALGORITH PATHFINDING
            else if (keyState.IsKeyDown(Keys.A))
            {
                level.astar.Build(level, bot, player);
            }

            //update bot and player
            bot.Update(gameTime, level, player);
            player.Update(gameTime, level);

            base.Update(gameTime);
        }
Exemplo n.º 2
0
        public void Update(GameTime gameTime)
        {
            // Handle player input for movement
            HandlePlayerMovement();

            // Update the pathfinder
            map.pathfinder.Build(bot.GridPosition, player.GridPosition);

            // Update bot and player
            bot.Update(gameTime, map, player);
            player.Update(gameTime, map);
        }
Exemplo n.º 3
0
        protected override void Update(GameTime gameTime)
        {
            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
            {
                this.Exit();
            }

            //player movement: read keyboard
            KeyboardState keyState   = Keyboard.GetState();
            Coord2        currentPos = new Coord2();

            currentPos = player.GridPosition;
            if (keyState.IsKeyDown(Keys.Up))
            {
                currentPos.Y -= 1;
                player.SetNextLocation(currentPos, level);
            }
            else if (keyState.IsKeyDown(Keys.Down))
            {
                currentPos.Y += 1;
                player.SetNextLocation(currentPos, level);
            }
            else if (keyState.IsKeyDown(Keys.Left))
            {
                currentPos.X -= 1;
                player.SetNextLocation(currentPos, level);
            }
            else if (keyState.IsKeyDown(Keys.Right))
            {
                currentPos.X += 1;
                player.SetNextLocation(currentPos, level);
            }

            //update bot and player
            bot.Update(gameTime, level, player);
            player.Update(gameTime, level);

            base.Update(gameTime);
        }
Exemplo n.º 4
0
        public void Update(GameTime gameTime)
        {
            // Handle player input for movement
            HandlePlayerMovement();

            // Update the pathfinder
            if (map.pathfinder.GetAlgorithm() == PathfinderAlgorithm.ScentMap)
            {
                map.pathfinder.Build(bot.GridPosition, player.GridPosition);
            }
            else
            {
                if (InputHandler.IsKeyPressed(Keys.Enter))
                {
                    map.pathfinder.Build(bot.GridPosition, player.GridPosition);
                }
            }

            // Update bot and player
            bot.Update(gameTime, map, player);
            player.Update(gameTime, map);
        }
Exemplo n.º 5
0
        protected override void Update(GameTime gameTime)
        {
            // Allows the game to exit
            //if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
            //    this.Exit();

            //player movement: read keyboard
            KeyboardState keyState   = Keyboard.GetState();
            Coord2        currentPos = new Coord2();

            currentPos = player.GridPosition;

            if (keyState.IsKeyDown(Keys.Up))
            {
                currentPos.Y -= 1;
                player.SetNextLocation(currentPos, level);
                if ((hasAStar == true) && (liveUpdate == true))
                {
                    level.aStar.Build(level, bot, player);
                }
                if ((hasDijkstra == true) && (liveUpdate == true))
                {
                    level.dijkstra.Build(level, bot, player);
                }
            }
            else if (keyState.IsKeyDown(Keys.Down))
            {
                currentPos.Y += 1;
                player.SetNextLocation(currentPos, level);
                if ((hasAStar == true) && (liveUpdate == true))
                {
                    level.aStar.Build(level, bot, player);
                }
                if ((hasDijkstra == true) && (liveUpdate == true))
                {
                    level.dijkstra.Build(level, bot, player);
                }
            }
            else if (keyState.IsKeyDown(Keys.Left))
            {
                currentPos.X -= 1;
                player.SetNextLocation(currentPos, level);
                if ((hasAStar == true) && (liveUpdate == true))
                {
                    level.aStar.Build(level, bot, player);
                }
                if ((hasDijkstra == true) && (liveUpdate == true))
                {
                    level.dijkstra.Build(level, bot, player);
                }
            }
            else if (keyState.IsKeyDown(Keys.Right))
            {
                currentPos.X += 1;
                player.SetNextLocation(currentPos, level);
                if ((hasAStar == true) && (liveUpdate == true))
                {
                    level.aStar.Build(level, bot, player);
                }
                if ((hasDijkstra == true) && (liveUpdate == true))
                {
                    level.dijkstra.Build(level, bot, player);
                }
            }
            //toggle liveUpdate
            else if ((keyState.IsKeyDown(Keys.L)) && (liveUpdate == false))
            {
                liveUpdate = true;
            }
            else if ((keyState.IsKeyDown(Keys.L)) && (liveUpdate == true))
            {
                liveUpdate = false;
            }
            //use dijkstra
            else if (keyState.IsKeyDown(Keys.D))
            {
                bot = new AiBotStatic(10, 20);
                level.dijkstra.Build(level, bot, player);
                hasScentMap = false;
                hasDijkstra = true;
                hasAStar    = false;
            }
            //use AStar
            else if (keyState.IsKeyDown(Keys.A))
            {
                bot = new AiBotStatic(10, 20);
                level.aStar.Build(level, bot, player);
                hasScentMap = false;
                hasAStar    = true;
                hasDijkstra = false;
            }
            //Use Scent Map
            else if (keyState.IsKeyDown(Keys.S))
            {
                bot = new AiBotStatic(10, 20);
                level.scentMap.Update(level, player, bot);
                hasScentMap = true;
                hasDijkstra = false;
                hasAStar    = false;
            }
            //Reset
            else if (keyState.IsKeyDown(Keys.F))
            {
                bot         = new AiBotStatic(10, 20);
                hasScentMap = false;
                hasDijkstra = false;
                hasAStar    = false;
            }
            //Exit
            else if (keyState.IsKeyDown(Keys.Escape))
            {
                Exit();
            }

            //update bot and player
            bot.Update(gameTime, level, player);
            player.Update(gameTime, level);
            //Update Scent Map
            level.scentMap.Update(level, player, bot);
            base.Update(gameTime);
        }