Forum Moderators: open
<html>
<div style='background-color:blue; height:480px; width:640px;'>
<canvas id="gameCanvas" width="640" height="480"></canvas>
</div>
<script>
var ctx=gameCanvas.getContext("2d");
var x=240, y=180, dir=90, score=0;
drawBackground();
function drawBackground(){
ctx.strokeStyle='orange';
ctx.lineWidth=40;
ctx.strokeRect(0, 0, 640, 480);
}
var gameTimer=setInterval(mainLoop, 50);
function mainloop(){
ctx.fillstyle='orange';
ctx.fillRect(x,y,9,9);
if(dir==90){x+=10;}
if(dir==180){y+=10;}
if(dir==-90){x-=10;}
if(dir==0){y-=10;}
//checkpixelcolor();
score++;
ctx.fillRect(0,0,100,20);
ctx.fillStyle='black';
ctx.font="20px Arial";
ctx.fillText("Score: "+score,2,16);
}
function checkPixelcolor(){
var col=ctx.getImagedata(x,y,1,1).data;
if(col[3]!=0){
clearInterval(gameTimer);
ctx.font="80px Arial";
ctx.fillText("Game Over!",100,250);
}
}
</script>
<html> So score++ shouldn't be in this section of the code, or it is in the wrong place in it?
So The wall game requires score++ in a Check for Hits part?
a random score of 12
This should work, but it doesn't