Skip to content

Instantly share code, notes, and snippets.

@akimboyko
Last active August 29, 2015 14:10
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save akimboyko/efa8d52e0293b441c40b to your computer and use it in GitHub Desktop.
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#/
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
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