Skip to content

Instantly share code, notes, and snippets.

@ssaurel
Created January 18, 2024 15:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ssaurel/a1381047c4849f76f38a99db5730231d to your computer and use it in GitHub Desktop.
Save ssaurel/a1381047c4849f76f38a99db5730231d to your computer and use it in GitHub Desktop.
Step 4 for creating a Snake on SSaurel's Blog
draw(realfps) {
this.ctx.fillStyle = "#EFEFEF";
this.ctx.fillRect(0, 0, canvas.width, canvas.height);
this.ctx.font = "20px Arial";
this.ctx.fillStyle = "black";
//this.ctx.fillText("FPS: " + realfps, 10, 30);
this.ctx.fillText("Points: " + this.points, 10, 30);
this.ctx.fillStyle = "green";
var eltw = this.eltw;
var elth = this.elth;
var marginx = this.marginx;
var marginy = this.marginy;
var ctx = this.ctx;
this.elements.forEach(function (element) {
ctx.fillRect(element.x * eltw + marginx, element.y * elth + marginy, eltw - marginx, elth - marginy);
});
this.ctx.fillStyle = "red";
ctx.fillRect(this.food.x * eltw + marginx, this.food.y * elth + marginy, eltw - marginx, elth - marginy);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment