Skip to content

Instantly share code, notes, and snippets.

@TheSeamau5
Last active August 29, 2015 14:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TheSeamau5/a73eec1aaf7b54cad437 to your computer and use it in GitHub Desktop.
Save TheSeamau5/a73eec1aaf7b54cad437 to your computer and use it in GitHub Desktop.
type alias Entity = {
position : Vector,
velocity : Vector,
scale : Vector,
...
}
type alias World = List Entity
type alias ComponentCreator = Entity -> Entity
-- Actions need to also take the world as input
-- Consider collision detection for example
-- Collision depends on all other collider entities
type alias Action = Entity -> World -> Entity
position : Float -> Float -> ComponentCreator
position x y entity =
{entity | position <- Just (Vector x y)
...
moveEntity : Action
moveEntity entity _ =
case (entity.position, entity.velocity) of
(Just pos, Just vel) ->
entity |> position (pos.x + vel.x) (pos.y + vel.y)
_ -> entity
resolveCollision : Action
resolveCollision entity world =
let collidingEntities = filter (collide entity) world
in
case collidingEntities of
[] -> entity
x :: xs -> resolveCollision (resolve entity x) xs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment