public class Lab5 { public static void main(String[] args) { // requires images angry.png and green-pig.png in the Lab5 folder // (see website for links) int x; int y; int xVelocity; int yVelocity; int oldx; int oldy; int targetx; int targety; boolean winner; Draw.window(600,600); targetx = 375; targety = Util.random(0,500); Draw.image(targetx,targety,100,100,"green-pig.png"); winner = false; // haven't won yet x = 0; // starting position of angry bird y = 500; Draw.image(x,y,100,100,"angry.png"); Util.pause(0.01); Draw.setColor(255,255,255); Draw.setFill(true); System.out.println("Please input the x velocity:"); xVelocity = Integer.parseInt(Util.input()); System.out.println("Please input the y velocity:"); yVelocity = Integer.parseInt(Util.input()); while (!winner && x <= 600 && y <= 500) { oldx = x; oldy = y; x = x + xVelocity; y = y - yVelocity; yVelocity = yVelocity - 1; if (x <= 600 && y <= 500) { // As long as the new x value isn't completely // off the screen to the right and as long as // the new y value doesn't make the bird go // through the "ground" Draw.oval(oldx-8,oldy-8,100+16,100+16); Draw.image(targetx,targety,100,100,"green-pig.png"); Draw.image(x,y,100,100,"angry.png"); Util.pause(0.01); if (x >= targetx - 50 && y >= targety - 50 && x <= targetx + 50 && y <= targety + 50) { // If the bird hits at least half of the target // then set winner to true which will cause the // loop to stop on the next loop check. winner = true; } } } Draw.setFont(144); Draw.setColor(0,0,255); if (winner) { Draw.text(300,300,"5000"); } } }