JSFiddle - React, Tailwind, and code Playground
by PiereDome
HTML
<canvas id='canvas'></canvas>
JavaScript
//Pong game test
var Paddle = function(gameHeight) {
var y = gameHeight / 2;
this.state = false;
this.getHeight = function() {
alert(y);
};
this.update = function(ctx) {
if (this.state != true) {
ctx.fillRect(10, y, 5, 5);
}
};
this.moveUp = function() {
y -= 1;
};
this.moveDown = function() {
y += 1;
};
};
var Ball = function() {
this.x;
this.y;
this.velX;
this.velY;
this.touchingWall();
this.touchingPaddle();
};
var Game = function() {
this.start();
this.score();
this.update();
this.end();
this.getKeypress();
};
canvas = document.getElementById('canvas');
ctx = canvas.getContext('2d');
paddle1 = new Paddle(canvas.height);
paddle1.update(ctx);
paddle1.moveUp();
paddle1.update(ctx);