Last active
August 29, 2015 14:12
-
-
Save TheSeamau5/a73eec1aaf7b54cad437 to your computer and use it in GitHub Desktop.
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 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