-
Notifications
You must be signed in to change notification settings - Fork 0
/
EnemyBullet.hs
46 lines (38 loc) · 1.33 KB
/
EnemyBullet.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
{-
File : EnemyBullet.hs
Represents the enemy attacking ship's bullets that travell vertically downward
and threaten the main ship.
-}
module EnemyBullet
(
EnemyBullet(..),
mkEnemyBullet,
renderEnemyBullets,
moveY,
moveX,
render
) where
import Graphics.Gloss
import GameConstants
import Data.List
data EnemyBullet = EnemyBullet {loc ::Point} deriving (Eq, Ord, Show)
render :: EnemyBullet -> IO Picture
render bullet = do
pic <- bulletPic
return $ translate (fst (loc bullet)) (snd (loc bullet)) pic
renderEnemyBullets :: [EnemyBullet] -> [IO Picture]
renderEnemyBullets bullets = do
listOfBullets <- map render bullets
return listOfBullets
bulletPic :: IO Picture
bulletPic = loadBMP "images/models/enemy_bullet.bmp"
mkEnemyBullet :: Point -> EnemyBullet
mkEnemyBullet loc = EnemyBullet loc
moveY :: EnemyBullet -> Float -> EnemyBullet
moveY b@(EnemyBullet {loc = (x,y)}) dy = b {loc = (x, y+dy)}
moveX :: EnemyBullet -> Float -> EnemyBullet
moveX e@(EnemyBullet {loc = (x,y)}) dx = if x + dx < (-380)
then e {loc = ((-380), y)}
else if x + dx > 380
then e {loc = (380, y)}
else e {loc = (x+dx, y)}