GitXplorerGitXplorer
a

elm-game-update

public
2 stars
0 forks
1 issues

Commits

List of commits on branch master.
Unverified
a9062ca6eb488a857b9e08b77e7fd65c8776f312

Version 1.1.0 - `fromEffects` function.

aakbiggs committed 9 years ago
Unverified
623f98f5cb91c5ae3bba9114bada015b9c45450a

Version 1.0.1 (minor README tweak)

aakbiggs committed 9 years ago
Unverified
cb114bab79535760d7f84c5a884bf7ff76896541

Forgot README

aakbiggs committed 9 years ago
Unverified
e2e8d595827413f2ea0e3baae97d4650e6450bc6

Version 1.0.0

aakbiggs committed 9 years ago

README

The README file for this repository.

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