Changeset 6621 for 2015/27/ohjaajat


Ignore:
Timestamp:
2015-06-30 17:54:04 (4 years ago)
Author:
sieerinn
Message:

Kamanäppäimiä voi nyt hakata villisti ja peli ei kaatua.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 2015/27/ohjaajat/TheLegendOfGabriel/TheLegendOfGabriel/TheLegendOfGabriel/TheLegendOfGabriel.cs

    r6620 r6621  
    215215        Keyboard.Listen(Key.Down, ButtonState.Down, player.Move, null, Direction.Down); 
    216216 
    217         Keyboard.Listen(Key.X, ButtonState.Pressed, delegate { if (player.ActiveItem != null) player.ActiveItem.UseKeyPressed(); }, null); 
    218         Keyboard.Listen(Key.X, ButtonState.Released, delegate { if (player.ActiveItem != null) player.ActiveItem.UseKeyReleased(); }, null); 
    219         Keyboard.Listen(Key.X, ButtonState.Down, delegate { if (player.ActiveItem != null) player.ActiveItem.UseKeyDown(); }, null); 
    220  
    221         Keyboard.Listen(Key.Z, ButtonState.Pressed, delegate { if (player.Sword != null) player.Sword.UseKeyPressed(); }, null); 
    222         Keyboard.Listen(Key.Z, ButtonState.Released, delegate { if (player.Sword != null) player.Sword.UseKeyReleased(); }, null); 
    223         Keyboard.Listen(Key.Z, ButtonState.Down, delegate { if (player.Sword != null) player.Sword.UseKeyDown(); }, null); 
     217        Keyboard.Listen(Key.X, ButtonState.Pressed, delegate { UseItem(player.ActiveItem, player.Sword, () => player.ActiveItem.UseKeyPressed()); }, null); 
     218        Keyboard.Listen(Key.X, ButtonState.Released, delegate { UseItem(player.ActiveItem, player.Sword, () => player.ActiveItem.UseKeyReleased()); }, null); 
     219        Keyboard.Listen(Key.X, ButtonState.Down, delegate { UseItem(player.ActiveItem, player.Sword, () => player.ActiveItem.UseKeyDown()); }, null); 
     220 
     221        Keyboard.Listen(Key.Z, ButtonState.Pressed, delegate { UseItem(player.Sword, player.ActiveItem, () => player.Sword.UseKeyPressed()); }, null); 
     222        Keyboard.Listen(Key.Z, ButtonState.Released, delegate { UseItem(player.Sword, player.ActiveItem, () => player.Sword.UseKeyReleased()); }, null); 
     223        Keyboard.Listen(Key.Z, ButtonState.Down, delegate { UseItem(player.Sword, player.ActiveItem, () => player.Sword.UseKeyDown()); }, null); 
    224224 
    225225        Keyboard.Listen(Key.Space, ButtonState.Pressed, delegate { player.CycleItems(); UpdateItemCycleImages(); }, null); 
    226226 
    227227        Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, null); 
     228    } 
     229 
     230    void UseItem(Item item, Item otherItem, Action action) 
     231    { 
     232        bool inUse = false; 
     233        if (otherItem != null) 
     234        { 
     235            inUse = otherItem.InUse; 
     236        } 
     237 
     238        if (item != null && !inUse) 
     239        { 
     240            action(); 
     241        } 
    228242    } 
    229243 
Note: See TracChangeset for help on using the changeset viewer.