Help me with collision detection with screen walls

you can check for the screen border with if(x<size)............ and if (x>width-size)................

see How do I get my shapes to move/animate around the canvas on p5.js?