Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class MyDemo
- {
- public static void main(String[]args)
- {
- int Counter=0, AnimY, AnimX, Menu=0, Distance=0, XPosit=0, YPosit=0, XSize=0, YSize=0, Movement=0;
- boolean Binary = true;
- System.out.println("How tall would you like the animation to be?");
- AnimY = IO.readInt();
- System.out.println("How wide would you like the animation to be?");
- AnimX = IO.readInt();
- Animation Demo = new Animation(1000, 600);
- Demo.setBackgroundImage("tunnel-background.jpg");
- Demo.setFrameRate(2);
- Demo.frameFinished();
- Sprite One = new Sprite("sailor.jpg");
- Demo.addSprite(One);
- One.setPosition(100, 100);
- Sprite Two = new Sprite("army.png");
- Demo.addSprite(Two);
- Two.setPosition(300, 100);
- Sprite Three = new Sprite("RSS.gif");
- Demo.addSprite(Three);
- Three.setPosition(500, 100);
- Sprite Current=null;
- Demo.frameFinished();
- while (Binary)
- {
- Menu = 0;
- //Menu
- System.out.println("Would you like to move sprite #1, #2, or #3? Press anything else to exit.");
- Menu = IO.readInt();
- if (Menu >3 || Menu < 1)
- {
- Binary = false;
- break;
- }
- //Sprite controls
- if (Menu == 1)
- {
- Current = One;
- }
- else if (Menu == 2)
- {
- Current = Two;
- }
- else if (Menu == 3)
- {
- Current = Three;
- }
- /*
- else
- {
- Binary = false;
- }
- */
- if (Binary)
- {
- System.out.println("Press 1 if you would like to move up, 2 if you would like to move right, 3 if you would like to move down, and 4 if you would like to move left.");
- Menu = IO.readInt();
- if (Menu >4 || Menu < 1)
- {
- IO.reportBadInput();
- System.out.println("I'm sorry, Dave; I can't let you do that.");
- }
- else
- {
- System.out.println("How far would you like to move?");
- Distance = IO.readInt();
- YPosit = Current.getYposition();
- XPosit = Current.getXposition();
- XSize = Current.getXsize();
- YSize = Current.getYsize();
- }
- if (Menu == 1)
- {
- YPosit = YPosit+Distance;
- Current.setPosition(XPosit, YPosit);
- //Interference Check
- if (Math.abs(One.getXposition() - Two.getXposition()) < Math.max(One.getXsize(), Two.getXsize()) &&
- Math.abs(One.getYposition() - Two.getYposition()) < Math.max(One.getYsize(), Two.getYsize()))
- {
- YPosit = YPosit - Distance;
- Current.setPosition(XPosit, YPosit);
- System.out.println("I'm sorry; you would bump into another sprite and we wouldn't want that.");
- }
- if (Math.abs(Two.getXposition() - Three.getXposition()) < Math.max(Two.getXsize(), Three.getXsize()) &&
- Math.abs(Two.getYposition() - Three.getYposition()) < Math.max(Two.getYsize(), Three.getYsize()))
- {
- YPosit = YPosit - Distance;
- Current.setPosition(XPosit, YPosit);
- System.out.println("I'm sorry; you would bump into another sprite and we wouldn't want that.");
- }
- if (Math.abs(One.getXposition() - Three.getXposition()) < Math.max(One.getXsize(), Three.getXsize()) &&
- Math.abs(One.getYposition() - Three.getYposition()) < Math.max(One.getYsize(), Three.getYsize()))
- {
- YPosit = YPosit - Distance;
- Current.setPosition(XPosit, YPosit);
- System.out.println("I'm sorry; you would bump into another sprite and we wouldn't want that.");
- }
- if ((Current.getYposition() < 0) || (Current.getYposition() > AnimX))
- {
- YPosit = YPosit - Distance;
- Current.setPosition(XPosit, YPosit);
- System.out.println("Oh, no! You can't go off the screen!");
- }
- }
- if (Menu == 2)
- {
- XPosit = XPosit+Distance;
- Current.setPosition(XPosit, YPosit);
- //Interference Check
- if (Math.abs(One.getXposition() - Two.getXposition()) < Math.max(One.getXsize(), Two.getXsize()) &&
- Math.abs(One.getYposition() - Two.getYposition()) < Math.max(One.getYsize(), Two.getYsize()))
- {
- XPosit = XPosit - Distance;
- Current.setPosition(XPosit, YPosit);
- System.out.println("I'm sorry; you would bump into another sprite and we wouldn't want that.");
- }
- if (Math.abs(Two.getXposition() - Three.getXposition()) < Math.max(Two.getXsize(), Three.getXsize()) &&
- Math.abs(Two.getYposition() - Three.getYposition()) < Math.max(Two.getYsize(), Three.getYsize()))
- {
- XPosit = XPosit - Distance;
- Current.setPosition(XPosit, YPosit);
- System.out.println("I'm sorry; you would bump into another sprite and we wouldn't want that.");
- }
- if (Math.abs(One.getXposition() - Three.getXposition()) < Math.max(One.getXsize(), Three.getXsize()) &&
- Math.abs(One.getYposition() - Three.getYposition()) < Math.max(One.getYsize(), Three.getYsize()))
- {
- XPosit = XPosit - Distance;
- Current.setPosition(XPosit, YPosit);
- System.out.println("I'm sorry; you would bump into another sprite and we wouldn't want that.");
- }
- if ((Current.getXposition() < 0) || (Current.getXposition() > AnimX))
- {
- XPosit = XPosit - Distance;
- Current.setPosition(XPosit, YPosit);
- System.out.println("Oh, no! You can't go off the screen!");
- }
- }
- if (Menu == 3)
- {
- YPosit = YPosit-Distance;
- Current.setPosition(XPosit, YPosit);
- //Interference Check
- if (Math.abs(One.getXposition() - Two.getXposition()) < Math.max(One.getXsize(), Two.getXsize()) &&
- Math.abs(One.getYposition() - Two.getYposition()) < Math.max(One.getYsize(), Two.getYsize()))
- {
- YPosit = YPosit + Distance;
- Current.setPosition(XPosit, YPosit);
- System.out.println("I'm sorry; you would bump into another sprite and we wouldn't want that.");
- }
- else if (Math.abs(Two.getXposition() - Three.getXposition()) < Math.max(Two.getXsize(), Three.getXsize()) &&
- Math.abs(Two.getYposition() - Three.getYposition()) < Math.max(Two.getYsize(), Three.getYsize()))
- {
- YPosit = YPosit + Distance;
- Current.setPosition(XPosit, YPosit);
- System.out.println("I'm sorry; you would bump into another sprite and we wouldn't want that.");
- }
- else if (Math.abs(One.getXposition() - Three.getXposition()) < Math.max(One.getXsize(), Three.getXsize()) &&
- Math.abs(One.getYposition() - Three.getYposition()) < Math.max(One.getYsize(), Three.getYsize()))
- {
- YPosit = YPosit + Distance;
- Current.setPosition(XPosit, YPosit);
- System.out.println("I'm sorry; you would bump into another sprite and we wouldn't want that.");
- }
- if ((Current.getYposition() < 0) || (Current.getYposition() > AnimX))
- {
- YPosit = YPosit + Distance;
- Current.setPosition(XPosit, YPosit);
- System.out.println("Oh, no! You can't go off the screen!");
- }
- }
- if (Menu == 4)
- {
- XPosit = XPosit-Distance;
- Current.setPosition(XPosit, YPosit);
- //Interference Check
- if (Math.abs(One.getXposition() - Two.getXposition()) < Math.max(One.getXsize(), Two.getXsize()) &&
- Math.abs(One.getYposition() - Two.getYposition()) < Math.max(One.getYsize(), Two.getYsize()))
- {
- XPosit = XPosit + Distance;
- Current.setPosition(XPosit, YPosit);
- System.out.println("I'm sorry; you would bump into another sprite and we wouldn't want that.");
- }
- if (Math.abs(Two.getXposition() - Three.getXposition()) < Math.max(Two.getXsize(), Three.getXsize()) &&
- Math.abs(Two.getYposition() - Three.getYposition()) < Math.max(Two.getYsize(), Three.getYsize()))
- {
- XPosit = XPosit + Distance;
- Current.setPosition(XPosit, YPosit);
- System.out.println("I'm sorry; you would bump into another sprite and we wouldn't want that.");
- }
- if (Math.abs(One.getXposition() - Three.getXposition()) < Math.max(One.getXsize(), Three.getXsize()) &&
- Math.abs(One.getYposition() - Three.getYposition()) < Math.max(One.getYsize(), Three.getYsize()))
- {
- XPosit = XPosit + Distance;
- Current.setPosition(XPosit, YPosit);
- System.out.println("I'm sorry; you would bump into another sprite and we wouldn't want that.");
- }
- if ((Current.getXposition() < 0) || (Current.getXposition() > AnimX))
- {
- XPosit = XPosit + Distance;
- Current.setPosition(XPosit, YPosit);
- System.out.println("Oh, no! You can't go off the screen!");
- }
- }
- Demo.frameFinished();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement