Initial Import
[glAntsMech.git] / octanemech / src / example / MechKeys.hs
blobb8b05645b957ee89e456198d26e1770f4136bbbb
1 ----------------------------------------
2 {- Module : Basic Keyboard Actions
3 Copyright : BSD License
4 License :
5 Maintainer : Berlin Brown
6 Stability :
7 Portability :
8 Description : Basic Keyboard Actions
9 TODO :
10 Date : 9/20/2007
12 ----------------------------------------
14 module MechKeys (mechKeyboardHandler) where
16 import Graphics.UI.GLUT
17 import System.Exit ( exitWith, ExitCode(..) )
19 import MatrixUtils
20 import BasicMechs
22 import Debug.Trace ( trace )
25 -- Mech Keyboard Action
26 -- mechKeyboardAct :: Map.Map k a -> Key -> KeyState -> SimplePlayer
27 mechKeyboardAct mech (SpecialKey KeyLeft) Down = mech{posX = (posX mech) - ssize}
28 mechKeyboardAct mech (SpecialKey KeyRight) Down = mech{posX = (posX mech) + ssize}
29 mechKeyboardAct mech (SpecialKey KeyUp) Down = mech{posY = (posY mech) + ssize}
30 mechKeyboardAct mech (SpecialKey KeyDown) Down = mech{posY = (posY mech) - ssize}
32 mechKeyboardAct mech (Char 'w') Down = mech
33 mechKeyboardAct mech (Char 'a') Down = mech
34 mechKeyboardAct mech (Char 's') Down = mech
35 mechKeyboardAct mech (Char 'd') Down = mech
37 mechKeyboardAct mech (Char '\27') Down = escapeKeyHandler mech
38 mechKeyboardAct mech _ _ = mech
41 -- Debug trace escape key handler
42 escapeKeyHandler :: SimplePlayer -> SimplePlayer
43 escapeKeyHandler mechRef =
44 trace ("INFO: exiting")
45 mechRef
48 -- Mech Keyboard Handler, given the mech object reference and the
49 -- [ key, state, modifiers, and keyboard pos ]
50 mechKeyboardHandler mechRef key state modifiers position = do
51 mech <- get mechRef
52 mechRef $= mechKeyboardAct mech key state