Skip to content

Instantly share code, notes, and snippets.

@eamonnmcevoy
Created September 9, 2018 18:33
Show Gist options
  • Save eamonnmcevoy/44caa60b6e55048a2aa8b84cc4324cad to your computer and use it in GitHub Desktop.
Save eamonnmcevoy/44caa60b6e55048a2aa8b84cc4324cad to your computer and use it in GitHub Desktop.
class Snake {
constructor(position) {
this.parts = [position];
}
update() {
let updates = [];
updates.push({
point: this.head,
state: 'on'
});
return updates;
}
get head() {
return Object.assign({}, this.parts[0]);
}
}
...
const grid = new Grid(width, height, blockarea, margin, ctx);
const snake = new Snake({x:10, y:10});
const updates = snake.update();
updates.forEach(x => {
grid.setPoint(x.point, x.state);
});
grid.render();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment