javascript pong game

Solutions on MaxInterview for javascript pong game by the best coders in the world

showing results for - "javascript pong game"
Simone
30 May 2017
1// define initial player score
2var playerLeft = playerRight = 0
3
4// create text for the score, set font properties
5var scoreLeft = draw.text(playerLeft+'').font({
6  size: 32,
7  family: 'Menlo, sans-serif',
8  anchor: 'end',
9  fill: '#fff'
10}).move(width/2-10, 10)
11
12// cloning rocks!
13var scoreRight = scoreLeft.clone()
14  .text(playerRight+'')
15  .font('anchor', 'start')
16  .x(width/2+10)
Olivia
24 Jun 2018
1// You will need Html, css and sketch.js for this game.
2// This is the sketch.js code for pong game.
3// Do this in the p5.js 
4// You will get HTML and CSS code there, it will be already coded there for you you just have to write the js code.
5
6let xpos = 200
7let ypos = 200
8let dx = 5;
9let dy = 3;
10function setup() {
11  createCanvas(400, 400);
12}
13
14function draw() {
15  background('blue');
16  rect(10,ypos,10,80);
17  rect(380,mouseY,10,80);
18  ellipse(xpos,ypos,20,20);
19  if (xpos>=width-20 || xpos==20)
20    {
21      dx = -dx
22    }
23  if (ypos>=height-20 || ypos==20)
24    {
25      dy = -dy
26    }
27  fill('black')
28  text('PONG GAME',163,20);
29  for (var i=0; i< 400; i+=20) {
30    line(200,i,200,i+10);
31  }
32  xpos = xpos + dx;
33  ypos = ypos + dy;
34}