Created
September 28, 2013 18:09
-
-
Save andy-morris/6744763 to your computer and use it in GitHub Desktop.
gloss stuff
This file contains 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
import Graphics.Gloss | |
import Graphics.Gloss.Interface.Pure.Game | |
main = play w white 60 st0 draw ev advance | |
w = InWindow "a boring game." (640,480) (30,30) | |
data State = State {s, x, y, ds, dx, dy :: Float} | |
st0 = State 10 30 30 0 0 0 | |
draw (State s x y _ _ _) = translate x y (circle s) | |
ev (EventKey k d _ _) st = | |
case k of | |
Char '+' -> st {ds = amt 0.5} | |
Char '-' -> st {ds = amt (-0.5)} | |
SpecialKey KeyUp -> st {dy = amt 1} | |
SpecialKey KeyDown -> st {dy = amt 1} | |
SpecialKey KeyRight -> st {dx = amt (-1)} | |
SpecialKey KeyLeft -> st {dx = amt 1} | |
_ -> st | |
where | |
amt i = case d of Down -> i | |
Up -> 0 | |
ev _ st = st | |
advance t st@(State s x y ds dx dy) = | |
st {ds = next s ds, dx = next x dx, y = next y dy} | |
where next a da = (60*t*da) + a |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment