I am teaching kids about the basic and simplest way of designing and coding the Pong Game via Javascript in the p5 editor. I just have a question regarding the initial phase of designing.
The code is as follows:
function setup()
{
createCanvas(400,400);
}
function draw()
{
background('black');
rect(20,160,10,80);
rect(195,195,10,10);
rect(380,mouseY,10,80);
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.0.0/p5.min.js"></script>
The first rect function is for the computer paddle controlled by AI. The second rect function is for the ball. The third rect function is for the player paddle.
I am using mouseY for the vertical movement but the paddle is going out of the canvas of dimension 400*400 towards the lower part of the canvas.
Without using any function and via simple addition/subtraction of the various numerical coordinates involved in this code, how can I prevent the player paddle from moving out of the canvas?