Skip to content

Instantly share code, notes, and snippets.

@TheSeamau5
Last active October 7, 2015 15:53
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TheSeamau5/ec9695232ae919185f4d to your computer and use it in GitHub Desktop.
Save TheSeamau5/ec9695232ae919185f4d to your computer and use it in GitHub Desktop.
Entity Component Systems in Elm using hacks à-la elm-webgl
type Entity entity = Entity
type Component = Component
get : String -> Entity -> Maybe Component
get = ECS.Native.get
update : String -> a -> Entity -> Entity
update = ECS.Native.update
entity : (record -> entity) -> (entity -> record) -> record -> Entity entity
entity = ECS.Native.entity
-- Trying to create a mario entity from the mario record
-- The mario Record
marioRecord = {
position = { x = 0, y = 0 },
velocity = { x = 0, y = 0 },
mass = 20,
isAlive = True,
controllable = True
}
-- Mario
mario = ...
move : Entity -> Entity
move entity =
case (get "position" entity, get "velocity" entity) of
-- The following will probably not unify
(Just position, Just velocity) ->
update "position" (position + velocity) entity
_ -> entity
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment