I have coded another helper program to a popular game using Robot class of Java. In this game, players are trying to score baskets in a 2d pitch by shooting the ball random positions to a basket of which position remains unchanged. The players only decide highest point of the path of the ball. By observation, it can be noticed that path of the ball is a parabola. Therefore the problem can be reduced to finding highest point of a parabolum of which two points (position of basket and initial position of ball) are known. Of course, countless different parabola can pass through two points. So setting height of highest point is also needed. Also note that basket and ball are on the separate arms of parabola.
Consequently, we have the following known values
Coordinates of basket: Px,Py
Coordinates of ball: Tx,Ty
Height of highest point: H
Parabola equation: y = a(x-X)^2 + H
We need to find axis of highest point: X
Since we know that basket and position are on the parabola, we have following two equations:
1: Py=a(Px-X)^2 + H
2: Ty=a(Tx-X)^2 + H
Find value of a from 1 and 2, these values will also be equal:
Py–H / (Px-X)^2 = Ty-H / (Tx-X)^2
Py – H / Ty – H = (Px – X)^2 / (Tx – X)^2
(Py – H / Ty – H)^1/2 = |Px – X| / |Tx – X|
You can see that Px < X < Tx by looking at positions of basket and ball in the game.
(Py – H / Ty – H)^1/2 = (X – Px) / (Tx – X)
Tx * (Py – H / Ty – H)^1/2 – X * (Py – H / Ty – H)^1/2 = X – PX
Tx * (Py – H / Ty – H)^1/2 + Px = X + X * (Py – H / Ty – H)^1/2
X = (Tx * (Py – H / Ty – H)^1/2 + Px) / (1 + (Py – H / Ty – H)^1/2)
So we have axis of the highest point expressed in terms of known values.
The Java program below helps you to play the game using the calculations above. Things you have to do: Start program and open the game. Put your mouse to the lowest point of the ball. Then wait a moment for program to calculate and move your mouse to shooting position. Click your mouse to shoot. When new ball appears put your mouse to the lowest point of the ball and make the loop continue.
N.B. Coordinates of basket can be different for each screen. You can update the values in your program, since the program prints positions of the mouse to standard output. Put your mouse in the middle of the basket to see its coordinates in standard output. Then update basketPositionX and basketPositionY values in the code.
N.B. Since the movement of the ball is not a perfect parabola, the calculations fail during long shots. There is a variable called optCons to regulate calculations for long shots. So if the program fails in your computer, try increasing and decreasing this variable by small amounts (like 0.01 or 0.005).
import java.awt.AWTException;
import java.awt.MouseInfo;
import java.awt.Point;
import java.awt.Robot;
/**
*
* @author Server
*/
public class Main {
/* screen dependent variables */
public static final double basketPositionX = 143;
public static final double basketPositionY = 336;
public static final double optCons = 0.03;
/* end of screen dependent variables */
public static final double shootHeightY = -44;
public static void main(String[] args) throws AWTException, InterruptedException {
Robot robot = new Robot();
Point lastLocation = MouseInfo.getPointerInfo().getLocation();
Point location = MouseInfo.getPointerInfo().getLocation();
int counter = 0;
while (true) {
Thread.sleep(100);
location = MouseInfo.getPointerInfo().getLocation();
if (lastLocation.x != location.x || lastLocation.y != location.y) {
lastLocation = location;
counter = 0;
} else {
counter++;
if (counter == 5) {
Point calculatedLocation = calculate(location);
robot.mouseMove(calculatedLocation.x, calculatedLocation.y);
System.out.println(“Coordinate Get:” + location.x + “,” + location.y);
counter = 0;
}
}
}
}
private static Point calculate(Point location) {
double x1 = location.x;
double y1 = -location.y ;
double h = shootHeightY;
double opt;
double a = Math.sqrt(basketPositionY + shootHeightY);
double b = Math.sqrt(Math.abs( -y1 + h));
double r = (x1 * a + basketPositionX * b) / (a + b);
System.out.println(r);
opt = (x1-r) * optCons;
r += opt;
return new Point((int) r, (int) -h);
}
}

ben bu kodu derlediğimde 5 hata ile bitirdi “javac”
hatalarda
class mouseinfo ve variable mouse info ile ilgili oldu sırf şunun için java öğrenmeye başladım ama bir yerde yanlışlık var ne dersiniz?
Ben de sorunsuz derliyor “javac Main.java” ile. hataların tam çıktısını yazabilir misiniz?