My code must make the mouse act with a joystick to direct a ball on the screen. It should work as follows: if the mouse is in the crosshairs, the ball does not move. If the mouse is to the right or to the left, the ball moves to the right or to the left. If the mouse is above or below the center, the ball moves up or down. The distance from the center mouse determines how fast the ball moves. I was able to implement the code to draw the ball and the crosshairs. But I can not get the ball to move properly. How do I use min and max functions in this case?
int ballPositionX = 250;
int ballPositionY = 250;
int ballSize = 20;
int slowerSpeed = 50;
int mouvement = 250;
int linePt1 = 100;
int linePt2 = 250;
int linePt3 = 400;
int rightLimit, leftLimit, bottomLimit, topLimit;
int moveX, moveY;
void setup(){
size(500,500);
}
void draw(){
background(255);
line(linePt1,linePt2,linePt3,linePt2);
line(linePt2,linePt1,linePt2,linePt3);
ellipse(ballPositionX, ballPositionY, ballSize, ballSize);
moveX = (mouseX - 250);
moveY = (mouseY - 250);
ballPositionX = min(ballPositionX, moveX+ballPositionY);
ballPositionY = max(ballPositionY, moveY+ballPositionX);
}