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
// HELPER FUNCTIONS | |
const has = (entity, components) => { | |
const exists = (x) => typeof x !== "undefined"; | |
return components.map((component) => exists(entity[component])) | |
.reduce((x,y) => x && y); | |
}; | |
const clone = (object) => { | |
if (object === null || typeof object !== 'object'){ | |
return object; |
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
class Point { | |
final num x; | |
final num y; | |
const Point(this.x, this.y); | |
Point operator + (Point p) { | |
return new Point(p.x + x, p.y + y); | |
} | |
Point scale(num factor){ | |
return new Point(x * factor, y * factor); | |
} |
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 DEFINITIONS ----- | |
---------------------------- | |
Entity : Object | |
Component : Object | |
DeltaTime : Component | |
deltaTime : Number |
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
import List (..) | |
import Text (asText) | |
import Graphics.Collage (..) | |
import Graphics.Element (..) | |
import Color (..) | |
--Based on http://www.redblobgames.com/grids/hexagons/ | |
type alias Point = { | |
x : Int, |
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
import Engine (..) | |
import Engine.Material.Material (MaterialProperty) | |
import Math.Vector3 (vec3, Vec3) | |
import Engine.Shader.GouraudShader (gouraudShader) | |
import Time (..) | |
import Signal (..) | |
import Keyboard | |
import Window |
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
import List (..) | |
import Random (..) | |
import Text (asText) | |
shuffle : List a -> List a | |
shuffle lt = | |
let len = length lt | |
fgen = float 0 1 | |
lgen = list len fgen | |
rlist = fst <| generate lgen (initialSeed 31415) |
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
loop : a -> (a -> Bool) -> (a -> a) -> (a -> b) -> b | |
loop start condition update return = | |
trampoline <| | |
loop' start condition update return | |
loop' : a -> (a -> Bool) -> (a -> a) -> (a -> b) -> Trampoline b | |
loop' start condition update return = | |
case condition start of | |
True -> Done (return start) |
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
import Array (..) | |
import Text (asText) | |
import Graphics.Collage (..) | |
import Color (..) | |
drawBox box = | |
move (box.horizontal.low + boxHalfWidth box, box.vertical.low + boxHalfHeight box) <| | |
outlined (solid black) <| | |
rect (boxWidth box) (boxHeight box) |
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
mapAll : (a -> a -> a) -> Array a -> Array (Array a) | |
mapAll f array = | |
let innerMap tempArray = | |
case head tempArray of | |
Nothing -> empty | |
Just x -> push (map (f x) array) (innerMap (rest tempArray)) | |
in | |
innerMap array |
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
interface Numerical a = { | |
(+) : a -> a -> a, | |
(-) : a -> a -> a, | |
(*) : a -> a -> a, | |
negate : a -> a, | |
abs : a -> a | |
} | |
implementation Numerical Float = { | |
(+) = Native.Float.add, |