@@ -142,7 +142,41 @@ module Player =
142142 Velocity = Vector( 1 , 0 )
143143 }
144144 let player ' = player.Update( getEmptyPlayerEnvWithLevel level, 1 )
145- Assert.True( match player' with | PlayerEffect.Die -> true | _ -> false )
145+ Assert.True( match player' with | PlayerEffect.Die -> true | _ -> false )
146+
147+ [<Theory>]
148+ [<InlineData( EntityKind.Fish) >]
149+ [<InlineData( EntityKind.Bomb) >]
150+ let ``Colliding with enemy kills the player and enemy`` ( enemy : EntityKind ): unit =
151+ let level = createEmptyLevel 1 2
152+
153+ let engine = newEngine.ChangeLevel( level)
154+ let engine = engine |> spawnEntity enemy ( 0 , 1 )
155+
156+ let enemyPos = engine |> getEntityPos enemy 0
157+
158+ let dist = 10
159+
160+ let engine =
161+ { engine with
162+ GameEngine.Player.TopLeft = Point( enemyPos.X,
163+ enemyPos.Y - GameRules.PlayerSize.Y - dist)
164+ GameEngine.Player.Velocity = Vector( 0 , 1 ) }
165+
166+ let initialLives = engine.Player.Lives
167+ let engine = engine |> frameUpN timeZero ( dist + 1 )
168+
169+ let actualLives = engine.Player.Lives
170+
171+ Assert.Equal( initialLives - 1 , actualLives)
172+ match enemy with
173+ | EntityKind.Bomb ->
174+ Assert.Equal( 0 , engine.Bombs.Length)
175+ | EntityKind.Fish ->
176+ // Assert.Equal(0, engine.Fishes.Length)
177+ // TODO: Uncomment when fishes are implemented
178+ ()
179+ | _ -> failwith " Entity is not enemy"
146180
147181module OxygenSystem =
148182
@@ -294,15 +328,7 @@ module ScoreSystem =
294328
295329 let engine = newEngine.ChangeLevel( level)
296330 let engine = engine |> spawnEntity entity ( 1 , 0 )
297- let enemyPosX =
298- match entity with
299- | EntityKind.Bomb ->
300- engine.Bombs[ 0 ]. TopLeft.X
301- | EntityKind.Fish ->
302- engine.Fishes[ 0 ]. TopLeft.X
303- | EntityKind.StaticBonus | EntityKind.Lifebuoy | EntityKind.LifeBonus ->
304- engine.Bonuses[ 0 ]. TopLeft.X
305- | _ -> failwithf $" Cannot get points for shot %s {Enum.GetName(entity)}"
331+ let enemyPosX = engine |> getEntityPos entity 0 |> _. X
306332
307333 let engine =
308334 { engine with
@@ -354,6 +380,23 @@ module ScoreSystem =
354380 let engine = engine |> frameUpN timeZero 1
355381 let actualLives = engine.Player.Lives
356382 Assert.Equal( initialLives + 1 , actualLives)
383+
384+ [<Fact>]
385+ let ``Picking up a life bonus adds ability to the player`` (): unit =
386+ let level = createEmptyLevel 1 1
387+
388+ let engine = newEngine.ChangeLevel( level)
389+ let engine = engine |> spawnEntity EntityKind.Lifebuoy ( 0 , 0 )
390+
391+ let engine =
392+ { engine with
393+ GameEngine.Player.TopLeft = engine.Bonuses[ 0 ]. TopLeft }
394+
395+ let initialAbilities = engine.Player.Abilities.Length
396+
397+ let engine = engine |> frameUpN timeZero 1
398+ let actualAbilities = engine.Player.Abilities.Length
399+ Assert.Equal( initialAbilities + 1 , actualAbilities)
357400
358401module Geometry =
359402 open O21.Game .Engine .Geometry
0 commit comments