import java.awt.AWTException;
import java.awt.Color;
import java.awt.Robot;
import java.awt.event.KeyEvent;
//Main Class of the bot
public class PinballBotThread extends Thread {
private Robot bot;
//Color of a certain pixel ball, grayish
private Color color = new Color(140,140,140);
//The white that can be found on the ball. Only used for making the bot shoot
//shoot of start position.
private Color white = new Color(255,255,255);
private int x1;
private int x2;
private int x3;
private int x4;
private int y;
private int startPosX;
private int startPosY;
public PinballBotThread() throws AWTException{
bot = new Robot();
ScreenSetup ss = new ScreenSetup();
x1 = ss.getX1();
x2 = ss.getX2();
x3 = ss.getX3();
x4 = ss.getX4();
y = ss.getY();
startPosX = ss.getStartPosX();
startPosY = ss.getStartPosY();
}
public void run() {
//Main engine of the bot.
//It takes advantage of fact that the graphics of the ball is static, and there
//is a place of the ball where 6 adjecent pixels have the same color, Color(140,140,140);
//It checks for a given color across a belt of pixels near paddles.
//A lot of the programming could be more pretty, but for optimation purposes, as many
//calculations as possible have been taken out of the loop, at the expense of clarity.
try{
while (true) {
for (int x = x1; x < x2; x = x+6){
if (bot.getPixelColor(x, y).equals(color)){
bot.keyPress(KeyEvent.VK_Z);
//makes the bot wait before executing more instructions. The game cannot handle
//inhuman press/release times of keys, that the bot could deliver.
bot.delay(200);
bot.keyRelease(KeyEvent.VK_Z);
bot.delay(200);
}
}
for (int j = x3; j < x4; j = j+6){
if (bot.getPixelColor(j, y).equals(color)){
bot.keyPress(KeyEvent.VK_QUOTE);
bot.delay(200);
bot.keyRelease(KeyEvent.VK_QUOTE);
bot.delay(200);
}
}
if (bot.getPixelColor(startPosX, startPosY).equals(white)){
bot.keyPress(KeyEvent.VK_SPACE);
bot.delay(2000);
bot.keyRelease(KeyEvent.VK_SPACE);
bot.delay(200);
}
Thread.sleep(1);
}
}catch (InterruptedException e){
}
}
}