Answers for "Javascript pong game"

1

pong game using sketch files in js

// define initial player score
var playerLeft = playerRight = 0

// create text for the score, set font properties
var scoreLeft = draw.text(playerLeft+'').font({
  size: 32,
  family: 'Menlo, sans-serif',
  anchor: 'end',
  fill: '#fff'
}).move(width/2-10, 10)

// cloning rocks!
var scoreRight = scoreLeft.clone()
  .text(playerRight+'')
  .font('anchor', 'start')
  .x(width/2+10)
Posted by: Guest on June-05-2020
0

Javascript pong game

// You will need Html, css and sketch.js for this game.
// This is the sketch.js code for pong game.
// Do this in the p5.js 
// You will get HTML and CSS code there, it will be already coded there for you you just have to write the js code.

let xpos = 200
let ypos = 200
let dx = 5;
let dy = 3;
function setup() {
  createCanvas(400, 400);
}

function draw() {
  background('blue');
  rect(10,ypos,10,80);
  rect(380,mouseY,10,80);
  ellipse(xpos,ypos,20,20);
  if (xpos>=width-20 || xpos==20)
    {
      dx = -dx
    }
  if (ypos>=height-20 || ypos==20)
    {
      dy = -dy
    }
  fill('black')
  text('PONG GAME',163,20);
  for (var i=0; i< 400; i+=20) {
    line(200,i,200,i+10);
  }
  xpos = xpos + dx;
  ypos = ypos + dy;
}
Posted by: Guest on January-27-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language