-
Notifications
You must be signed in to change notification settings - Fork 0
/
GameLogic.hs
618 lines (544 loc) · 22.7 KB
/
GameLogic.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
{-# LANGUAGE RecordWildCards#-}
module GameLogic where
import GUI
import Data.Ord (comparing)
import Data.List
import Graphics.Gloss.Data.Vector
import Graphics.Gloss.Data.Picture
import Graphics.Gloss.Interface.Pure.Game
import Graphics.Gloss
import Data.Typeable
import Data.Maybe
import qualified Data.Map as Map
import Config
import Graphics.Gloss.Data.Point
type Tower = GameObject
type Enemy = GameObject
data GameObject =
Tower { name::String,
position::Point,
price::Int,
render::GameObject -> AssetLibrary->Picture,
sellCost::Int,
upgradeCost::Int,
nextUpgrade::Maybe Tower,
range::Float,
cooldown::Float,
lastShot::Float,
power::Float,
target::String,
bulletsCount::Int,
update::GameObject->Float->[GameObject]->[GameObject]} |
Enemy { name::String,
position::Point,
render::GameObject -> AssetLibrary->Picture,
path::[Point],
speed::Float,
hitpoints::Float,
maxHitpoints::Float,
power::Float,
reward::Int,
update::GameObject->Float->[GameObject]->[GameObject]} |
Bullet { name::String,
position::Point,
render::GameObject -> AssetLibrary->Picture,
speed::Float,
target::String,
power::Float,
update::GameObject->Float->[GameObject]->[GameObject]}
basicTower :: GameObject
basicTower = Tower {
name = "",
position = (0,0),
price = 5,
render = getAsset "Tower1-1",
sellCost = 5,
upgradeCost = 10,
nextUpgrade = Just basicTowerUpgrade1,
range = 200,
cooldown = 0.5,
lastShot = 0,
power = 3,
target = "",
bulletsCount = 0,
update = (basicTowerShoot basicBullet)}
basicTowerUpgrade1 :: GameObject
basicTowerUpgrade1 = Tower {
name = "",
position = (0,0),
price = 5,
render = getAsset "Tower1-2",
sellCost = 10,
upgradeCost = 20,
nextUpgrade = Just basicTowerUpgrade2,
range = 250,
cooldown = 0.3,
lastShot = 0,
power = 4,
target = "",
bulletsCount = 0,
update = (basicTowerShoot basicBullet)}
basicTowerUpgrade2 :: GameObject
basicTowerUpgrade2 = Tower {
name = "",
position = (0,0),
price = 5,
render = getAsset "Tower1-3",
sellCost = 15,
upgradeCost = 0,
nextUpgrade = Nothing,
range = 350,
cooldown = 0.2,
lastShot = 0,
power = 5,
target = "",
bulletsCount = 0,
update = (basicTowerShoot basicBullet)}
magicTower :: GameObject
magicTower = Tower {
name = "",
position = (0,0),
price = 5,
render = getAsset "Tower2-1",
sellCost = 5,
upgradeCost = 10,
nextUpgrade = Just magicTowerUpgrade1,
range = 200,
cooldown = 3,
lastShot = 0,
power = 15,
target = "",
bulletsCount = 0,
update = (basicTowerShoot magicBullet)}
magicTowerUpgrade1 :: GameObject
magicTowerUpgrade1 = Tower {
name = "",
position = (0,0),
price = 5,
render = getAsset "Tower2-2",
sellCost = 10,
upgradeCost = 20,
nextUpgrade = Just magicTowerUpgrade2,
range = 220,
cooldown = 3,
lastShot = 0,
power = 20,
target = "",
bulletsCount = 0,
update = (basicTowerShoot magicBullet)}
magicTowerUpgrade2 :: GameObject
magicTowerUpgrade2 = Tower {
name = "",
position = (0,0),
price = 5,
render = getAsset "Tower2-3",
sellCost = 20,
upgradeCost = 0,
nextUpgrade = Nothing,
range = 240,
cooldown = 0.2,
lastShot = 3,
power = 25,
target = "",
bulletsCount = 0,
update = (basicTowerShoot magicBullet)}
archerTower :: GameObject
archerTower = Tower {
name = "",
position = (0,0),
price = 5,
render = getAsset "Tower3-1",
sellCost = 5,
upgradeCost = 10,
nextUpgrade = Just archerTowerUpgrade1,
range = 250,
cooldown = 0.5,
lastShot = 0,
power = 2,
target = "",
bulletsCount = 0,
update = (basicTowerShoot archerBullet)}
archerTowerUpgrade1 :: GameObject
archerTowerUpgrade1 = Tower {
name = "",
position = (0,0),
price = 5,
render = getAsset "Tower3-2",
sellCost = 10,
upgradeCost = 20,
nextUpgrade = Just archerTowerUpgrade2,
range = 300,
cooldown = 0.3,
lastShot = 0,
power = 4,
target = "",
bulletsCount = 0,
update = (basicTowerShoot archerBullet)}
archerTowerUpgrade2 :: GameObject
archerTowerUpgrade2 = Tower {
name = "",
position = (0,0),
price = 5,
render = getAsset "Tower3-3",
sellCost = 20,
upgradeCost = 0,
nextUpgrade = Nothing,
range = 350,
cooldown = 0.2,
lastShot = 0,
power = 6,
target = "",
bulletsCount = 0,
update = (basicTowerShoot archerBullet)}
basicTowerShoot :: GameObject-> GameObject -> Float -> [GameObject] -> [GameObject]
basicTowerShoot bType t time obj = if target t /= ""
&& lastShot t <= 0
then sortBy (comparing objectsOrder) $ (bType{name = bulletName, position = position t, target = target t}):(replaceGameObject (name t) (t{lastShot = cooldown t, bulletsCount = (1 + bulletsCount t)}) obj)
else
if target t /= "" && isJust oldtarget then
replaceGameObject (name t) t{lastShot = lastShot t - time} obj
else if length newTargets /= 0 then
replaceGameObject (name t) newTower obj
else
replaceGameObject (name t) (t{target = "", lastShot = lastShot t - time}) obj
where
oldtarget = find (\x -> target t == name x) obj
newTargets = sortBy (comparing snd) $ filter (\(_, d) -> d>=0 && d<=range t) $ map (mapDistance (fst $ position t) (snd $ position t)) obj
newTower = t{target = (fst $ head newTargets), lastShot = lastShot t - time}
bulletName = name t ++ (show $ bulletsCount t) ++ target t
mapDistance :: Float -> Float -> GameObject -> (String, Float)
mapDistance x y t@Enemy{..} = (name, dist)
where
dx = x - (fst position)
dy = y - (snd position)
dist = sqrt (dx*dx + dy*dy)
mapDistance _ _ _ = ("", -1)
basicBullet :: GameObject
basicBullet = Bullet {
name = ""
,position = (0,0)
,render = getAsset "bullet1"
,speed = 100
,target = ""
,power = 1
,update = basicBulletUpdate
}
magicBullet :: GameObject
magicBullet = Bullet {
name = ""
,position = (0,0)
,render = getAsset "bullet3"
,speed = 50
,target = ""
,power = 10
,update = basicBulletUpdate
}
archerBullet :: GameObject
archerBullet = Bullet {
name = ""
,position = (0,0)
,render = getAsset "bullet2"
,speed = 150
,target = ""
,power = 1
,update = basicBulletUpdate
}
basicBulletUpdate :: GameObject -> Float -> [GameObject] -> [GameObject]
basicBulletUpdate b time objs = if isJust mB && isNothing shooted then
replaceGameObject (name b) (fromJust mB) objs
else
if isJust shooted then
replaceGameObject (name shEn) (shEn{hitpoints = hitpoints shEn - power b}) delBullet
else
delBullet
where
mB = moveBullet time b objs
shooted = (targetShooted b objs)
shEn = (fromJust shooted)
delBullet = filter ((/= name b).name) objs
targetShooted :: GameObject -> [GameObject] -> Maybe GameObject
targetShooted b@Bullet{..} objs
| isJust mTarget && dist <= Config.enemyRadius = mTarget
| otherwise = Nothing
where
(bx, by) = position
(tx, ty) = getPos $ fromJust mTarget
dx = tx - bx
dy = ty - by
dist = sqrt (dx*dx + dy*dy)
mTarget = find (\x -> target == getName x) objs
moveBullet :: Float -> GameObject -> [GameObject] -> Maybe GameObject
moveBullet delta b@Bullet{..} objs
| null target = Nothing
| otherwise = maybe Nothing (const (Just movedBullet)) mTarget
where
(bx, by) = position
(tx, ty) = getPos $ fromJust mTarget
dx = tx - bx
dy = ty - by
dist = sqrt (dx*dx + dy*dy)
dir = atan2 dy dx
movedBullet = b { position = (bx + speed * delta * cos dir, by + speed * delta * sin dir) }
mTarget = find (\x -> target == getName x) objs
getName :: GameObject -> String
getName = name
getPos :: GameObject -> Point
getPos = position
getAsset :: String -> GameObject -> AssetLibrary -> Picture
getAsset name go assets = Translate (fst $ position go) (snd $ position go) $ maybe Blank id $ Map.lookup name assets
basicEnemy :: GameObject
basicEnemy = Enemy {
name="",
position=(0,0),
render = renderBasicEnemy "enemy1",--"enemy1",
path=[],
speed=50,
hitpoints=10,
maxHitpoints=10,
power=1,
reward = 10,
update=basicEnemyUpdate
}
basicUpdatedEnemy :: GameObject
basicUpdatedEnemy = Enemy {
name="",
position=(0,0),
render = renderBasicEnemy "enemy2",--"enemy2",
path=[],
speed=80,
hitpoints=20,
maxHitpoints=20,
power=3,
reward = 15,
update=basicEnemyUpdate
}
middleEnemy :: GameObject
middleEnemy = Enemy {
name="",
position=(0,0),
render = renderBasicEnemy "enemy3",--"enemy2",
path=[],
speed=100,
hitpoints=30,
maxHitpoints=30,
power=4,
reward = 20,
update=basicEnemyUpdate
}
strongEnemy :: GameObject
strongEnemy = Enemy {
name="",
position=(0,0),
render = renderBasicEnemy "enemy4",--"enemy2",
path=[],
speed=120,
hitpoints=50,
maxHitpoints=50,
power=6,
reward = 40,
update=basicEnemyUpdate
}
renderBasicEnemy :: String -> GameObject -> AssetLibrary -> Picture
renderBasicEnemy an e@Enemy{..} assets = Translate (fst position) (snd position) pic
where
dir = -(enemyDir e) * 180 / pi
pic = Pictures $ [asset, healthBar]
asset = maybe Blank (Rotate dir) $ Map.lookup an assets
all = Color (makeColor 0 0 0 1) $ Polygon [((-Config.hpHalfWidth), (-Config.hpHalfHeight)),(Config.hpHalfWidth, (-Config.hpHalfHeight)),(Config.hpHalfWidth, Config.hpHalfHeight),((-Config.hpHalfWidth), Config.hpHalfHeight)]
ratio = hitpoints / maxHitpoints
health = Color (makeColor 1 1 1 1) $ Polygon [((-Config.hpHalfWidth) * ratio + Config.hpMargin, (-Config.hpHalfHeight) + Config.hpMargin),(Config.hpHalfWidth * ratio - Config.hpMargin, (-Config.hpHalfHeight) + Config.hpMargin),(Config.hpHalfWidth * ratio - Config.hpMargin, Config.hpHalfHeight - Config.hpMargin),((-Config.hpHalfWidth) * ratio + Config.hpMargin, Config.hpHalfHeight - Config.hpMargin)]
healthBar = Translate 0 Config.hpTranslate $ Pictures $ [ all, health ]
replace :: (a -> Bool) -> a -> [a] -> [a]
replace pred new xs = map (\x -> if pred x then new else x) xs
replaceGameObject :: String -> GameObject -> [GameObject] -> [GameObject]
replaceGameObject n obj xs = replace ((n==).name) obj xs
enemyDir :: GameObject -> Float
enemyDir Enemy{..} = dir
where
(cx, cy) = position
(nx, ny) = head path
dx = nx - cx
dy = ny - cy
dir = atan2 dy dx
enemyDir _ = 0
moveEnemy :: Float -> GameObject -> GameObject
moveEnemy delta e@Enemy{..}
| null path = e
| dist < 1 = e { position = (nx, ny), path = tail path }
| otherwise = movedEnemy
where
(cx, cy) = position
(nx, ny) = head path
dx = nx - cx
dy = ny - cy
dist = sqrt (dx*dx + dy*dy)
dir = atan2 dy dx
movedEnemy = e { position = (cx + speed * delta * cos dir, cy + speed * delta * sin dir) }
basicEnemyUpdate :: GameObject -> Float -> [GameObject] -> [GameObject]
basicEnemyUpdate e time objs = replaceGameObject (name e) newEnemy objs
where
newEnemy = moveEnemy time e
--Wave is (time to wait before starting after previous one, enemies of this wave)
type Wave = (Float, [Enemy])
data Level = Level {levelPicture::Picture, levelPath::[Point], levelWaves::[Wave]}
data GameState = GameState { level :: Level,
money :: Int,
isPaused :: Bool,
selectedTower :: String,
lives :: Float,
objects :: [GameObject],
placingTower :: Maybe GameObject,
lastIndex :: Int
}
type AssetLibrary = Map.Map String Picture
data Game = Game Point
Integer
Integer
AssetLibrary
GameState
deriving Typeable
instance GUIObject Game where
renderObject g = renderGame g
updateObject time g = updateGame time g
eventHandler event g = handleGameEvents event g
--TODO: Actually use w and h parameters (Resize level? And everything else?)
renderGame :: Game -> Picture
renderGame (Game (x, y) w h assets GameState{..}) = Translate x y
$ Pictures $ (levelP : objectsP ++ placingP)
where
levelP = levelPicture level
objectsP = map (\x -> Pictures $ ((render x x assets) : if (selectedTower == name x) then [renderSelected x] else [] )) objects
placingP = maybe [] (\x -> [render x x assets, renderSelected x]) placingTower
filledCircle :: Int -> Float -> Picture
filledCircle n r = Polygon p
where
(p, _) = foldl step ([], 0) [1..n]
step (acc, angle) _ = ((r * cos angle, r * sin angle):acc, angle + 2*pi / fromIntegral n)
renderSelected :: GameObject -> Picture
renderSelected Tower{..} = Translate (fst position) (snd position) $ Color (makeColor 1 1 1 0.5) $ filledCircle 500 range
renderSelected _ = Blank
objectsOrder :: GameObject -> Int
objectsOrder Tower{..} = 1
objectsOrder Enemy{..} = 2
objectsOrder Bullet{..} = 3
updateObjects :: Float -> [GameObject] -> [GameObject]
updateObjects time xs = foldl (\acc x -> update x x time acc) xs xs
updateGame :: Float -> Game -> Game
updateGame delta (Game (x, y) w h assets gs@GameState{..})
| isPaused = (Game (x, y) w h assets gs)
| otherwise = (Game (x, y) w h assets gs { objects = globalUpdates, level = level {levelWaves = nw}, lives = lives - livesDelta, lastIndex = newIndex, money = money + moneyDelta})
where
individualUpdates = updateObjects delta objects
(ne, nw) = updateWaves delta $ levelWaves level
lpath = map (toGameCoords (x,y) w h) (levelPath level)
newName = "Enemy" ++ show lastIndex
newIndex
| isJust ne = lastIndex + 1
| otherwise = lastIndex
afterSpawn = case ne of
Just e -> sortBy (comparing objectsOrder) $ (initEnemy e newName lpath) : individualUpdates
Nothing -> individualUpdates
(livesDelta, moneyDelta, afterDeath) = getFinishedEnemies afterSpawn
globalUpdates = afterDeath
enemyReachedEnd :: Enemy -> Bool
enemyReachedEnd Enemy{..} = null path
getFinishedEnemies :: [GameObject] -> (Float, Int, [GameObject])
getFinishedEnemies xs = foldr step (0, 0, []) xs
where
step x@Enemy{..} (d, m, es)
| hitpoints <= 0 = (d, m + reward, es)
| enemyReachedEnd x = (d + power, m, es)
| otherwise = (d, m, x:es)
step x (d, m, es) = (d, m, x:es)
initEnemy :: Enemy -> String -> [Point] -> Enemy
initEnemy e@Enemy{..} n p = e {path = p, position = head p, name = n}
updateWaves :: Float -> [Wave] -> (Maybe Enemy, [Wave])
updateWaves _ [] = (Nothing, [])
updateWaves time (w:ws) = case updateWave time w of
(Nothing, nw) -> (Nothing, nw:ws)
(Just e, (_, [])) -> (Just e, ws)
(Just e, nw) -> (Just e, nw:ws)
updateWave :: Float -> Wave -> (Maybe Enemy, Wave)
updateWave dt (spawn, e : es)
| spawn > dt = (Nothing, (spawn - dt, e:es) )
| otherwise = (Just e, (1, es) )
--TODO: Check if tower is on the path or collides with other towers
isPlacementCorrect x y w h pos gs@GameState{..} = (not $ pathCollision (map (toGameCoords (x,y) w h) (levelPath level)) pos) && (not $ towerCollision (map (position) objects) pos) && (not $ pointInBox pos ((fromIntegral w) / 2,-(fromIntegral h) / 2) (-(fromIntegral w) / 2, -300))
pathCollision (x:y:[]) p = (pointInBox p x y)
pathCollision (x:y:xs) p = (pointInBox p x y) || pathCollision (y:xs) p
towerCollision ((x,y):[]) p = (pointInBox p (x-70,y-70) (x+70, y+70))
towerCollision ((x,y):z) p = (pointInBox p (x-70,y-70) (x+70, y+70)) || towerCollision z p
towerCollision _ _ = False
distance :: Point -> Point -> Float
distance (x1, y1) (x2, y2) = let dx = x2 - x1
dy = y2 - y1 in sqrt (dx * dx + dy * dy)
gameObjectHittest :: GameObject -> Point -> Bool
gameObjectHittest t p = Config.towerRadius > distance p (position t)
isTower :: GameObject -> Bool
isTower Tower{..} = True
isTower _ = False
isEnemy :: GameObject -> Bool
isEnemy Enemy{..} = True
isEnemy _ = False
toGameCoords :: Point -> Integer -> Integer -> Point -> Point
toGameCoords (gx, gy) w h (x, y) = (x - gx, y - gy)
gameHittest :: Point -> Integer -> Integer -> Point -> Bool
gameHittest (gx, gy) w h p = pointInBox p rightBot leftTop
where
halfW = (fromIntegral w) / 2
halfH = (fromIntegral h) / 2
leftTop = (gx-halfW,gy+halfH)
rightBot = (gx+halfW, gy-halfH)
handleGameEvents :: Event -> Game -> Game
handleGameEvents (EventMotion rpos) (Game (x, y) w h assets gs@GameState{..}) = (Game (x, y) w h assets gs { placingTower = newPlacingTower })
where
mpos = toGameCoords (x, y) w h rpos
newPlacingTower = maybe Nothing (\t ->Just t {position = mpos}) placingTower
handleGameEvents (EventKey (MouseButton LeftButton) Down _ rpos) (Game (x, y) w h assets gs@GameState{..})
| gameHittest (x,y) w h rpos = (Game (x, y) w h assets gs { objects = newObjects, selectedTower = newSelectedName, placingTower = newPlacing, lastIndex = newIndex})
| otherwise = Game (x, y) w h assets gs
where
pos = toGameCoords (x, y) w h rpos
possibleSelect = maybe "" name $ find (\x -> gameObjectHittest x pos && isTower x) objects
newSelectedName = if isJust placingTower then selectedTower else possibleSelect
newName = show lastIndex
placeTower = isPlacementCorrect x y w h pos gs && isJust placingTower
newIndex
| placeTower = lastIndex + 1
| otherwise = lastIndex
newObjects
| placeTower = sortBy (comparing objectsOrder) $ ((fromJust placingTower) {name = newName}) : objects
| otherwise = objects
newPlacing
| placeTower = Nothing
| otherwise = placingTower
handleGameEvents (EventKey (MouseButton RightButton) Down _ rpos) (Game (x, y) w h assets gs@GameState{..}) = (Game (x, y) w h assets gs { placingTower = Nothing})
handleGameEvents _ g = g
setPlacingTower :: Game -> Point -> GameObject -> Game
setPlacingTower (Game (x,y) w h assets gs) pos t@Tower{..} | price <= (money gs) = ( Game (x,y) w h assets gs {placingTower = Just t {position = toGameCoords (x,y) w h pos}, selectedTower = "", money = (money gs) - price} )
setPlacingTower g _ _ = g
deleteCurrentTower :: Game -> Game
deleteCurrentTower (Game (x,y) w h assets gs@GameState{..})
|selectedTower /= "" = Game (x,y) w h assets gs { objects = (filter (\x -> (getName x) /= (selectedTower)) (objects) ) ,
money = money + sellCost ( head (filter (\x -> (getName x) == (selectedTower)) (objects))) }
| otherwise = (Game (x,y) w h assets gs)
upgradeCurrentTower::Game -> Game
upgradeCurrentTower (Game (x,y) w h assets gs@GameState{..})
| selectedTower /= "" && (isJust mselectedT) && (isJust mnewTower) && (upgradeCost selectedT) <= money = Game (x,y) w h assets gs { money = money - upgradeCost selectedT, objects = replaceGameObject selectedTower newTower objects }
| otherwise = (Game (x,y) w h assets gs)
where
mselectedT = listToMaybe $ filter ((selectedTower==).name) objects
selectedT = fromJust mselectedT
mnewTower = nextUpgrade selectedT
newTower = (fromJust mnewTower) { name = name selectedT, position = position selectedT }
wavesLeft :: Game -> Int
wavesLeft (Game (x,y) w h assets gs@GameState{..}) = length $ levelWaves level
pauseGame :: Bool -> Game -> Game
pauseGame pause (Game (x,y) w h assets gs@GameState{..}) = (Game (x,y) w h assets gs {isPaused = pause} )
data GameResult = Win | Lose | Playing
deriving (Show, Eq)
gameResult :: Game -> GameResult
gameResult (Game (x,y) w h assets gs@GameState{..})
| lives <= 0 = Lose
| null (levelWaves level) && null (filter isEnemy objects) = Win
| otherwise = Playing