Skip to content

Instantly share code, notes, and snippets.

@andy-morris
Created September 28, 2013 18:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andy-morris/6744763 to your computer and use it in GitHub Desktop.
Save andy-morris/6744763 to your computer and use it in GitHub Desktop.
gloss stuff
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