Created
January 18, 2024 15:34
-
-
Save ssaurel/a1381047c4849f76f38a99db5730231d to your computer and use it in GitHub Desktop.
Step 4 for creating a Snake on SSaurel's Blog
This file contains hidden or 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
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