-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGameLogic.hs
More file actions
45 lines (37 loc) · 1.09 KB
/
GameLogic.hs
File metadata and controls
45 lines (37 loc) · 1.09 KB
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
36
37
38
39
40
41
42
43
44
45
module GameLogic where
import Reactive.Banana
import Reactive.Banana.Frameworks
import Debug.Trace
import CalcGeom
import Time
import GameState
import Input
gameLogic :: Event t Duration -> Behavior t ArrowKeys -> Behavior t GameState
gameLogic dtE arrowKeysB = GameState <$> pos
where
accel = (vmult 500) <$> arrowKeysB
zero = (0,0) :: Pos
(_, vel) = integralVSP cols accel dtE
(_, pos) = integralVSP colp vel dtE
cols = whenE (isCollision <$> pos) ((collision <$> pos <*> vel) <@ dtE)
colp = whenE (isCollision <$> pos) ((collisionP <$> pos) <@ dtE)
isCollision (x,y) = colX || colY
where
colX | x > 1920 || x < 0 = True
| otherwise = False
colY | y > 1080 || y < 0 = True
| otherwise = False
collision (x,y) (vx, vy) = (colX, colY)
where
colX | x > 1920 || x < 0 = -vx
| otherwise = vx
colY | y > 1080 || y < 0 = -vy
| otherwise = vy
collisionP (x,y) = (colX, colY)
where
colX | x > 1920 = 1919
| x < 0 = 1
| otherwise = x
colY | y > 1080 = 1079
| y < 0 = 1
| otherwise = y