I'm trying to make a Pong game using the HTML canvas element. I already animated the ball bouncing off the walls, but I'm stuck on how to add the paddle. What I want is a rectangle that's a little wider than the ball. When the user moves their mouse left or right, the paddle should move with it without them having to click anything. Here's what I have so far:

<script>
    class BouncingCanvas {
        constructor(args) {
            Object.assign(this, args);
            this.canvas = document.getElementById(this.canvas_id);
            this.ball_x = this.ball_y = this.ball_radius;

            window.requestAnimationFrame(this.draw);
        }

        checkForBounce = () => {
            if (this.ball_x + this.ball_radius >= this.canvas.width || this.ball_x - this.ball_radius <= 0) {
                this.x_movement_rate = this.x_movement_rate * -1;
            }

            if (this.ball_y + this.ball_radius >= this.canvas.height || this.ball_y - this.ball_radius <= 0) {
                this.y_movement_rate = this.y_movement_rate * -1;
            }
        }

        draw = () => {
            let ctx = this.canvas.getContext("2d");

            ctx.fillStyle = "blue";
            ctx.fillRect(0, 0, this.canvas.width, this.canvas.height);

            ctx.fillStyle = "green";
            ctx.translate(this.x_movement_rate, this.y_movement_rate);

            ctx.beginPath();
            ctx.arc(this.ball_radius, this.ball_radius, this.ball_radius, 0, 2 * Math.PI);
            ctx.fill();

            this.ball_x += this.x_movement_rate;
            this.ball_y += this.y_movement_rate;

            this.checkForBounce();

            window.requestAnimationFrame(this.draw);
        }
    }

    bc = new BouncingCanvas({'canvas_id': 'animation_canvas', 'ball_radius': 50, 'x_movement_rate': 4, 'y_movement_rate': 3});
  </script>
system
main HTML canvas tatv kaa upyog karke ek pong game banane kii koshish kar rahaa hum.main pehle se hi deevaaron se uchhalte hue gend ko anemated karata hum, lekin main pedal ko jodne ke liye kaise atak gaya hum.main jo chahta hum vah ek aayat he jo gend kii tulana main thodaa chaudaa he.jab upyogkarta apane mouse ko baayen yaa daaen le jaataa he, to pedal ko uske saath kuch bhi clic kiye bina janaa chahie.yahan mere paas ab tak he:

<script>
    class bounsingkanvas {
        constructor (args) {
            Object.Assign (yah, args);
            this.canvas = document.getElementByid (this.canvas_id);
            this.ball_x = this.ball_y = this.ball_radius;

            window.requestanimationframe (this.draw);
        }

        checkforbounce = () => {
            if (this.ball_x + this.ball_radius> = this.canvas.width || this.ball_x - this.ball_radius <= 0) {
                this.x_movement_rate = this.x_movement_rate * -1;
            }

            if (this.ball_y + this.ball_radius> = this.canvas.height || this.ball_y - this.ball_radius <= 0) {
                this.y_movement_rate = this.y_movement_rate * -1;
            }
        }

        dra = () => {
            Ctx = this.canvas.getContext ("2D") ko bataa den;

            ctx.fillstyle = "nila";
            ctx.fillrect (0, 0, this.canvas.width, this.canvas.height);

            ctx.fillstyle = "green";
            ctx.translate (this.x_movement_rate, this.y_movement_rate);

            ctx.beginpath ();
            ctx.arc (this.ball_radius, this.ball_radius, this.ball_radius, 0, 2 * math.pi);
            ctx.fill ();

            this.ball_x += this.x_movement_rate;
            this.ball_y += this.y_movement_rate;

            this.checkforbounce ();

            window.requestanimationframe (this.draw);
        }
    }

    bc = new Bouncingcanvas ({'canvas_id': 'anemeshan_canvas', 'ball_radius': 50, 'x_movement_rate': 4, 'y_movement_rate': 3});
  </script>
user
zarur!aap canvas tatv main ek event shrota ko jodakar aisa kar sakate hai jo har baar upyogkarta ke mouse kii chaal main aag lagayegaa.phir aap event se mouse kii vartmaan sthiti ko ek udhaaharan char main sangrahit kar sakate hai, or pedal ko khinchne ke liye iskaa upyog kar sakate hai.yahan code kaa nayaa sanskaran he:

  <script>
    class bounsingkanvas {
        constructor (args) {
            Object.Assign (yah, args);
            this.canvas = document.getElementByid (this.canvas_id);
            yah.

            this.ball_x = this.ball_y = this.ball_radius;

            this.paddle_width = this.ball_radius * 4;
            this.paddle_height = 40;
            this.paddle_x = this.paddle_width / 2;

            window.requestanimationframe (this.draw);
        }

        checkforbounce = () => {
            if (this.ball_x + this.ball_radius> = this.canvas.width || this.ball_x - this.ball_radius <= 0) {
                this.x_movement_rate = this.x_movement_rate * -1;
            }

            if (this.ball_y + this.ball_radius> = this.canvas.height - this.paddle_height || this.ball_y - this.ball_radius <= 0) {
                this.y_movement_rate = this.y_movement_rate * -1;
            }
        }

        dra = () => {
            Ctx = this.canvas.getContext ("2D") ko bataa den;

            // antim frem par khaali canvas prishthbhumi dra karen
            ctx.fillstyle = "nila";
            ctx.fillrect (0, 0, this.canvas.width, this.canvas.height);

            // vartmaan mouse sthaan par pedal dra karen
            ctx.beginpath ();
            ctx.moveto (0, 0);
            ctx.fillstyle = 'kaala';
            ctx.fillrect (this.paddle_x - this.paddle_width/2, this.canvas.height - this.paddle_height, this.paddle_width, this.paddle_height);

            // gend ko sthanantarit karen or phir ise khinchen
            this.ball_x += this.x_movement_rate;
            this.ball_y += this.y_movement_rate;

            ctx.beginpath ();
            ctx.moveto (0, 0);
            ctx.fillstyle = "green";
            ctx.arc (this.ball_x, this.ball_y, this.ball_radius, 0, 2 * math.pi);
            ctx.fill ();

            this.checkforbounce ();

            window.requestanimationframe (this.draw);
        }
    }

    bc = new Bouncingcanvas ({'canvas_id': 'anemeshan_canvas', 'ball_radius': 50, 'x_movement_rate': 4, 'y_movement_rate': 3});
  </script>
assistant
<|system|>
</s>
<|user|>
main HTML canvas tatv kaa upyog karke ek pong game banane kii koshish kar rahaa hum.main pehle se hi deevaaron se uchhalte hue gend ko anemated karata hum, lekin main pedal ko jodne ke liye kaise atak gaya hum.main jo chahta hum vah ek aayat he jo gend kii tulana main thodaa chaudaa he.jab upyogkarta apane mouse ko baayen yaa daaen le jaataa he, to pedal ko uske saath kuch bhi clic kiye bina janaa chahie.yahan mere paas ab tak he:

<script>
    class bounsingkanvas {
        constructor (args) {
            Object.Assign (yah, args);
            this.canvas = document.getElementByid (this.canvas_id);
            this.ball_x = this.ball_y = this.ball_radius;

            window.requestanimationframe (this.draw);
        }

        checkforbounce = () => {
            if (this.ball_x + this.ball_radius> = this.canvas.width || this.ball_x - this.ball_radius <= 0) {
                this.x_movement_rate = this.x_movement_rate * -1;
            }

            if (this.ball_y + this.ball_radius> = this.canvas.height || this.ball_y - this.ball_radius <= 0) {
                this.y_movement_rate = this.y_movement_rate * -1;
            }
        }

        dra = () => {
            Ctx = this.canvas.getContext ("2D") ko bataa den;

            ctx.fillstyle = "nila";
            ctx.fillrect (0, 0, this.canvas.width, this.canvas.height);

            ctx.fillstyle = "green";
            ctx.translate (this.x_movement_rate, this.y_movement_rate);

            ctx.beginpath ();
            ctx.arc (this.ball_radius, this.ball_radius, this.ball_radius, 0, 2 * math.pi);
            ctx.fill ();

            this.ball_x += this.x_movement_rate;
            this.ball_y += this.y_movement_rate;

            this.checkforbounce ();

            window.requestanimationframe (this.draw);
        }
    }

    bc = new Bouncingcanvas ({'canvas_id': 'anemeshan_canvas', 'ball_radius': 50, 'x_movement_rate': 4, 'y_movement_rate': 3});
  </script></s>
<|assistant|>
zarur!aap canvas tatv main ek event shrota ko jodakar aisa kar sakate hai jo har baar upyogkarta ke mouse kii chaal main aag lagayegaa.phir aap event se mouse kii vartmaan sthiti ko ek udhaaharan char main sangrahit kar sakate hai, or pedal ko khinchne ke liye iskaa upyog kar sakate hai.yahan code kaa nayaa sanskaran he:

  <script>
    class bounsingkanvas {
        constructor (args) {
            Object.Assign (yah, args);
            this.canvas = document.getElementByid (this.canvas_id);
            yah.

            this.ball_x = this.ball_y = this.ball_radius;

            this.paddle_width = this.ball_radius * 4;
            this.paddle_height = 40;
            this.paddle_x = this.paddle_width / 2;

            window.requestanimationframe (this.draw);
        }

        checkforbounce = () => {
            if (this.ball_x + this.ball_radius> = this.canvas.width || this.ball_x - this.ball_radius <= 0) {
                this.x_movement_rate = this.x_movement_rate * -1;
            }

            if (this.ball_y + this.ball_radius> = this.canvas.height - this.paddle_height || this.ball_y - this.ball_radius <= 0) {
                this.y_movement_rate = this.y_movement_rate * -1;
            }
        }

        dra = () => {
            Ctx = this.canvas.getContext ("2D") ko bataa den;

            // antim frem par khaali canvas prishthbhumi dra karen
            ctx.fillstyle = "nila";
            ctx.fillrect (0, 0, this.canvas.width, this.canvas.height);

            // vartmaan mouse sthaan par pedal dra karen
            ctx.beginpath ();
            ctx.moveto (0, 0);
            ctx.fillstyle = 'kaala';
            ctx.fillrect (this.paddle_x - this.paddle_width/2, this.canvas.height - this.paddle_height, this.paddle_width, this.paddle_height);

            // gend ko sthanantarit karen or phir ise khinchen
            this.ball_x += this.x_movement_rate;
            this.ball_y += this.y_movement_rate;

            ctx.beginpath ();
            ctx.moveto (0, 0);
            ctx.fillstyle = "green";
            ctx.arc (this.ball_x, this.ball_y, this.ball_radius, 0, 2 * math.pi);
            ctx.fill ();

            this.checkforbounce ();

            window.requestanimationframe (this.draw);
        }
    }

    bc = new Bouncingcanvas ({'canvas_id': 'anemeshan_canvas', 'ball_radius': 50, 'x_movement_rate': 4, 'y_movement_rate': 3});
  </script></s>
