Code With Examples

Snake Game Design (Part -1)

inpage-crack-softwares

<!–Level 1–>

<canvas id=”canvas” width=”500″ height=”500″ style=”background: red”></canvas>

<script>
var cvs = document.getElementById(“canvas”);
var ctx = cvs.getcontext(“2d”);
var snakew = 10;
var snakeh = 10;

function drawsnake(x, y) {
ctx.fillstyle = “white”;
ctx.fillrect(x * snakew, y * snakeh, snakew, snakeh);
}

drawsnake(10, 2);
function demox(x, y) {
ctx.fillstyle = “black”;
ctx.fillrect(x * snakew, y * snakeh, cvs.width, snakeh);
}

for (var i = 0; i <= 50; i++) {
i++;
demox(0, i);
}

function demoy(x, y) {
ctx.fillstyle = “black”;
ctx.fillrect(x * snakew, y * snakeh, snakeh, cvs.height);
}

for (var i = 0; i <= 50; i++) {
i++;
demoy(i, 0);
}

</script>

Leave a Comment