Beispiel #1
0
 public override void Update(GameTime time)
 {
     //first handle CTRL/ALT/SHIFT keys
     if (KeyIsHeld(KeyBindings.L_CTRL) || KeyIsHeld(KeyBindings.R_CTRL))
     {
         if (KeyIsPushed(KeyBindings.UP))
         {
             MapBlock location = map.GetBlockAt(player.Location.Coordinates.X, player.Location.Coordinates.Y - 1);
             EventHandler.Instance.AddEvent(EventFactory.CreateAttackSpaceEvent(player, location));
         }
         else if (KeyIsPushed(KeyBindings.DOWN))
         {
             MapBlock location = map.GetBlockAt(player.Location.Coordinates.X, player.Location.Coordinates.Y + 1);
             EventHandler.Instance.AddEvent(EventFactory.CreateAttackSpaceEvent(player, location));
         }
         else if (KeyIsPushed(KeyBindings.LEFT))
         {
             MapBlock location = map.GetBlockAt(player.Location.Coordinates.X - 1, player.Location.Coordinates.Y);
             EventHandler.Instance.AddEvent(EventFactory.CreateAttackSpaceEvent(player, location));
         }
         else if (KeyIsPushed(KeyBindings.RIGHT))
         {
             MapBlock location = map.GetBlockAt(player.Location.Coordinates.X + 1, player.Location.Coordinates.Y);
             EventHandler.Instance.AddEvent(EventFactory.CreateAttackSpaceEvent(player, location));
         }
     }
     else if (KeyIsHeld(KeyBindings.L_SHIFT) || KeyIsHeld(KeyBindings.R_SHIFT))
     {
         if (KeyIsHeld(KeyBindings.LEFT))
         {
             EventHandler.Instance.AddEvent(EventFactory.CreateMoveEvent(player, map.GetBlockAt(player.Location.Coordinates.X - 1, player.Location.Coordinates.Y)));
         }
         else if (KeyIsHeld(KeyBindings.RIGHT))
         {
             EventHandler.Instance.AddEvent(EventFactory.CreateMoveEvent(player, map.GetBlockAt(player.Location.Coordinates.X + 1, player.Location.Coordinates.Y)));
         }
         else if (KeyIsHeld(KeyBindings.DOWN))
         {
             EventHandler.Instance.AddEvent(EventFactory.CreateMoveEvent(player, map.GetBlockAt(player.Location.Coordinates.X, player.Location.Coordinates.Y + 1)));
         }
         else if (KeyIsHeld(KeyBindings.UP))
         {
             EventHandler.Instance.AddEvent(EventFactory.CreateMoveEvent(player, map.GetBlockAt(player.Location.Coordinates.X, player.Location.Coordinates.Y - 1)));
         }
     }
     else if (KeyIsHeld(KeyBindings.L_ALT) || KeyIsHeld(KeyBindings.R_ALT))
     {
         if (KeyIsPushed(KeyBindings.UP))
         {
             MapBlock location = map.GetBlockAt(player.Location.Coordinates.X, player.Location.Coordinates.Y - 1);
             EventHandler.Instance.AddEvent(EventFactory.CreatePropInteractionEvent(location.Props[0], player));
         }
         else if (KeyIsPushed(KeyBindings.DOWN))
         {
             MapBlock location = map.GetBlockAt(player.Location.Coordinates.X, player.Location.Coordinates.Y + 1);
             EventHandler.Instance.AddEvent(EventFactory.CreatePropInteractionEvent(location.Props[0], player));
         }
         else if (KeyIsPushed(KeyBindings.LEFT))
         {
             MapBlock location = map.GetBlockAt(player.Location.Coordinates.X - 1, player.Location.Coordinates.Y);
             EventHandler.Instance.AddEvent(EventFactory.CreatePropInteractionEvent(location.Props[0], player));
         }
         else if (KeyIsPushed(KeyBindings.RIGHT))
         {
             MapBlock location = map.GetBlockAt(player.Location.Coordinates.X + 1, player.Location.Coordinates.Y);
             EventHandler.Instance.AddEvent(EventFactory.CreatePropInteractionEvent(location.Props[0], player));
         }
     }
     else if (InputHandler.Instance.IsKeyPushed(Keys.Escape))
     {
         this.Exit();
     }
     else if (InputHandler.Instance.IsKeyPushed(KeyBindings.LEFT))
     {
         EventHandler.Instance.AddEvent(EventFactory.CreateMoveEvent(player, map.GetBlockAt(player.Location.Coordinates.X - 1, player.Location.Coordinates.Y)));
     }
     else if (InputHandler.Instance.IsKeyPushed(KeyBindings.RIGHT))
     {
         EventHandler.Instance.AddEvent(EventFactory.CreateMoveEvent(player, map.GetBlockAt(player.Location.Coordinates.X + 1, player.Location.Coordinates.Y)));
     }
     else if (InputHandler.Instance.IsKeyPushed(KeyBindings.DOWN))
     {
         EventHandler.Instance.AddEvent(EventFactory.CreateMoveEvent(player, map.GetBlockAt(player.Location.Coordinates.X, player.Location.Coordinates.Y + 1)));
     }
     else if (InputHandler.Instance.IsKeyPushed(KeyBindings.UP))
     {
         EventHandler.Instance.AddEvent(EventFactory.CreateMoveEvent(player, map.GetBlockAt(player.Location.Coordinates.X, player.Location.Coordinates.Y - 1)));
     }
     else if (InputHandler.Instance.IsKeyPushed(KeyBindings.PICK_UP))
     {
         if (player.Location.HasItems)
         {
             EventHandler.Instance.AddEvent(EventFactory.CreatePickupItemEvent(player, player.Location.ItemAt(0)));
         }
     }
     else if (InputHandler.Instance.IsKeyPushed(Keys.W))
     {
         EventHandler.Instance.AddEvent(EventFactory.CreateWaitEvent(player));
     }
     else if (InputHandler.Instance.IsKeyPushed(KeyBindings.OPEN_INV))
     {
         AddState(StateFactory.CreateInventoryState());
     }
     else if (KeyIsPushed(Keys.N))
     {
         EventHandler.Instance.AddEvent(EventFactory.CreateMakeNoiseEvent(map.GetBlockAt(player.Location.Coordinates), 50));
     }
     else if (KeyIsPushed(Keys.Back))
     {
         MessageBus.Instance.AddMessage(new FillerMessage());
     }
     else if (KeyIsPushed(Keys.E))
     {
         Trace.WriteLine("Player is equipped with " + player.EquipmentIn(EquipmentTypes.MELEE_WEAPON).Name);
     }
 }
Beispiel #2
0
        public override void UpdateState(GameTime time, InputHandler input)
        {
            if (selectedIndex >= items[selectedSource].Count)
            {
                selectedIndex = (uint)items[selectedSource].Count - 1;
            }

            if (InputHandler.Instance.IsKeyPushed(KeyBindings.CLOSE_INV))
            {
                this.EndState();
            }


            if (InputHandler.Instance.IsKeyPushed(KeyBindings.UP))
            {
                if (items[selectedSource].Count > 0)
                {
                    selectedIndex = (--selectedIndex); //% (uint)items[selectedSource].Count;
                }
            }

            if (InputHandler.Instance.IsKeyPushed(KeyBindings.DOWN))
            {
                if (items[selectedSource].Count > 0)
                {
                    selectedIndex = (++selectedIndex) % (uint)items[selectedSource].Count;
                }
            }

            if (InputHandler.Instance.IsKeyPushed(KeyBindings.LEFT))
            {
                selectedSource = (--selectedSource) % NumSources;
                if (items[selectedSource].Count > 0)
                {
                    selectedIndex = (uint)Math.Min(items[selectedSource].Count, (int)selectedIndex);
                }
                else
                {
                    selectedSource = (++selectedSource) % 2;
                }
            }

            if (InputHandler.Instance.IsKeyPushed(KeyBindings.RIGHT))
            {
                selectedSource = (++selectedSource) % 2;
                if (items[selectedSource].Count > 0)
                {
                    selectedIndex = (uint)Math.Min(items[selectedSource].Count, (int)selectedIndex);
                }
                else
                {
                    selectedSource = (--selectedSource) % 2;
                }
            }

            if (InputHandler.Instance.IsKeyPushed(KeyBindings.PICK_UP))
            {
                if (items[selectedSource].Count > 0)
                {
                    itemEventDelegates[SelectedSource][ItemEvent.GrabItem]();
                    selectedIndex  = 0;
                    selectedSource = (uint)ItemSource.Player;
                }
            }

            if (InputHandler.Instance.IsKeyPushed(Keys.A))
            {
                foreach (Ability a in items[(int)selectedSource][(int)selectedIndex].Abilities.Values)
                {
                    Trace.WriteLine(a.Name + " ");
                }
            }

            if (InputHandler.Instance.IsKeyPushed(KeyBindings.DROP_ITEM))
            {
                items[(int)selectedSource][(int)selectedIndex].Abilities["Drop"].ItemAction(player);
            }

            if (InputHandler.Instance.IsKeyPushed(Keys.M))
            {
                items[(int)selectedSource][(int)selectedIndex].Abilities["First Aid"].ItemAction(player);
            }

            if (KeyIsPushed(Keys.Enter))
            {
                if (items[selectedSource].Count > 0)
                {
                    if (selectedSource == 0)
                    {
                        AddState(StateFactory.CreateItemDetailsState(items[(int)selectedSource][(int)selectedIndex]));
                    }
                    else if (selectedSource == 1)
                    {
                        EventHandler.Instance.AddEvent(EventFactory.CreatePickupItemEvent(player, items[(int)selectedSource][(int)selectedIndex]));
                    }
                }
            }
        }