Skip to content

Instantly share code, notes, and snippets.

@a60814billy
Last active December 24, 2015 12:29
Show Gist options
  • Save a60814billy/6797606 to your computer and use it in GitHub Desktop.
Save a60814billy/6797606 to your computer and use it in GitHub Desktop.
lab
// SnakeGame namespace
var SnakeGame = SnakeGame || {};
SnakeGame.fps = document.getElementById("fps");
// MenuState Object
SnakeGame.MenuState = {
index: 0,
item: ["Start" , "About"],
setup: function(){
console.log(this.item.length);
index = 0;
jaws.on_keydown(["up", "w"], function(){
SnakeGame.MenuState.index = (SnakeGame.MenuState.index-1<0)?(SnakeGame.MenuState.item.length-1):(SnakeGame.MenuState.index-1);
console.log("Keydown:up,index:"+SnakeGame.MenuState.index);
});
jaws.on_keydown(["down", "s"], function(){
SnakeGame.MenuState.index = (SnakeGame.MenuState.index+1>SnakeGame.MenuState.item.length-1)?0:(SnakeGame.MenuState.index+1);
console.log("Keydown:down,index:"+SnakeGame.MenuState.index);
});
jaws.on_keydown(["enter", "space"], function(){
jaws.switchGameState("");
});
},
update:function(){
SnakeGame.fps.innerHTML = "FPS:" + jaws.game_loop.fps;
},
draw: function (){
var canvas = jaws.context;
canvas.clearRect(0, 0, jaws.width, jaws.height);
for(var i=0,len=SnakeGame.MenuState.item.length;i<len;i++){
canvas.font = "bold 30px console";
canvas.fillStyle = (i == SnakeGame.MenuState.index)?"#f00":"#000";
canvas.fillText(this.item[i],140 , 100 + i * 60);
}
}
};
window.onload = function(){
jaws.start(SnakeGame.MenuState);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment