Moved some stuff arround

This commit is contained in:
plane000
2018-06-17 19:48:10 +01:00
parent 6158662de5
commit 70aff3619e
3 changed files with 0 additions and 0 deletions

41
JavaScript/Pong/game.js Normal file
View File

@@ -0,0 +1,41 @@
let c = document.getElementById("canv");
let ctx = c.getContext("2d");
let playerP = {
width: 30,
height: 60,
x: 30 / 2,
y: ctx.canvas.height / 2
}
window.addEventListener("keydown", onKeyDown, false);
function onKeyDown(event) {
switch (event.key) {
case 'W':
case 'w':
playerP.y++;
break;
case 'S':
case 's':
playerP.x--;
break;
}
}
function gameLoop() {
draw();
}
function draw() {
ctx.clearRect(0, 0, ctx.canvas.width, ctx.canvas.height);
ctx.fillStyle="#FFFFFF";
ctx.fillRect(0, 0, 400, 400);
ctx.fillStyle="#FF00FF";
ctx.fillRect(playerP.x, playerP.y, playerP.w, playerP.h);
}
setInterval(gameLoop, 10);