public override void Update(GameTime gameTime)
        {
            world.Update(gameTime);
            player.Update(gameTime);
            player.Camera.LockToSprite(player.Sprite);

            if (InputHandler.KeyReleased(Keys.Space) ||
                InputHandler.ButtonReleased(Buttons.A, PlayerIndex.One))
            {
                foreach (ILayer layer in World.Levels[World.CurrentLevel].Map.Layers)
                {
                    if (layer is CharacterLayer)
                    {
                        foreach (Character c in ((CharacterLayer)layer).Characters.Values)
                        {
                            float distance = Vector2.Distance(
                                player.Sprite.Center,
                                c.Sprite.Center);

                            if (distance < Character.SpeakingRadius && c is NonPlayerCharacter)
                            {
                                NonPlayerCharacter npc = (NonPlayerCharacter)c;

                                if (npc.HasConversation)
                                {
                                    StateManager.PushState(GameRef.ConversationScreen);

                                    GameRef.ConversationScreen.SetConversation(
                                        player,
                                        npc,
                                        npc.CurrentConversation);

                                    GameRef.ConversationScreen.StartConversation();
                                }
                            }
                            else if (distance < Character.SpeakingRadius && c is Merchant)
                            {
                                StateManager.PushState(GameRef.ShopScreen);
                                GameRef.ShopScreen.SetMerchant(c as Merchant);
                            }
                        }
                    }
                }
            }

            if (InputHandler.KeyReleased(Keys.I))
            {
                StateManager.PushState(GameRef.InventoryScreen);
            }

            base.Update(gameTime);
        }
Пример #2
0
        public override void HandleInput(PlayerIndex playerIndex)
        {
            if (!HasFocus)
            {
                return;
            }

            if (InputHandler.KeyReleased(Keys.Enter) ||
                InputHandler.ButtonReleased(Buttons.A, playerIndex))
            {
                base.OnSelected(null);
            }
        }
Пример #3
0
        public override void HandleInput(PlayerIndex playerIndex)
        {
            if (!HasFocus)
            {
                return;
            }

            if (InputHandler.KeyReleased(Keys.Down) ||
                InputHandler.ButtonReleased(Buttons.LeftThumbstickDown, playerIndex))
            {
                if (selectedItem < items.Count - 1)
                {
                    selectedItem++;

                    if (selectedItem >= startItem + lineCount)
                    {
                        startItem = selectedItem - lineCount + 1;
                    }

                    OnSelectionChanged(null);
                }
            }
            else if (InputHandler.KeyReleased(Keys.Up) ||
                     InputHandler.ButtonReleased(Buttons.LeftThumbstickUp, playerIndex))
            {
                if (selectedItem > 0)
                {
                    selectedItem--;

                    if (selectedItem < startItem)
                    {
                        startItem = selectedItem;
                    }

                    OnSelectionChanged(null);
                }
            }

            if (InputHandler.KeyReleased(Keys.Enter) ||
                InputHandler.ButtonReleased(Buttons.A, playerIndex))
            {
                HasFocus = false;
                OnSelected(null);
            }

            if (InputHandler.KeyReleased(Keys.Escape) ||
                InputHandler.ButtonReleased(Buttons.B, playerIndex))
            {
                HasFocus = false;
            }
        }
Пример #4
0
        /* The Update() functon for the InventoryScreen updates the ControlManager, and handles input to switch back to the WorldScreen. */
        public override void Update(GameTime gameTime)
        {
            ControlManager.Update(gameTime, PlayerIndex.One);

            /* If the "I" key or Start button is released, then the InventoryScreen is popped off the stack of states.
             * The engine should then return to the WorldScreen. */
            if (InputHandler.KeyReleased(Keys.I) || InputHandler.ButtonReleased(Buttons.Start, PlayerIndex.One))
            {
                Change(ChangeType.Pop, null);
            }

            /* The parent Update() function is also called. */
            base.Update(gameTime);
        }
Пример #5
0
        public override void HandleInput(PlayerIndex playerIndex)
        {
            if (!HasFocus)
            {
                return;
            }

            if (InputHandler.KeyReleased(Keys.Down) ||
                InputHandler.ButtonReleased(Buttons.LeftThumbstickDown, playerIndex))
            {
                if (SelectedIndex < Items.Count - 1)
                {
                    SelectedIndex++;
                    if (SelectedIndex >= startItem + lineCount)
                    {
                        startItem = SelectedIndex - lineCount + 1;
                    }

                    OnSelectionChanged(EventArgs.Empty);
                }
            }
            else if (InputHandler.KeyReleased(Keys.Up) ||
                     InputHandler.ButtonReleased(Buttons.LeftThumbstickUp, playerIndex))
            {
                if (SelectedIndex > 0)
                {
                    SelectedIndex--;
                    if (SelectedIndex < startItem)
                    {
                        startItem = SelectedIndex;
                    }

                    OnSelectionChanged(EventArgs.Empty);
                }
            }

            if (InputHandler.KeyReleased(Keys.Enter) ||
                InputHandler.ButtonReleased(Buttons.A, playerIndex))
            {
                HasFocus = false;
                OnSelect(EventArgs.Empty);
            }

            if (InputHandler.KeyReleased(Keys.Escape) ||
                InputHandler.ButtonReleased(Buttons.B, playerIndex))
            {
                HasFocus = false;
            }
        }
Пример #6
0
        public override void HandleInput(PlayerIndex playerIndex)
        {
            if (HasFocus &&
                bounds.Contains(InputHandler.MousePos) &&
                InputHandler.MouseButtonPressed(MouseButton.LeftButton))
            {
                base.OnSelected(null);
            }

            if (InputHandler.KeyReleased(Keys.Enter) ||
                InputHandler.ButtonReleased(Buttons.A, playerIndex))
            {
                base.OnSelected(null);
            }
        }
Пример #7
0
        public override void Update(GameTime gameTime)
        {
            elapsed += gameTime.ElapsedGameTime;

            menuMain.Update(gameTime, PlayerIndex.One);
            System.Console.WriteLine(menuMain.SelectedIndex);

            if (InputHandler.KeyPressed(Keys.Enter) || InputHandler.ButtonReleased(Buttons.A, PlayerIndex.One))
            {
                if (menuMain.SelectedIndex == 0)
                {
                    InputHandler.FlushInput();
                }
                else if (menuMain.SelectedIndex == 1)
                {
                    InputHandler.FlushInput();
                }
                else if (menuMain.SelectedIndex == 2)
                {
                    InputHandler.FlushInput();
                }
                else if (menuMain.SelectedIndex == 3)
                {
                    Game.Exit();
                }
            }

            bgMountDest.X   -= 1;
            bgFollowMount.X -= 1;

            if (bgMountDest.X <= -bgMountains.Width)
            {
                bgMountDest.X   = 0;
                bgFollowMount.X = bgMountains.Width;
            }

            bgCloudDest.X   -= 2;
            bgFollowCloud.X -= 2;

            if (bgCloudDest.X <= -bgClouds.Width)
            {
                bgCloudDest.X   = 0;
                bgFollowCloud.X = bgClouds.Width;
            }

            base.Update(gameTime);
        }
Пример #8
0
        private void CheckForInput()
        {
            if (InputHandler.KeyReleased(Keys.F) ||
                InputHandler.ButtonReleased(Buttons.RightStick, PlayerIndex.One))
            {
                StateManager.Camera.ToggleCameraMode();
            }

            /*
             * if (player.Camera.CameraMode != CameraMode.Follow)
             * {
             *  if (InputHandler.KeyReleased(Keys.C) ||
             *      InputHandler.ButtonReleased(Buttons.LeftStick, PlayerIndex.One))
             *  {
             *      player.Camera.LockToSprite(sprite);
             *  }
             * }*/
        }
        public override void Update(GameTime gameTime)
        {
            conversation.Update(gameTime);

            if (InputHandler.KeyReleased(Keys.Enter) || InputHandler.KeyReleased(Keys.Space) ||
                InputHandler.ButtonReleased(Buttons.A, PlayerIndex.One) ||
                (InputHandler.CheckMouseReleased(MouseButton.Left) && conversation.CurrentScene.IsOver))
            {
                InputHandler.Flush();
                SceneAction action = conversation.CurrentScene.OptionAction;

                switch (action.Action)
                {
                case ActionType.Talk:
                    conversation.ChangeScene(conversation.CurrentScene.OptionScene);
                    break;

                case ActionType.Quest:
                    if (npc.HasQuest && npc.Quests[0].Steps[0].Level <= player.Character.Entity.Level)
                    {
                        npc.Quests[0].Steps[0].Start();
                        GamePlayScreen.Player.Quests.Add(npc.Quests[0]);
                    }
                    npc.SetConversation(conversation.CurrentScene.OptionScene);
                    conversation =
                        conversations.GetConversation(conversation.CurrentScene.OptionScene);
                    conversation.StartConversation();
                    break;

                case ActionType.Change:
                    npc.SetConversation(conversation.CurrentScene.OptionScene);
                    conversation =
                        conversations.GetConversation(conversation.CurrentScene.OptionScene);
                    conversation.StartConversation();
                    break;

                case ActionType.End:
                    StateManager.PopState();
                    break;
                }
            }

            base.Update(gameTime);
        }
Пример #10
0
 public void Update(GameTime gameTime, PlayerIndex index)
 {
     if (InputHandler.KeyReleased(Keys.Up) || InputHandler.ButtonReleased(Buttons.LeftThumbstickUp, index))
     {
         selectedIndex--;
         if (selectedIndex < 0)
         {
             selectedIndex = options.Count - 1;
         }
     }
     else if (InputHandler.KeyReleased(Keys.Down) || InputHandler.ButtonReleased(Buttons.LeftThumbstickDown, index))
     {
         selectedIndex++;
         if (selectedIndex > options.Count - 1)
         {
             selectedIndex = 0;
         }
     }
 }
Пример #11
0
        public override void HandleInput(PlayerIndex playerIndex)
        {
            if (!HasFocus)
            {
                return;
            }

            if (InputHandler.KeyReleased(Keys.Enter) ||
                InputHandler.ButtonReleased(Buttons.A, playerIndex))
            {
                base.OnSelected(null);
            }

            if (InputHandler.CheckMouseReleased(MouseButton.Left))
            {
                if (GetBounds().Contains(InputHandler.MouseAsPoint))
                {
                    base.OnSelected(null);
                }
            }
        }
Пример #12
0
        public override void HandleInput(PlayerIndex playerIndex)
        {
            if (items.Count == 0)
            {
                return;
            }

            if (InputHandler.ButtonReleased(Buttons.LeftThumbstickLeft, playerIndex) ||
                InputHandler.ButtonReleased(Buttons.DPadLeft, playerIndex) ||
                InputHandler.KeyReleased(Keys.Left) ||
                (InputHandler.CheckMouseReleased(MouseButton.Left) && overLeft))
            {
                selectedItem--;

                if (selectedItem < 0)
                {
                    selectedItem = 0;
                }

                OnSelectionChanged();
            }

            if (InputHandler.ButtonReleased(Buttons.LeftThumbstickRight, playerIndex) ||
                InputHandler.ButtonReleased(Buttons.DPadRight, playerIndex) ||
                InputHandler.KeyReleased(Keys.Right) ||
                (InputHandler.CheckMouseReleased(MouseButton.Left) && overRight))
            {
                selectedItem++;

                if (selectedItem >= items.Count)
                {
                    selectedItem = items.Count - 1;
                }

                OnSelectionChanged();
            }
        }
Пример #13
0
 public override void HandleInput(PlayerIndex playerIndex)
 {
     HasFocus = true;
     if ( //trying new format for sake of clarity
         InputHandler.KeyReleased(Keys.Enter)
         ||
         InputHandler.ButtonReleased(Buttons.A, playerIndex)
         ||
         InputHandler.CurrentGesture.GestureType == GestureType.Hold &&
         InputHandler.CurrentGesture.Position.X > this.position.X &&
         InputHandler.CurrentGesture.Position.X < this.position.X + SpriteFont.MeasureString(Text).X&&
         InputHandler.CurrentGesture.Position.Y > this.position.Y &&
         InputHandler.CurrentGesture.Position.Y < this.position.Y + SpriteFont.MeasureString(Text).Y
         ||
         InputHandler.CurrentMouseState.LeftButton == ButtonState.Pressed &&
         InputHandler.CurrentMouseState.X > this.position.X &&
         InputHandler.CurrentMouseState.X < this.position.X + SpriteFont.MeasureString(Text).X&&
         InputHandler.CurrentMouseState.Y > this.position.Y &&
         InputHandler.CurrentMouseState.Y < this.position.Y + SpriteFont.MeasureString(Text).Y
         )
     {
         base.OnSelected(null);
     }
 }
Пример #14
0
        public override void Update(GameTime gameTime)
        {
            conversation.Update(gameTime);

            if (InputHandler.KeyReleased(Keys.Enter) || InputHandler.KeyReleased(Keys.Space) || InputHandler.ButtonReleased(Buttons.A, PlayerIndex.One))
            {
                InputHandler.Flush();

                SceneAction action = conversation.CurrentScene.OptionAction;

                switch (action.Action)
                {
                case ActionType.Talk:
                    conversation.ChangeScene(conversation.CurrentScene.OptionScene);
                    break;

                case ActionType.Quest:
                    conversation.ChangeScene(conversation.CurrentScene.OptionScene);
                    break;

                case ActionType.Change:
                    conversation = conversations.GetConversation(conversation.CurrentScene.OptionScene);
                    conversation.StartConversation();
                    break;

                case ActionType.End:
                    StateManager.PopState();
                    break;
                }
            }

            base.Update(gameTime);
        }
Пример #15
0
        public void Update(GameTime gameTime)
        {
            camera.Update(gameTime);
            Sprite.Update(gameTime);

            if (InputHandler.KeyReleased(Keys.PageUp) ||
                InputHandler.ButtonReleased(Buttons.LeftShoulder, PlayerIndex.One))
            {
                camera.ZoomIn();

                if (camera.CameraMode == CameraMode.Follow)
                {
                    camera.LockToSprite(Sprite);
                }
            }
            else if (InputHandler.KeyReleased(Keys.PageDown) ||
                     InputHandler.ButtonReleased(Buttons.RightShoulder, PlayerIndex.One))
            {
                camera.ZoomOut();

                if (camera.CameraMode == CameraMode.Follow)
                {
                    camera.LockToSprite(Sprite);
                }
            }

            Vector2 motion = new Vector2();

            if (InputHandler.KeyDown(Keys.W) ||
                InputHandler.ButtonDown(Buttons.LeftThumbstickUp, PlayerIndex.One))
            {
                Sprite.CurrentAnimation = AnimationKey.Up;
                motion.Y = -1;
            }
            else if (InputHandler.KeyDown(Keys.S) ||
                     InputHandler.ButtonDown(Buttons.LeftThumbstickDown, PlayerIndex.One))
            {
                Sprite.CurrentAnimation = AnimationKey.Down;
                motion.Y = 1;
            }

            if (InputHandler.KeyDown(Keys.A) ||
                InputHandler.ButtonDown(Buttons.LeftThumbstickLeft, PlayerIndex.One))
            {
                Sprite.CurrentAnimation = AnimationKey.Left;
                motion.X = -1;
            }
            else if (InputHandler.KeyDown(Keys.D) ||
                     InputHandler.ButtonDown(Buttons.LeftThumbstickRight, PlayerIndex.One))
            {
                Sprite.CurrentAnimation = AnimationKey.Right;
                motion.X = 1;
            }

            if (motion != Vector2.Zero)
            {
                UpdatePosition(gameTime, motion);
            }
            else
            {
                Sprite.IsAnimating = false;
            }

            if (InputHandler.KeyReleased(Keys.F) ||
                InputHandler.ButtonReleased(Buttons.RightStick, PlayerIndex.One))
            {
                camera.ToggleCameraMode();

                if (camera.CameraMode == CameraMode.Follow)
                {
                    camera.LockToSprite(Sprite);
                }
            }

            if (camera.CameraMode != CameraMode.Follow)
            {
                if (InputHandler.KeyReleased(Keys.C) ||
                    InputHandler.ButtonReleased(Buttons.LeftStick, PlayerIndex.One))
                {
                    camera.LockToSprite(Sprite);
                }
            }
        }
Пример #16
0
        /* HandleInput controls the changing of the selected item. */
        public override void HandleInput(PlayerIndex playerIndex)
        {
            /* If the list is empty, the function must stop here to avoid crashes. */
            if (items.Count == 0)
            {
                return;
            }

            /* If the left arrow key is pressed, then the selected index is reduced by one.
             * The selected index cannot go below zero, and if it goes below, it is set to zero again.
             * The OnSelectionChanged() function is called so that the right event handler is fired. */
            if (InputHandler.ButtonReleased(Buttons.LeftThumbstickLeft, playerIndex) || InputHandler.ButtonReleased(Buttons.DPadLeft, playerIndex) || InputHandler.KeyReleased(Keys.Left))
            {
                selectedItem--;
                if (selectedItem < 0)
                {
                    selectedItem = 0;
                }
                OnSelectionChanged();
            }

            /* If the right arrow key is pressed, the selected index increments.
             * The index can't go past the end of the list, and if it tries, it's set to the end of the list again.
             * Finally, OnSelectionChanged() is called to trigger the event handler. */
            if (InputHandler.ButtonReleased(Buttons.LeftThumbstickRight, playerIndex) || InputHandler.ButtonReleased(Buttons.DPadRight, playerIndex) || InputHandler.KeyReleased(Keys.Right))
            {
                selectedItem++;
                if (selectedItem >= items.Count)
                {
                    selectedItem = items.Count - 1;
                }
                OnSelectionChanged();
            }
        }
Пример #17
0
        public override void Update(GameTime gameTime)
        {
            world.Update(gameTime);
            player.Update(gameTime);
            player.Camera.LockToSprite(player.Sprite);

            if (InputHandler.KeyReleased(Keys.Space) ||
                InputHandler.ButtonReleased(Buttons.A, PlayerIndex.One))
            {
                foreach (ILayer layer in World.Levels[World.CurrentLevel].Map.Layers)
                {
                    if (layer is CharacterLayer)
                    {
                        foreach (Character c in ((CharacterLayer)layer).Characters.Values)
                        {
                            float distance = Vector2.Distance(
                                player.Sprite.Center,
                                c.Sprite.Center);

                            if (distance < Character.SpeakingRadius && c is NonPlayerCharacter)
                            {
                                NonPlayerCharacter npc = (NonPlayerCharacter)c;

                                if (npc.HasConversation)
                                {
                                    StateManager.PushState(GameRef.ConversationScreen);

                                    GameRef.ConversationScreen.SetConversation(
                                        player,
                                        npc,
                                        npc.CurrentConversation);

                                    GameRef.ConversationScreen.StartConversation();
                                }
                            }
                            else if (distance < Character.SpeakingRadius && c is Merchant)
                            {
                                StateManager.PushState(GameRef.ShopScreen);
                                GameRef.ShopScreen.SetMerchant(c as Merchant);
                            }
                        }
                    }
                }
            }

            MobLayer mobLayer = World.Levels[World.CurrentLevel].Map.Layers.Find(x => x is MobLayer) as MobLayer;

            if (playerAttacking)
            {
                foreach (var mob in mobLayer.Mobs.Values)
                {
                    if (playerSword.Intersects(mob.Sprite.Bounds))
                    {
                        if (player.Character.Entity.MainHand != null &&
                            player.Character.Entity.MainHand.Item is Weapon)
                        {
                            mob.Entity.ApplyDamage(player.Character.Entity.MainHand);
                            playerAttacking = false;

                            if (mob.Entity.Health.CurrentValue <= 0)
                            {
                                StateManager.PushState(GameRef.LootScreen);
                                GamePlayScreen.Player.Character.Entity.AddExperience(mob.XPValue);
                                GameRef.LootScreen.Gold = mob.GoldDrop;

                                foreach (var i in mob.Drops)
                                {
                                    GameRef.LootScreen.Items.Add(i);
                                }
                            }
                        }
                    }
                }
            }

            foreach (var mob in mobLayer.Mobs.Where(kv => kv.Value.Entity.Health.CurrentValue <= 0).ToList())
            {
                mobLayer.Mobs.Remove(mob.Key);
            }

            foreach (var mob in mobLayer.Mobs.Values)
            {
                float distance = Vector2.Distance(player.Sprite.Center, mob.Sprite.Center);

                if (distance < mob.Sprite.Width * 4)
                {
                    Vector2 motion = Vector2.Zero;

                    if (mob.Sprite.Position.X < player.Sprite.Position.X)
                    {
                        motion.X = 1;
                        mob.Sprite.CurrentAnimation = AnimationKey.Right;
                    }

                    if (mob.Sprite.Position.X > player.Sprite.Position.X)
                    {
                        motion.X = -1;
                        mob.Sprite.CurrentAnimation = AnimationKey.Left;
                    }

                    if (mob.Sprite.Position.Y < player.Sprite.Position.Y)
                    {
                        motion.Y = 1;
                        mob.Sprite.CurrentAnimation = AnimationKey.Down;
                    }

                    if (mob.Sprite.Position.Y > player.Sprite.Position.Y)
                    {
                        motion.Y = -1;
                        mob.Sprite.CurrentAnimation = AnimationKey.Up;
                    }

                    if (motion != Vector2.Zero)
                    {
                        motion.Normalize();
                    }

                    float speed = 200f;

                    motion *= speed * (float)gameTime.ElapsedGameTime.TotalSeconds;

                    mob.Sprite.Position   += motion;
                    mob.Sprite.IsAnimating = true;

                    if (mob.Sprite.Bounds.Intersects(player.Sprite.Bounds))
                    {
                        mob.Sprite.Position -= motion;
                    }
                }
                else
                {
                    mob.Sprite.IsAnimating = false;
                }
            }
            if (InputHandler.KeyReleased(Keys.I))
            {
                StateManager.PushState(GameRef.InventoryScreen);
            }

            if (InputHandler.KeyReleased(Keys.C))
            {
                StateManager.PushState(GameRef.StatsScreen);
                Visible = true;
            }

            if (Player.Character.Entity.Level < Mechanics.Experiences.Length)
            {
                if (Player.Character.Entity.Experience >= Mechanics.Experiences[Player.Character.Entity.Level])
                {
                    Player.Character.Entity.LevelUp();
                    StateManager.PushState(GameRef.LevelScreen);
                    Visible = true;
                }
            }

            if (InputHandler.CheckMousePress(MouseButton.Left) && playerTimer > 0.25 && !playerAttacking)
            {
                playerAttacking = true;
                playerTimer     = 0;

                if (player.Sprite.CurrentAnimation == AnimationKey.Up)
                {
                    attackDirection = 0;
                }
                else if (player.Sprite.CurrentAnimation == AnimationKey.Right)
                {
                    attackDirection = 1;
                }
                else if (player.Sprite.CurrentAnimation == AnimationKey.Down)
                {
                    attackDirection = 2;
                }
                else
                {
                    attackDirection = 3;
                }
            }

            if (playerTimer >= 0.25)
            {
                playerAttacking = false;
            }
            playerTimer += gameTime.ElapsedGameTime.TotalSeconds;

            base.Update(gameTime);
        }
Пример #18
0
        private void HandleConversation()
        {
            if (InputHandler.KeyReleased(Keys.F) ||
                InputHandler.ButtonReleased(Buttons.A, PlayerIndex.One))
            {
                foreach (ILayer layer in World.Levels[World.CurrentLevel].Map.Layers)
                {
                    if (layer is CharacterLayer layer1)
                    {
                        foreach (Character c in layer1.Characters.Values)
                        {
                            float distance = Vector2.Distance(
                                player.Sprite.Center,
                                c.Sprite.Center);

                            if (distance < Character.SpeakingRadius && c is NonPlayerCharacter character)
                            {
                                NonPlayerCharacter npc = character;

                                if (npc.Quests.Count > 0)
                                {
                                    npc.Quests[0].CheckFinished();

                                    if (npc.Quests[0].Finished)
                                    {
                                        Reward r = npc.Quests[0].Reward;

                                        player.Gold += r.Gold;
                                        player.Character.Entity.AddExperience(r.Experience);

                                        foreach (var s in r.Items)
                                        {
                                            GameItem item = GameItemManager.GetItem(s);

                                            if (item != null)
                                            {
                                                player.Backpack.AddItem(item);
                                            }
                                        }

                                        npc.Quests.RemoveAt(0);

                                        GameRef.QuestCompleteState.SetReward(r);
                                        StateManager.PushState(GameRef.QuestCompleteState);
                                        return;
                                    }
                                }

                                if (npc.HasConversation)
                                {
                                    StateManager.PushState(GameRef.ConversationScreen);

                                    GameRef.ConversationScreen.SetConversation(
                                        player,
                                        npc,
                                        npc.CurrentConversation);

                                    GameRef.ConversationScreen.StartConversation();
                                }
                            }
                            else if (distance < Character.SpeakingRadius && c is Merchant)
                            {
                                StateManager.PushState(GameRef.ShopScreen);
                                GameRef.ShopScreen.SetMerchant(c as Merchant);
                            }
                        }
                    }
                }
            }
        }
Пример #19
0
        public void Update(GameTime gameTime, MapLayer tilemap)
        {
            createBullet = false;
            playerOrigin = new Vector2(animatedSprite.Position.X + animatedSprite.Width / 2, animatedSprite.Position.Y + animatedSprite.Height / 2);
            animatedSprite.Update(gameTime);

            if (InputHandler.KeyReleased(Keys.Z) || InputHandler.Scroll(Mouse.GetState()) == 1 ||
                InputHandler.ButtonReleased(Buttons.LeftShoulder, PlayerIndex.One))
            {
                camera.Zoom(0.25f);
                camera.LockToSprite(animatedSprite);
            }

            else if (InputHandler.KeyReleased(Keys.X) || InputHandler.Scroll(Mouse.GetState()) == -1 ||
                     InputHandler.ButtonReleased(Buttons.RightShoulder, PlayerIndex.One))
            {
                camera.Zoom(-0.25f);
                camera.LockToSprite(animatedSprite);
            }
            motion = new Vector2();
            if (InputHandler.KeyDown(Keys.W) ||
                InputHandler.ButtonDown(Buttons.LeftThumbstickUp, PlayerIndex.One))
            {
                animatedSprite.currentAnimation = Constants.Direction.Up;
                if (checkIfCanWalkOnTile(tilemap, 0, -3) == 2)
                {
                    completedLevel = true;
                }
                if (checkIfCanWalkOnTile(tilemap, 0, -3) == 1)
                {
                    motion.Y = -9;
                }
            }
            else if (InputHandler.KeyDown(Keys.S) ||
                     InputHandler.ButtonDown(Buttons.LeftThumbstickDown, PlayerIndex.One))
            {
                animatedSprite.currentAnimation = Constants.Direction.Down;
                if (checkIfCanWalkOnTile(tilemap, 0, 3) == 2)
                {
                    completedLevel = true;
                }
                if (checkIfCanWalkOnTile(tilemap, 0, 3) == 1)
                {
                    motion.Y = 9;
                }
            }
            if (InputHandler.KeyDown(Keys.A) ||
                InputHandler.ButtonDown(Buttons.LeftThumbstickLeft, PlayerIndex.One))
            {
                animatedSprite.currentAnimation = Constants.Direction.Left;
                if (checkIfCanWalkOnTile(tilemap, -3, 0) == 2)
                {
                    completedLevel = true;
                }
                if (checkIfCanWalkOnTile(tilemap, -3, 0) == 1)
                {
                    motion.X = -9;
                }
            }
            if (InputHandler.KeyDown(Keys.D) ||
                InputHandler.ButtonDown(Buttons.LeftThumbstickRight, PlayerIndex.One))
            {
                animatedSprite.currentAnimation = Constants.Direction.Right;
                if (checkIfCanWalkOnTile(tilemap, 3, 0) == 2)
                {
                    completedLevel = true;
                }
                if (checkIfCanWalkOnTile(tilemap, 3, 0) == 1)
                {
                    motion.X = 9;
                }
            }



            if (motion != Vector2.Zero)
            {
                animatedSprite.isAnimating = true;
                motion.Normalize();
                animatedSprite.Position += motion * animatedSprite.Speed;
                animatedSprite.LockToMap();
                camera.LockToSprite(animatedSprite);
            }
            else
            {
                animatedSprite.isAnimating = false;
            }
            if (InputHandler.KeyPressed(Keys.Space) ||
                InputHandler.ButtonDown(Buttons.A, PlayerIndex.One))
            {
                bullets.Add(new Bullet(bulletSprite, playerOrigin, animatedSprite.currentAnimation.ToString(), motion));
                createBullet = true;
            }

            foreach (Bullet bullet in bullets)
            {
                bullet.Update(gameTime, tilemap);
            }

            UpdateHealthBar();

            playerHealth.Update(gameTime);
        }
Пример #20
0
        public override void Update(GameTime gameTime)
        {
            player.Update(gameTime);
            sprite.Update(gameTime);

            if (InputHandler.KeyReleased(Keys.PageUp) ||
                InputHandler.ButtonReleased(Buttons.LeftShoulder, PlayerIndex.One))
            {
                player.Camera.ZoomIn();

                if (player.Camera.CameraMode == CameraMode.Follow)
                {
                    player.Camera.LockToSprite(sprite);
                }
            }
            else if (InputHandler.KeyReleased(Keys.PageDown) ||
                     InputHandler.ButtonReleased(Buttons.RightShoulder, PlayerIndex.One))
            {
                player.Camera.ZoomOut();

                if (player.Camera.CameraMode == CameraMode.Follow)
                {
                    player.Camera.LockToSprite(sprite);
                }
            }

            Vector2 motion = new Vector2();

            if (InputHandler.KeyDown(Keys.W) ||
                InputHandler.ButtonDown(Buttons.LeftThumbstickUp, PlayerIndex.One))
            {
                sprite.CurrentAnimation = AnimationKey.Up;
                motion.Y = -1;
            }
            else if (InputHandler.KeyDown(Keys.S) ||
                     InputHandler.ButtonDown(Buttons.LeftThumbstickDown, PlayerIndex.One))
            {
                sprite.CurrentAnimation = AnimationKey.Down;
                motion.Y = 1;
            }

            if (InputHandler.KeyDown(Keys.A) ||
                InputHandler.ButtonDown(Buttons.LeftThumbstickLeft, PlayerIndex.One))
            {
                sprite.CurrentAnimation = AnimationKey.Left;
                motion.X = -1;
            }
            else if (InputHandler.KeyDown(Keys.D) ||
                     InputHandler.ButtonDown(Buttons.LeftThumbstickRight, PlayerIndex.One))
            {
                sprite.CurrentAnimation = AnimationKey.Right;
                motion.X = 1;
            }

            if (motion != Vector2.Zero)
            {
                sprite.IsAnimating = true;

                motion.Normalize();

                sprite.Position += motion * sprite.Speed;
                sprite.LockToMap();

                if (player.Camera.CameraMode == CameraMode.Follow)
                {
                    player.Camera.LockToSprite(sprite);
                }
            }
            else
            {
                sprite.IsAnimating = false;
            }

            if (InputHandler.KeyReleased(Keys.F) ||
                InputHandler.ButtonReleased(Buttons.RightStick, PlayerIndex.One))
            {
                player.Camera.ToggleCameraMode();

                if (player.Camera.CameraMode == CameraMode.Follow)
                {
                    player.Camera.LockToSprite(sprite);
                }
            }

            if (player.Camera.CameraMode != CameraMode.Follow)
            {
                if (InputHandler.KeyReleased(Keys.C) ||
                    InputHandler.ButtonReleased(Buttons.LeftStick, PlayerIndex.One))
                {
                    player.Camera.LockToSprite(sprite);
                }
            }

            base.Update(gameTime);
        }
Пример #21
0
	//This is where we'll check for inputs for all players
	void Update()
	{
		#if !UNITY_EDITOR_OSX
		GamePadState testState;
		for (int i = 0; i < 4; i++) {
			PlayerIndex getIndex = (PlayerIndex)i;
			testState = GamePad.GetState (getIndex);
			if(testState.IsConnected){
				prevState [i] = states [i];
				states [i] = GamePad.GetState (getIndex);
			}
		}
		#endif
		//Only check if a button is actually being pressed or released
		if(ButtonPressed!=null)
			for (int i = 0; i < 4; i++) {
			//xInput section
			#if !UNITY_EDITOR_OSX
				PlayerIndex getIndex = (PlayerIndex)i;
				testState = GamePad.GetState (getIndex);
			if (testState.IsConnected) {
				if (prevState [i].Buttons.A == ButtonState.Released && states [i].Buttons.A == ButtonState.Pressed) {
					InputHandler.ButtonPressed (i, InputHandler.Buttons.a);
				}
				if (prevState [i].Buttons.B == ButtonState.Released && states [i].Buttons.B == ButtonState.Pressed) {
					InputHandler.ButtonPressed (i, InputHandler.Buttons.b);
				}
				if (prevState [i].Buttons.X == ButtonState.Released && states [i].Buttons.X == ButtonState.Pressed) {
					InputHandler.ButtonPressed (i, InputHandler.Buttons.x);
				}
				if (prevState [i].Buttons.Y == ButtonState.Released && states [i].Buttons.Y == ButtonState.Pressed) {
					InputHandler.ButtonPressed (i, InputHandler.Buttons.y);
				}
			} else {
			#else
				//Normal joystick support (only 1 player currently)
				if(i==0){
					if(Input.GetKeyDown(KeyCode.JoystickButton16)){
						InputHandler.ButtonPressed (i, InputHandler.Buttons.a);
					}
					if(Input.GetKeyDown(KeyCode.JoystickButton17)){
						InputHandler.ButtonPressed (i, InputHandler.Buttons.b);
					}
					if(Input.GetKeyDown(KeyCode.JoystickButton18)){
						InputHandler.ButtonPressed (i, InputHandler.Buttons.x);
					}
					if(Input.GetKeyDown(KeyCode.JoystickButton19)){
						InputHandler.ButtonPressed (i, InputHandler.Buttons.y);
					}
				}
			#endif
				if (i == 0) {
					//Keyboard support
					if (Input.GetKeyDown ("a")) {
						InputHandler.ButtonPressed (i, InputHandler.Buttons.x);
					}
					if (Input.GetKeyDown ("s")) {
						InputHandler.ButtonPressed (i, InputHandler.Buttons.a);
					}
					if (Input.GetKeyDown ("d")) {
						InputHandler.ButtonPressed (i, InputHandler.Buttons.b);
					}
					if (Input.GetKeyDown ("w")) {
						InputHandler.ButtonPressed (i, InputHandler.Buttons.y);
					}
				} else if (i == 1) {
					if (Input.GetKeyDown ("f")) {
						InputHandler.ButtonPressed (i, InputHandler.Buttons.x);
					}
					if (Input.GetKeyDown ("g")) {
						InputHandler.ButtonPressed (i, InputHandler.Buttons.a);
					}
					if (Input.GetKeyDown ("h")) {
						InputHandler.ButtonPressed (i, InputHandler.Buttons.b);
					}
					if (Input.GetKeyDown ("t")) {
						InputHandler.ButtonPressed (i, InputHandler.Buttons.y);
					}
				} else if (i == 2) {
					if (Input.GetKeyDown ("j")) {
						InputHandler.ButtonPressed (i, InputHandler.Buttons.x);
					}
					if (Input.GetKeyDown ("k")) {
						InputHandler.ButtonPressed (i, InputHandler.Buttons.a);
					}
					if (Input.GetKeyDown ("l")) {
						InputHandler.ButtonPressed (i, InputHandler.Buttons.b);
					}
					if (Input.GetKeyDown ("i")) {
						InputHandler.ButtonPressed (i, InputHandler.Buttons.y);
					}
				} else {
					if (Input.GetKeyDown (KeyCode.Keypad4)) {
						InputHandler.ButtonPressed (i, InputHandler.Buttons.x);
					}
					if (Input.GetKeyDown (KeyCode.Keypad5)) {
						InputHandler.ButtonPressed (i, InputHandler.Buttons.a);
					}
					if (Input.GetKeyDown (KeyCode.Keypad6)) {
						InputHandler.ButtonPressed (i, InputHandler.Buttons.b);
					}
					if (Input.GetKeyDown (KeyCode.Keypad8)) {
						InputHandler.ButtonPressed (i, InputHandler.Buttons.y);
					}
				}
			#if !UNITY_EDITOR_OSX
			}
			#endif
		}
		if(ButtonReleased!=null)
			for (int i = 0; i < 4; i++) {
				//xInput section
				#if !UNITY_EDITOR_OSX
				PlayerIndex getIndex = (PlayerIndex)i;
				testState = GamePad.GetState (getIndex);
				if (testState.IsConnected) {
					if(prevState [i].Buttons.A == ButtonState.Pressed && states [i].Buttons.A == ButtonState.Released) {
						InputHandler.ButtonReleased (i, InputHandler.Buttons.a);
					}
					if(prevState [i].Buttons.B == ButtonState.Pressed && states [i].Buttons.B == ButtonState.Released) {
						InputHandler.ButtonReleased (i, InputHandler.Buttons.b);
					}
					if(prevState [i].Buttons.X == ButtonState.Pressed && states [i].Buttons.X == ButtonState.Released) {
						InputHandler.ButtonReleased (i, InputHandler.Buttons.x);
					}
					if(prevState [i].Buttons.Y == ButtonState.Pressed && states [i].Buttons.Y == ButtonState.Released) {
						InputHandler.ButtonReleased (i, InputHandler.Buttons.y);
					}
				} else {
				#else
				//Normal joystick support (only 1 player currently)
				if(i==0){
					if(Input.GetKeyUp(KeyCode.JoystickButton16)){
						InputHandler.ButtonReleased (i, InputHandler.Buttons.a);
					}
					if(Input.GetKeyUp(KeyCode.JoystickButton17)){
						InputHandler.ButtonReleased (i, InputHandler.Buttons.b);
					}
					if(Input.GetKeyUp(KeyCode.JoystickButton18)){
						InputHandler.ButtonReleased (i, InputHandler.Buttons.x);
					}
					if(Input.GetKeyUp(KeyCode.JoystickButton19)){
						InputHandler.ButtonReleased (i, InputHandler.Buttons.y);
					}
				}
				#endif
					if (i == 0) {
						//Keyboard support
						if (Input.GetKeyUp ("a")) {
							InputHandler.ButtonReleased (i, InputHandler.Buttons.x);
						}
						if (Input.GetKeyUp ("s")) {
							InputHandler.ButtonReleased (i, InputHandler.Buttons.a);
						}
						if (Input.GetKeyUp ("d")) {
							InputHandler.ButtonReleased (i, InputHandler.Buttons.b);
						}
						if (Input.GetKeyUp ("w")) {
							InputHandler.ButtonReleased (i, InputHandler.Buttons.y);
						}
					} else if (i == 1) {
						if (Input.GetKeyUp ("f")) {
							InputHandler.ButtonReleased (i, InputHandler.Buttons.x);
						}
						if (Input.GetKeyUp ("g")) {
							InputHandler.ButtonReleased (i, InputHandler.Buttons.a);
						}
						if (Input.GetKeyUp ("h")) {
							InputHandler.ButtonReleased (i, InputHandler.Buttons.b);
						}
						if (Input.GetKeyUp ("t")) {
							InputHandler.ButtonReleased (i, InputHandler.Buttons.y);
						}
					} else if (i == 2) {
						if (Input.GetKeyUp ("j")) {
							InputHandler.ButtonReleased (i, InputHandler.Buttons.x);
						}
						if (Input.GetKeyUp ("k")) {
							InputHandler.ButtonReleased (i, InputHandler.Buttons.a);
						}
						if (Input.GetKeyUp ("l")) {
							InputHandler.ButtonReleased (i, InputHandler.Buttons.b);
						}
						if (Input.GetKeyUp ("i")) {
							InputHandler.ButtonReleased (i, InputHandler.Buttons.y);
						}
					} else {
						if (Input.GetKeyUp (KeyCode.Keypad4)) {
							InputHandler.ButtonReleased (i, InputHandler.Buttons.x);
						}
						if (Input.GetKeyUp (KeyCode.Keypad5)) {
							InputHandler.ButtonReleased (i, InputHandler.Buttons.a);
						}
						if (Input.GetKeyUp (KeyCode.Keypad6)) {
							InputHandler.ButtonReleased (i, InputHandler.Buttons.b);
						}
						if (Input.GetKeyUp (KeyCode.Keypad8)) {
							InputHandler.ButtonReleased (i, InputHandler.Buttons.y);
						}
					}
					#if !UNITY_EDITOR_OSX
				}
					#endif
			}
	}
Пример #22
0
        public override void Update(GameTime gameTime)
        {
            world.Update(gameTime);
            player.Update(gameTime);
            player.Camera.LockToSprite(player.Sprite);

            if (InputHandler.KeyReleased(Keys.Space) ||
                InputHandler.ButtonReleased(Buttons.A, PlayerIndex.One))
            {
                foreach (ILayer layer in World.Levels[World.CurrentLevel].Map.Layers)
                {
                    if (layer is CharacterLayer)
                    {
                        foreach (Character c in ((CharacterLayer)layer).Characters.Values)
                        {
                            float distance = Vector2.Distance(
                                player.Sprite.Center,
                                c.Sprite.Center);

                            if (distance < Character.SpeakingRadius && c is NonPlayerCharacter)
                            {
                                NonPlayerCharacter npc = (NonPlayerCharacter)c;

                                if (npc.HasConversation)
                                {
                                    StateManager.PushState(GameRef.ConversationScreen);

                                    GameRef.ConversationScreen.SetConversation(
                                        player,
                                        npc,
                                        npc.CurrentConversation);

                                    GameRef.ConversationScreen.StartConversation();
                                }
                            }
                            else if (distance < Character.SpeakingRadius && c is Merchant)
                            {
                                StateManager.PushState(GameRef.ShopScreen);
                                GameRef.ShopScreen.SetMerchant(c as Merchant);
                            }
                        }
                    }
                }
            }

            MobLayer mobLayer = World.Levels[World.CurrentLevel].Map.Layers.Find(x => x is MobLayer) as MobLayer;

            foreach (var mob in mobLayer.Mobs.Where(kv => kv.Value.Entity.Health.CurrentValue <= 0).ToList())
            {
                mobLayer.Mobs.Remove(mob.Key);
            }

            foreach (Rectangle r in mobLayer.Mobs.Keys)
            {
                float distance = Vector2.Distance(mobLayer.Mobs[r].Sprite.Center, player.Sprite.Center);

                if (distance < Mob.AttackRadius)
                {
                    GameRef.CombatScreen.SetMob(mobLayer.Mobs[r]);

                    StateManager.PushState(GameRef.CombatScreen);
                    Visible = true;
                }
            }

            if (InputHandler.KeyReleased(Keys.I))
            {
                StateManager.PushState(GameRef.InventoryScreen);
            }

            base.Update(gameTime);
        }
Пример #23
0
        /* This function handles all input while the ListBox is active. */
        public override void HandleInput(PlayerIndex playerIndex)
        {
            /* If focus is not on the ListBox, it does not need to receive input, so the function returns. */
            if (!HasFocus)
            {
                return;
            }

            /* If the user releases the down arrow, or the left thumbstick is pushed down on a gamepad, the selection needs to move down. */
            if (InputHandler.KeyReleased(Keys.Down) || InputHandler.ButtonReleased(Buttons.LeftThumbstickDown, playerIndex))
            {
                /* This condition checks if the selected item isn't at the end of the list.
                 * The ListBox selection does not wrap around - it just won't do anything if you try to move outside the list. */
                if (selectedIndex < items.Count - 1)
                {
                    /* In this case, the selectedIndex is increased by one.
                     * If the selectedIndex is bigger than the startItem plus the lineCount,
                     * then the index is beyond the end of the list and the startItem needs to be changed accordingly. */
                    selectedIndex++;
                    if (selectedIndex >= startItem + lineCount)
                    {
                        startItem = selectedIndex - lineCount + 1;
                    }

                    /* Since the selection has been changed, the OnSelectionChanged() event handler function is called. */
                    OnSelectionChanged(null);
                }
            }

            /* Similarly, if the up arrow is released, or the left thumbstick is pushed up on a gamepad, the selection needs to move up. */
            else if (InputHandler.KeyReleased(Keys.Up) || InputHandler.ButtonReleased(Buttons.LeftThumbstickUp, playerIndex))
            {
                /* If the selected item isn't at the beginning of the list, then this block executes. */
                if (selectedIndex > 0)
                {
                    /* The selectedIndex is decremented, and if the selectedIndex is smaller than the startItem,
                     * the startItem is not set correctly, and it is changed to be the same as the selectedIndex. */
                    selectedIndex--;
                    if (selectedIndex < startItem)
                    {
                        startItem = selectedIndex;
                    }

                    /* The selection has been changed, so OnSelectionChanged() is called. */
                    OnSelectionChanged(null);
                }
            }

            /* If the enter key or A button is pressed, the user is confirmng their selection and HasFocus is set to false.
             * Since the property is being set to false, this also fires the OnLeave() event handler.
             * The parent OnSelected() event is also triggered. */
            if (InputHandler.KeyPressed(Keys.Enter) || InputHandler.ButtonReleased(Buttons.A, playerIndex))
            {
                HasFocus = false;
                OnSelected(null);
            }

            /* Finally, to escape from the list, the user can release the backspace key or B button.
             * If this happens, HasFocus is set to false, which calls OnLeave(). */
            if (InputHandler.KeyReleased(Keys.Back) || InputHandler.ButtonReleased(Buttons.B, playerIndex))
            {
                HasFocus = false;
            }
        }