Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ai;
- import mvc.Control;
- import spaceracer.Asteroid;
- import spaceracer.Constants;
- import spaceracer.PowerUp;
- import spaceracer.Range;
- import spaceracer.Spaceship;
- import spaceracer.SpaceshipRadar;
- import start.Startup;
- public class StudentAI implements Control {
- private Spaceship myShip;
- private SpaceshipRadar myRadar;
- private boolean avoidModeOn;
- private boolean goUp;
- public StudentAI(Spaceship ship) {
- myShip = ship;
- myRadar = myShip.getRadar();
- }
- public void moveShip() {
- float upperBarrierY = myRadar.getMaxY();
- float lowerBarrierY = myRadar.getMinY();
- //myShip.accelerate();
- if (avoidModeOn==true && myRadar.isAsteroidInFront()==true){
- if (goUp==true && myRadar.getNearestClearSpot(myRadar.getClearSpots())!=null&& myShip.getY()!=(myRadar.getMaxY())){
- //System.out.println("check1!");
- myShip.moveUp();
- }else if(goUp==false && myRadar.getNearestClearSpot(myRadar.getClearSpots())!=null&&myShip.getY()!=(myRadar.getMinY())) {
- myShip.moveDown();
- }
- } else if (avoidModeOn==true && myRadar.isAsteroidInFront()==false){
- avoidModeOn=false;
- myShip.yStop();
- } else if (avoidModeOn==false && myRadar.isAsteroidInFront()==true){
- //myShip.moveDown();
- avoidModeOn=true;
- if (myShip.getY()>3) {
- goUp=false;
- } else if (myShip.getY() <= 0){
- goUp=true;
- }
- } else if (avoidModeOn==false && myRadar.isAsteroidInFront()==false){
- myShip.accelerate();
- }
- Asteroid a= myRadar.getFirstAsteroidInFront();
- Asteroid d = myRadar.getFirstAsteroidBelow();
- Asteroid e = myRadar.getFirstAsteroidAbove();
- if (a!=null)
- {
- float b;
- float c;
- //float l;
- //float k;
- b=a.getX()-myShip.getX();
- c=a.getY()-myShip.getY();
- //l=myShip.getY()-d.getY();
- //k=e.getY()-myShip.getY();
- if (myRadar.isAsteroidInFront()==true &&b<=5&& c<=5){
- myShip.decelerate();
- //System.out.println("CHECK!");\
- }
- if (myRadar.isAsteroidInFront()==true &&b<=3&& c<=3){
- myShip.activateShield();
- //System.out.println("CHECK!");
- }
- /*else if (myRadar.isAsteroidInFront()==false &&k<=2){
- myShip.moveDown();
- }
- else if (myRadar.isAsteroidInFront()==false &&l<=2){
- myShip.moveUp();
- }*/
- /*else if (myRadar.isAsteroidInFront()==true &&avoidModeOn==true){
- if (goUp==true){
- myShip.moveUp();
- //System.out.println("CHECK!");
- }
- else
- myShip.moveDown();
- //System.out.println("CHECK!");
- }
- else if (myRadar.isAsteroidInFront()==true &&avoidModeOn==false)
- {
- avoidModeOn=true;
- if (myShip.getY()>0)
- {
- goUp=false;
- }
- else
- {
- goUp=true;
- }}
- else if (myRadar.isAsteroidInFront()==false &&avoidModeOn==true){
- avoidModeOn=false;
- myShip.yStop();
- } }
- else if (myRadar.isAsteroidInFront()==false &&avoidModeOn==false){
- myShip.accelerate();
- }*/
- }
- }
- }
- /*if (myRadar.isAsteroidInFront()==false){
- myShip.accelerate();
- }
- float Range;
- Range x[], y;
- x = myRadar.getClearSpots();
- if(x!=null){
- y = myRadar.getNearestClearSpot(x);
- if (y!=null);
- float clearCenter = y.getCenter();
- if (myShip.getY() > clearCenter ){
- myShip.moveDown();
- }
- else {
- myShip.moveUp();
- }
- }
- }
- }
- */ /*float yCoord;
- float yCoord1;
- float myY;
- yCoord=d.getY();
- yCoord1=e.getY();
- myY=myShip.getY();
- if (myY>yCoord){
- //myShip.moveUp();
- } else {myShip.moveDown();*/
- // put your code here
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement