-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathStep.hs
35 lines (29 loc) · 1.14 KB
/
Step.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
module Play.Step ( step, stepPlay, stepBall ) where
import Level.Level
import Play.PlayState
import Play.Collisions
step :: Float -> PlayState -> PlayState
step dt pl =
let pl' = case docState pl of
DocShownFor t ->
pl { docState = let t' = t + dt
in if t' > 10
then DocDone
else DocShownFor t' }
DocDone -> pl
in if paused pl'
then pl'
else stepPlay dt pl'
stepPlay :: Float -> PlayState -> PlayState
stepPlay dt pl@(PlayState { level = l, balls = bs, drawnWalls = ws, drawing = dwg }) =
pl { balls = let ws' = walls l ++ case dwg of
Drawing dw -> dw:ws
NotDrawing -> ws in
map (\b -> foldr collideWB (stepBall dt b) ws') bs }
gravity :: Float
gravity = 0.03
stepBall :: Float -> Ball -> Ball
stepBall _ ball@(Ball { pos = (x, y), vel = (vx, vy), theta = t, omega = w }) =
ball { pos = (x + vx, y + vy)
, vel = (vx, vy - gravity)
, theta = t + w }