Example #1
0
 /// <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()
 {
     // TODO: Add your initialization logic here
     Log.Write("Welcome to the dungeon!");
     level = new Dungeon(npcDicationary);
     dungeon.Add(level);
     npcs   = level.npcs;
     player = new Player(level.upStairs);
     fov    = new FOV(level.grid, player.location);
     fov.GetVisibility();
     base.Initialize();
 }
Example #2
0
        /// <summary>
        /// Get input for commands
        /// </summary>
        private void UpdateInput()
        {
            KeyboardState newState      = Keyboard.GetState();
            MouseState    newMouseState = Mouse.GetState();

            //Checks if the same key has been held for a period of time.
            if (newState.Equals(oldState))
            {
                if (!held)
                {
                    oldtime = time;
                    held    = true;
                }
                else
                {
                    if (!repeat && time.TotalMilliseconds - oldtime.TotalMilliseconds > 250)
                    {
                        repeat = true;
                    }
                }
            }
            else
            {
                held   = false;
                repeat = false;
            }

            // Is the SPACE key down?
            if (newState.IsKeyDown(Keys.Space))
            {
                if (!oldState.IsKeyDown(Keys.Space))
                {
                    dungeon.Clear();
                    level = new Dungeon(npcDicationary);
                    dungeon.Add(level);
                    npcs = level.npcs;
                    currentdngn_floor = 0;
                    player            = new Player(level.upStairs);
                    fov = new FOV(level.grid, player.location);
                    fov.GetVisibility();
                    Log.Write("New floor generated.");
                    playerActed = false;
                }
            }
            if (newState.IsKeyDown(Keys.Left) || newState.IsKeyDown(Keys.NumPad4))
            {
                if (!oldState.IsKeyDown(Keys.Left) && !oldState.IsKeyDown(Keys.NumPad4) || repeat)
                {
                    if (doorWait != "none")
                    {
                        doorTile = level.grid[(int)player.location.X - 1, (int)player.location.Y];
                        switch (doorWait)
                        {
                        case ("close"):
                            playerActed = doorTile.CloseDoor();
                            break;

                        case ("open"):
                            playerActed = doorTile.OpenDoor();
                            break;
                        }
                        doorWait = "none";
                    }
                    else
                    {
                        moveToList = player.Movement(new Vector2(-1, 0), level.grid, moveType, moveToList);
                        moveType   = "one";
                    }
                    fov = new FOV(level.grid, player.location);
                    fov.GetVisibility();
                }
            }
            if (newState.IsKeyDown(Keys.NumPad7))
            {
                if (!oldState.IsKeyDown(Keys.NumPad7) || repeat)
                {
                    if (doorWait != "none")
                    {
                        doorTile = level.grid[(int)player.location.X - 1, (int)player.location.Y - 1];
                        switch (doorWait)
                        {
                        case ("close"):
                            playerActed = doorTile.CloseDoor();
                            break;

                        case ("open"):
                            playerActed = doorTile.OpenDoor();
                            break;
                        }
                        doorWait = "none";
                    }
                    else
                    {
                        moveToList = player.Movement(new Vector2(-1, -1), level.grid, moveType, moveToList);
                        moveType   = "one";
                    }
                    fov = new FOV(level.grid, player.location);
                    fov.GetVisibility();
                }
            }
            if (newState.IsKeyDown(Keys.Up) || newState.IsKeyDown(Keys.NumPad8))
            {
                if (!oldState.IsKeyDown(Keys.Up) && !oldState.IsKeyDown(Keys.NumPad8) || repeat)
                {
                    if (doorWait != "none")
                    {
                        doorTile = level.grid[(int)player.location.X, (int)player.location.Y - 1];
                        switch (doorWait)
                        {
                        case ("close"):
                            playerActed = doorTile.CloseDoor();
                            break;

                        case ("open"):
                            playerActed = doorTile.OpenDoor();
                            break;
                        }
                        doorWait = "none";
                    }
                    else
                    {
                        moveToList = player.Movement(new Vector2(0, -1), level.grid, moveType, moveToList);
                        moveType   = "one";
                    }
                    fov = new FOV(level.grid, player.location);
                    fov.GetVisibility();
                }
            }
            if (newState.IsKeyDown(Keys.NumPad9))
            {
                if (!oldState.IsKeyDown(Keys.NumPad9) || repeat)
                {
                    if (doorWait != "none")
                    {
                        doorTile = level.grid[(int)player.location.X + 1, (int)player.location.Y - 1];
                        switch (doorWait)
                        {
                        case ("close"):
                            playerActed = doorTile.CloseDoor();
                            break;

                        case ("open"):
                            playerActed = doorTile.OpenDoor();
                            break;
                        }
                        doorWait = "none";
                    }
                    else
                    {
                        moveToList = player.Movement(new Vector2(1, -1), level.grid, moveType, moveToList);
                        moveType   = "one";
                    }
                    fov = new FOV(level.grid, player.location);
                    fov.GetVisibility();
                }
            }
            if (newState.IsKeyDown(Keys.Right) || newState.IsKeyDown(Keys.NumPad6))
            {
                if (!oldState.IsKeyDown(Keys.Right) && !oldState.IsKeyDown(Keys.NumPad6) || repeat)
                {
                    if (doorWait != "none")
                    {
                        doorTile = level.grid[(int)player.location.X + 1, (int)player.location.Y];
                        switch (doorWait)
                        {
                        case ("close"):
                            playerActed = doorTile.CloseDoor();
                            break;

                        case ("open"):
                            playerActed = doorTile.OpenDoor();
                            break;
                        }
                        doorWait = "none";
                    }
                    else
                    {
                        moveToList = player.Movement(new Vector2(1, 0), level.grid, moveType, moveToList);
                        moveType   = "one";
                    }
                    fov = new FOV(level.grid, player.location);
                    fov.GetVisibility();
                }
            }
            if (newState.IsKeyDown(Keys.NumPad3))
            {
                if (!oldState.IsKeyDown(Keys.NumPad3) || repeat)
                {
                    if (doorWait != "none")
                    {
                        doorTile = level.grid[(int)player.location.X + 1, (int)player.location.Y + 1];
                        switch (doorWait)
                        {
                        case ("close"):
                            playerActed = doorTile.CloseDoor();
                            break;

                        case ("open"):
                            playerActed = doorTile.OpenDoor();
                            break;
                        }
                        doorWait = "none";
                    }
                    else
                    {
                        moveToList = player.Movement(new Vector2(1, 1), level.grid, moveType, moveToList);
                        moveType   = "one";
                    }
                    fov = new FOV(level.grid, player.location);
                    fov.GetVisibility();
                }
            }
            if (newState.IsKeyDown(Keys.Down) || newState.IsKeyDown(Keys.NumPad2))
            {
                if (!oldState.IsKeyDown(Keys.Down) && !oldState.IsKeyDown(Keys.NumPad2) || repeat)
                {
                    if (doorWait != "none")
                    {
                        doorTile = level.grid[(int)player.location.X, (int)player.location.Y + 1];
                        switch (doorWait)
                        {
                        case ("close"):
                            playerActed = doorTile.CloseDoor();
                            break;

                        case ("open"):
                            playerActed = doorTile.OpenDoor();
                            break;
                        }
                        doorWait = "none";
                    }
                    else
                    {
                        moveToList = player.Movement(new Vector2(0, 1), level.grid, moveType, moveToList);
                        moveType   = "one";
                    }
                    fov = new FOV(level.grid, player.location);
                    fov.GetVisibility();
                }
            }
            if (newState.IsKeyDown(Keys.NumPad1))
            {
                if (!oldState.IsKeyDown(Keys.NumPad1) || repeat)
                {
                    if (doorWait != "none")
                    {
                        doorTile = level.grid[(int)player.location.X - 1, (int)player.location.Y + 1];
                        switch (doorWait)
                        {
                        case ("close"):
                            playerActed = doorTile.CloseDoor();
                            break;

                        case ("open"):
                            playerActed = doorTile.OpenDoor();
                            break;
                        }
                        doorWait = "none";
                    }
                    else
                    {
                        moveToList = player.Movement(new Vector2(-1, 1), level.grid, moveType, moveToList);
                        moveType   = "one";
                    }
                    fov = new FOV(level.grid, player.location);
                    fov.GetVisibility();
                }
            }
            if (newState.IsKeyDown(Keys.OemPeriod))
            {
                if (!oldState.IsKeyDown(Keys.OemPeriod))
                {
                    if (player.MoveDown(level.grid))
                    {
                        if (currentdngn_floor == dungeon.Count - 1)
                        {
                            level = new Dungeon(npcDicationary);
                            dungeon.Add(level);
                            npcs = level.npcs;
                            currentdngn_floor++;
                        }
                        else
                        {
                            currentdngn_floor++;
                            level = dungeon[currentdngn_floor];
                        }
                        player.location = level.upStairs.tilePos;
                        fov             = new FOV(level.grid, player.location);
                        fov.GetVisibility();
                    }
                }
            }
            if (newState.IsKeyDown(Keys.OemComma))
            {
                if (!oldState.IsKeyDown(Keys.OemComma))
                {
                    if (currentdngn_floor > 0)
                    {
                        if (player.MoveUp(level.grid))
                        {
                            currentdngn_floor--;
                            level           = dungeon[currentdngn_floor];
                            npcs            = level.npcs;
                            player.location = level.downStairs.tilePos;
                            fov             = new FOV(level.grid, player.location);
                            fov.GetVisibility();
                        }
                    }
                }
            }
            if (newState.IsKeyDown(Keys.C))
            {
                if (!oldState.IsKeyDown(Keys.C))
                {
                    doorWait = "close";
                    Log.Write("Close which door?");
                }
            }
            if (newState.IsKeyDown(Keys.O))
            {
                if (!oldState.IsKeyDown(Keys.O))
                {
                    doorWait = "open";
                    Log.Write("Open which door?");
                }
            }
            if (newState.IsKeyDown(Keys.Divide))
            {
                if (!oldState.IsKeyDown(Keys.Divide))
                {
                    moveType = "five";
                }
            }
            if (newState.IsKeyDown(Keys.Multiply))
            {
                if (!oldState.IsKeyDown(Keys.Multiply))
                {
                    moveType = "end";
                }
            }

            if (newState.IsKeyDown(Keys.I))
            {
                if (!oldState.IsKeyDown(Keys.I))
                {
                    menu = !menu;
                }
            }

            /*if (newState.IsKeyDown(Keys.X))
             * {
             *  if (!oldState.IsKeyDown(Keys.X))
             *  {
             *      moveToList = Pathing.FindPath(new Vector2(12,12),level.grid);
             *  }
             * }*/

            if (newState.IsKeyDown(Keys.Escape))
            {
                if (!oldState.IsKeyDown(Keys.Escape))
                {
                    Exit();
                }
            }

            if (newState.IsKeyDown(Keys.Enter))
            {
                if (!oldState.IsKeyDown(Keys.Enter))
                {
                    Log.Write("Test message!");
                }
            }

            if (newState.IsKeyDown(Keys.F10))
            {
                if (!oldState.IsKeyDown(Keys.F10))
                {
                    for (int x = 0; x < 50; x++)
                    {
                        for (int y = 0; y < 50; y++)
                        {
                            level.grid[x, y].visible = true;
                        }
                    }
                }
            }

            if (newMouseState.LeftButton == ButtonState.Pressed)
            {
                if (oldMouseState.LeftButton != ButtonState.Pressed &&
                    GraphicsDevice.Viewport.Bounds.Contains(new Point((int)newMouseState.X, (int)newMouseState.Y)))
                {
                    Vector2 clickedTile = new Vector2();
                    Vector2 moveToTile  = new Vector2();
                    clickedTile.X = newMouseState.X / 32;  //Get on screen tile coords
                    clickedTile.Y = newMouseState.Y / 32;

                    if (clickedTile.X >= 0 && clickedTile.X < 25 && clickedTile.Y >= 0 && clickedTile.Y < 25)
                    {
                        moveToTile = viewport.GetTile(clickedTile);  //Get whole dungeon tile coords
                        if (level.grid[(int)moveToTile.X, (int)moveToTile.Y].seen ||
                            level.grid[(int)moveToTile.X, (int)moveToTile.Y].visible)
                        {
                            moveToList = Pathing.FindPath(moveToTile, player.location, level.grid);
                        }
                    }
                }
            }

            // Update saved state.
            oldState      = newState;
            oldMouseState = newMouseState;
        }
Example #3
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)
        {
            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
            {
                this.Exit();
            }

            // TODO: Add your update logic here
            time = gameTime.TotalGameTime;


            foreach (NPC npc in npcs)
            {
                /*if (playerActed)
                 * {
                 *  npc.MovePlayer(new Vector2(random.Next(3) - 1, random.Next(3) - 1), level.grid);
                 * }*/
                npc.npcStillAlive(level.grid);
            }

            /*playerActed = false;
             *
             * if (!playerActed)
             * {*/
            if (!menu)
            {
                UpdateInput();
            }
            else
            {
                MenuInput();
            }

            if (moveToList.Count > 0)            //Update postion here so it can be drawn
            {
                playerActed = player.MovePlayer(moveToList[0], level.grid);
                moveToList.RemoveAt(0);
                fov = new FOV(level.grid, player.location);
                fov.GetVisibility();
                if (player.MonsterCheck(level.grid) && moveToList.Count > 0)
                {
                    if (!enemyDetected)
                    {
                        Log.Write("Enemy detected! Auto-travel has stopped.");
                    }
                    moveToList.Clear();
                    enemyDetected = true;
                }
            }
            if (!player.MonsterCheck(level.grid))
            {
                enemyDetected = false;
            }
            else
            {
                enemyDetected = true;
            }

            //}

            base.Update(gameTime);
        }