Last active
October 7, 2015 15:53
-
-
Save TheSeamau5/ec9695232ae919185f4d to your computer and use it in GitHub Desktop.
Entity Component Systems in Elm using hacks à-la elm-webgl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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