@@ -6,6 +6,7 @@ module Bullet
66 , fireFrom
77 , move
88 , impact
9+ , keepExploding
910 , isDead
1011 )
1112
@@ -16,6 +17,7 @@ import Time exposing (Time)
1617
1718type Status
1819 = Flying
20+ | Exploding Time
1921 | Impacted
2022
2123
@@ -41,6 +43,16 @@ fireTowards targetPosition bullet =
4143
4244move : Time -> Bullet -> Bullet
4345move diff bullet =
46+ case bullet. status of
47+ Flying ->
48+ moveTheBullet diff bullet
49+
50+ _ ->
51+ bullet
52+
53+
54+ moveTheBullet : Time -> Bullet -> Bullet
55+ moveTheBullet diff bullet =
4456 let
4557 distanceToNextPoint =
4658 Coordinate . distance bullet. position bullet. target
@@ -63,7 +75,20 @@ move diff bullet =
6375
6476impact : Bullet -> Bullet
6577impact bullet =
66- { bullet | status = Impacted }
78+ { bullet | status = Exploding 0 }
79+
80+
81+ keepExploding : Time -> Bullet -> Bullet
82+ keepExploding diff bullet =
83+ case bullet. status of
84+ Exploding timeSoFar ->
85+ if ceiling ( timeSoFar / explosionSpeed) > 3 then
86+ { bullet | status = Impacted }
87+ else
88+ { bullet | status = Exploding ( timeSoFar + diff) }
89+
90+ _ ->
91+ bullet
6792
6893
6994isDead : Bullet -> Bool
@@ -77,9 +102,56 @@ speedPerSecond =
77102
78103
79104toEntity : Bullet -> Entity
80- toEntity { position } =
105+ toEntity { position, status } =
106+ case status of
107+ Exploding diff ->
108+ if ceiling ( diff / explosionSpeed) == 1 then
109+ explosionPhase1 position diff
110+ else if ceiling ( diff / explosionSpeed) == 2 then
111+ explosionPhase2 position diff
112+ else
113+ explosionPhase3 position diff
114+
115+ _ ->
116+ regularBulletEntity position
117+
118+
119+ regularBulletEntity : Coordinate .Global -> Entity
120+ regularBulletEntity position =
81121 { position = position
82122 , width = 10
83123 , height = 10
84124 , imagePath = " images/cannon-ball.png"
85125 }
126+
127+
128+ explosionPhase1 : Coordinate .Global -> Time -> Entity
129+ explosionPhase1 position timeSoFar =
130+ { position = position
131+ , width = 50
132+ , height = 50
133+ , imagePath = " images/explosion1.png"
134+ }
135+
136+
137+ explosionPhase2 : Coordinate .Global -> Time -> Entity
138+ explosionPhase2 position timeSoFar =
139+ { position = position
140+ , width = 75
141+ , height = 75
142+ , imagePath = " images/explosion2.png"
143+ }
144+
145+
146+ explosionPhase3 : Coordinate .Global -> Time -> Entity
147+ explosionPhase3 position timeSoFar =
148+ { position = position
149+ , width = 50
150+ , height = 50
151+ , imagePath = " images/explosion3.png"
152+ }
153+
154+
155+ explosionSpeed : Time
156+ explosionSpeed =
157+ Time . second / 20
0 commit comments