Last active
August 29, 2015 14:10
-
-
Save akimboyko/efa8d52e0293b441c40b to your computer and use it in GitHub Desktop.
Active Pattern sample from F#, THIS AINT A GAME by ANDREA MAGNORSKY http://www.roundcrisis.com/presentations/fsharp_this_aint_a_game/index.html#/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let (|SpaceKey|) (keyboard:KeyboardInput) = | |
keyboard.KeyPressed(Key.Space) | |
let (|Hold100ms|) (keyboard:KeyboardInput) = | |
keyboard.KeyPressedFor(Key.I, 100) | |
match DualityApp.Keyboard with | |
| SpaceKey true & Hold100ms false -> playerGo Jump | |
| SpaceKey true & Hold100ms true -> playerGo DoubleJump |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let (|LeftKey|RightKey|OtherKey|) (keyboard:KeyboardInput) = | |
if keyboard.KeyPressed(Key.Left) then LeftKey | |
elif keyboard.KeyPressed(Key.Right) then RightKey | |
else OtherKey "Hi, you pressed a key...well that is interesting :D" | |
interface ICmpUpdatable with | |
member this.OnUpdate()= | |
match DualityApp.Keyboard with | |
| LeftKey -> playerGo Left | |
| RightKey-> playerGo Right | |
| OtherKey s-> () |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment