export default class Ball { constructor(game) { this.image = document.getElementById("imgBall"); this.gameWidth = game.gameWidth; this.gameHeight = game.gameHeight; this.position = { x: 10, y: 10, }; this.speed = { x: 5, y: 3, }; this.size = 16; } update(deltaTime) { this.position.x += this.speed.x; this.position.y += this.speed.y; if(this.position.x + this.size > this.gameWidth || this.position.x < 0) { this.speed.x = -this.speed.x; } if(this.position.y + this.size > this.gameHeight || this.position.y < 0) { this.speed.y = -this.speed.y; } } draw(context) { context.drawImage(this.image, this.position.x, this.position.y, this.size, this.size); } }