LOADING...

Preview

Pen ID
Unlock Campus Themeforest adv

 

Code

This Game lets you move around!

Here's the test!

  1. Make the player bigger
  2. Make the player a different colour
  3. Make the player move faster
  4. Make the player move up and down
  5. make something happen when you press spacebar!
JS
document.addEventListener("keydown", press);

var cv = document.getElementById("cv");
var ctx = cv.getContext("2d");
setInterval(game, 30);

// your horizontal position
xPosition = 0;
// your vertical position
yPosition = 0;

function game() {
  // paint a white background to cover up the previous frame
  ctx.fillStyle = "white";
  ctx.fillRect(0, 0, cv.width, cv.height);

  // paint the player in its new position!
  ctx.fillStyle = "blue";
  ctx.fillRect(xPosition, yPosition, 10, 10);

}

function press(evt) {
  button = evt.keyCode;
  // move left
  if (button == 37) {
    xPosition = xPosition - 5;
  }
  // move right
  if (button == 39) {
    xPosition = xPosition + 5;
  }
  // --> do the move up!
  
  
  // --> do the move down!
  
}
Term
Sat, 01/13/2018 - 07:27

Related Codes

Pen ID
Pen ID
Pen ID
Square Adv