Skip to content

Instantly share code, notes, and snippets.

@phi16
Last active August 29, 2015 14:24
Show Gist options
  • Save phi16/f13f6f7459dd1a9c3866 to your computer and use it in GitHub Desktop.
Save phi16/f13f6f7459dd1a9c3866 to your computer and use it in GitHub Desktop.
State Transition
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;
});
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