Open Code
×
function level1(){ DRAW.clearRect(0,0,myCanvas.width,myCanvas.height); line(100,50,100,100);line(200,50,200,100); line(50,100,100,150);line(100,150,200,150);line(200,150,250,100); //use the line(), rect(), and circle() methods to draw stuff. How about a stick figure? } function level2(){ var playerX = 0; var playerY = 0; document.addEventListener('keydown',function(event){ if(event.keyCode===65||event.keyCode===37) playerX-=3; if(event.keyCode===87||event.keyCode===38) playerY-=3; if(event.keyCode===83||event.keyCode===40) playerY+=3; if(event.keyCode===68||event.keyCode===39) playerX+=3; }); setInterval(function(){ DRAW.clearRect(0,0,myCanvas.width,myCanvas.height); circle(playerX,playerY,40); },20); } function level3(){ var player = { x:0, y:0, controls:[false,false,false,false], draw:function(){circle(player.x,player.y,40);}, update:function(){ if(player.controls[0]) player.x--; if(player.controls[1]) player.y--; if(player.controls[2]) player.y++; if(player.controls[3]) player.x++; }, } function drawScene(){ DRAW.clearRect(0,0,myCanvas.width,myCanvas.height); player.draw(); requestAnimationFrame(drawScene); } function updateGame(){ player.update(); } document.addEventListener('keydown',function(event){ if(event.keyCode===65||event.keyCode===37) player.controls[0] = true; if(event.keyCode===87||event.keyCode===38) player.controls[1] = true; if(event.keyCode===83||event.keyCode===40) player.controls[2] = true; if(event.keyCode===68||event.keyCode===39) player.controls[3] = true; }); document.addEventListener('keyup',function(event){ if(event.keyCode===65||event.keyCode===37) player.controls[0] = false; if(event.keyCode===87||event.keyCode===38) player.controls[1] = false; if(event.keyCode===83||event.keyCode===40) player.controls[2] = false; if(event.keyCode===68||event.keyCode===39) player.controls[3] = false; }); setInterval(updateGame,20); drawScene(); }