My program crashes every time I call this method because of the while loop. I guess its going into a infinite loop, but I cant figure out why. The game should keep running until the user ends it. Is the use of my .isKeyPressed correct and if so what else could it be?
public static void run() {
while (true) {
if (StdDraw.isKeyPressed(KeyEvent.VK_Q)) {
break;
}
StdDraw.picture(250, 250, "space.jpg", 500, 500);
Ship ship = new Ship();
int x = ship.getShipPosx();
int y = ship.getShipPosy();
StdDraw.picture(x, y, "ship2.png", 40, 50);
if (StdDraw.isKeyPressed(KeyEvent.VK_LEFT)) {
ship.setShipPos(x - 10, y);
}
if (StdDraw.isKeyPressed(KeyEvent.VK_RIGHT)) {
ship.setShipPos(x + 10, y);
}
StdDraw.show(150);
}
}
No comments:
Post a Comment