This is an alternative site for discovering Elm packages. You may be looking for the official Elm package site instead.
1.0.0 1.0.1
Chain operations on game objects with side-effects + death
version 1.1.0
license BSD3
native-modules False
elm-version 0.17.0 <= v < 0.18.0
Tag 1.1.0
Committed At 2016-06-15 23:48:44 UTC
elm-lang/core 4.0.1 <= v < 5.0.0 4.0.5
akbiggs/elm-effects 2.0.3 <= v < 3.0.0 2.1.1

Modules

README

When updating a component in a game, frequently you will want to have some state for representing the death/destruction of the component. Game.Update offers you convenient operations for chaining together update functions that have side-effects and could kill the object, representing the alive state as Just object and the death state as Nothing.

The results that this module creates are Effects from elm-effects -- knowing how to use that library is necessary before using this one.

import Game.Update as Update exposing (Update)
import Effects exposing (Effects)

-- in your game player
type alias Model =
    { velocity : { x : Float, y : Float }
    }

type Msg
    = Jump
    | TakeDamage

type Effect
    = PlaySound String
    | SpawnDustParticles

update : Msg -> Update Model Effect
update msg model =
    case msg of
        Jump ->
            Update.returnAlive
                { model | velocity = { model.velocity | y = 2.0 } }
                |> Effects.add [ SpawnDustParticles, PlaySound "jump.wav" ]

        TakeDamage ->
            Update.returnDead
                |> Effects.add [PlaySound "death.wav"]

-- in your game world

type alias Model =
    { player : Maybe Player.Model
    }

-- in your game world update somewhere
let
    -- update the player if the player is alive
    (updatedPlayer, playerEffects) =
        Update.runOnMaybe (Player.update Player.Jump) model.player
in
    { model | player = updatedPlayer }
        |> Effects.handle handlePlayerEffect playerEffects