June 2018 Update
This commit is contained in:
parent
ba8067c3b7
commit
22f33d4004
5278 changed files with 84726 additions and 14379 deletions
22
Task/Joystick-position/Haskell/joystick-position.hs
Normal file
22
Task/Joystick-position/Haskell/joystick-position.hs
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
import qualified Graphics.UI.GLFW as GLFW -- cabal install GLFW-b
|
||||
import Graphics.Win32.Key
|
||||
import Control.Monad.RWS.Strict (liftIO)
|
||||
|
||||
main = do
|
||||
liftIO $ do
|
||||
_ <- GLFW.init
|
||||
GLFW.pollEvents
|
||||
(jxrot, jyrot) <- liftIO $ getJoystickDirections GLFW.Joystick'1
|
||||
putStrLn $ (show jxrot) ++ " " ++ (show jyrot)
|
||||
w <- getAsyncKeyState 27 -- ESC pressed?
|
||||
if (w<1) then main else do
|
||||
GLFW.terminate
|
||||
return ()
|
||||
|
||||
getJoystickDirections :: GLFW.Joystick -> IO (Double, Double)
|
||||
|
||||
getJoystickDirections js = do
|
||||
maxes <- GLFW.getJoystickAxes js
|
||||
return $ case maxes of
|
||||
(Just (x:y:_)) -> (-y, x)
|
||||
_ -> ( 0, 0)
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
10 DIM o$(5)
|
||||
20 LET xm=0: LET xx=31: REM screen limits
|
||||
30 LET ym=0: LET yx=18
|
||||
40 LET xo=16: LET yo=9: REM origin
|
||||
50 LET xc=xo: LET yc=yo
|
||||
60 PRINT AT yc,xc;" ": REM entry point for scan loop - blank cursor
|
||||
70 LET xc=xo: LET yc=yo
|
||||
80 LET t=IN 31
|
||||
90 IF t=1 OR t=5 OR t=9 OR t=17 OR t=21 OR t=25 THEN LET xc=xx: LET o$(2)="R": REM right
|
||||
100 IF t=2 OR t=6 OR t=10 OR t=18 OR t=22 OR t=26 THEN LET xc=xm: LET o$(1)="L": REM left
|
||||
110 IF t=4 OR t=5 OR t=6 OR t=20 OR t=21 OR t=22 THEN LET yc=yx: LET o$(4)="D": REM down
|
||||
120 IF t=8 OR t=9 OR t=10 OR t=24 OR t=25 OR t=26 THEN LET yc=ym: LET o$(3)="U": REM up
|
||||
130 IF t>=16 THEN LET o$(5)="F": REM fire
|
||||
140 PRINT AT 21,0;"Input:";o$
|
||||
150 PRINT AT yc,xc;"+"
|
||||
160 LET o$=" ": REM five spaces to blank output line again
|
||||
170 GO TO 60
|
||||
Loading…
Add table
Add a link
Reference in a new issue