Last active
August 29, 2015 14:24
-
-
Save phi16/f13f6f7459dd1a9c3866 to your computer and use it in GitHub Desktop.
State Transition
This file contains 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
var W = World(function(transit){ | |
var Title; | |
var Game; | |
Title = function(){ | |
var h = {}; | |
var x = 0; | |
Input.listen(function(c){ | |
if(c == Key.Enter)transit(Game(x)); | |
}); | |
h.step = function(){ | |
x++; | |
}; | |
h.draw = function(){ | |
Graphics.drawCircle(x,height/2,0xff0000); | |
}; | |
return h; | |
}; | |
Game = function(ini){return function(){ | |
var h = {}; | |
var x = ini; | |
Input.listen(function(c){ | |
if(c == Key.Escape)transit(Title); | |
}); | |
h.step = function(){ | |
x--; | |
}; | |
h.draw = function(){ | |
Graphics.drawCircle(x,height/2,0xffff00); | |
}; | |
return h; | |
};}; | |
return Title; | |
}); |
This file contains 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
World = function(init){ | |
var w = {}; | |
w.current = null; | |
function transit(h){ | |
w.current = h(); | |
Screen.step(function(){ | |
w.current.step(); | |
w.current.draw(); | |
}); | |
} | |
transit(init(transit)); | |
return w; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment