Skip to content

Commit

Permalink
game freezes when player dead
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisPritchard committed May 3, 2019
1 parent 3870504 commit 043529e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
13 changes: 7 additions & 6 deletions samples/space-invaders-clone/Player.fs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ let update message model =
let pos = model.x + playerWidth / 2, resHeight - (playerHeight + padding) - projectileHeight - 1
{ model with laser = Some pos }

let view model dispatch =
let view model dispatch freeze =
match model.state with
| Alive ->
[
Expand All @@ -49,12 +49,13 @@ let view model dispatch =
| Some (x, y) ->
yield colour Colour.White (projectileWidth, projectileHeight) (x, y)
| _ ->
yield onkeydown Keys.Space (fun () -> dispatch Shoot)
if not freeze then yield onkeydown Keys.Space (fun () -> dispatch Shoot)

yield whilekeydown Keys.Left (fun () -> dispatch (Move -1))
yield whilekeydown Keys.A (fun () -> dispatch (Move -1))
yield whilekeydown Keys.Right (fun () -> dispatch (Move 1))
yield whilekeydown Keys.D (fun () -> dispatch (Move 1))
if not freeze then
yield whilekeydown Keys.Left (fun () -> dispatch (Move -1))
yield whilekeydown Keys.A (fun () -> dispatch (Move -1))
yield whilekeydown Keys.Right (fun () -> dispatch (Move 1))
yield whilekeydown Keys.D (fun () -> dispatch (Move 1))
]
| Dying _ ->
[
Expand Down
2 changes: 1 addition & 1 deletion samples/space-invaders-clone/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ let view model dispatch =
yield text "SCORE" (10, 10)
yield text (sprintf "%04i" model.score) (10, 44)

yield! Player.view model.player (PlayerMessage >> dispatch)
yield! Player.view model.player (PlayerMessage >> dispatch) model.freeze

yield! model.bunkers
|> List.map (fun r ->
Expand Down

0 comments on commit 043529e

Please sign in to comment.