Package org.newdawn.slick.geom

Examples of org.newdawn.slick.geom.Vector2f


   *
   * @param x The x coordinate of the start control point
   * @param y The y coordinate of the start control point
   */
  public void setStart(float x, float y) {
    setStart(new Vector2f(x,y));
  }
View Full Code Here


   * Set the start control point's position
   *
   * @param start The new poisition for the start point
   */
  public void setStart(Vector2f start) {
    this.start = new Vector2f(start);
  }
View Full Code Here

   *
   * @param x The x coordinate of the end control point
   * @param y The y coordinate of the end control point
   */
  public void setEnd(float x, float y) {
    setEnd(new Vector2f(x,y));
  }
View Full Code Here

   * Set the end control point's position
   *
   * @param end The new position for the end point
   */
  public void setEnd(Vector2f end) {
    this.end = new Vector2f(end);
  }
View Full Code Here

  public void enter(GameContainer container, StateBasedGame game) throws SlickException {
    toggleFullscreen = false;
    returnToGame = false;
    credits = false;
    bigMap = false;
    mapOffset = new Vector2f(0,0);
    keyDown = -1;
    zLocation = Maxim.getMaxim().getCurrentMap().getWorldZ();
  }
View Full Code Here

      if ((actor.getBox().getX()%16 == 0 && actor.getBox().getY()%16 == 0) || actor.getMoveDirection().x + actor.getMoveDirection().y == 0) {
        Behaviors.wanderAimlessly(actor);
      }
     
    } else if (behavior.equals("projectile")) {
      actor.setMoveDirection(new Vector2f((float)FastTrig.cos(direction), (float)FastTrig.sin(direction)));
     
      if (!actor.canMove(actor.getMoveDirection()) || isMovingOffMap(actor, actor.getMoveDirection())) {
        actor.destroy();
        return;
      }
     
    } else if (behavior.equals("hunt")) {

      if ((actor.getBox().getX()%16 == 0 && actor.getBox().getY()%16 == 0) || actor.getMoveDirection().x + actor.getMoveDirection().y == 0) {
        Entity max = null;
        ArrayList<Entity> entities = actor.getMap().getEntities();
        for (Entity e : entities) {
          if (e.getName().equals("player")) {
            max = e;
            break;
          }
        }
       
        if (max == null) {
          Behaviors.wanderAimlessly(actor);
        } else {
          Behaviors.hunt(actor, new Vector2f(max.getBox().getCenterX(), max.getBox().getCenterY()), false);
        }
      }
     
    } else if (behavior.equals("intercept")) {

      if ((actor.getBox().getX()%16 == 0 && actor.getBox().getY()%16 == 0) || actor.getMoveDirection().x + actor.getMoveDirection().y == 0) {
        Entity player = null;
        ArrayList<Entity> entities = actor.getMap().getEntities();
        for (Entity e : entities) {
          if (e.getName().equals("player")) {
            player = e;
            break;
          }
        }
       
        if (player == null) {
          Behaviors.wanderAimlessly(actor);
        } else {
          Behaviors.hunt(actor, new Vector2f(player.getBox().getCenterX()+player.getLastDirection().x*64, player.getBox().getCenterY()+player.getLastDirection().y*64), false);
        }
      }
     
    } else if (behavior.equals("flee")) {

      if ((actor.getBox().getX()%16 == 0 && actor.getBox().getY()%16 == 0) || actor.getMoveDirection().x + actor.getMoveDirection().y == 0) {
        Entity player = null;
        ArrayList<Entity> entities = actor.getMap().getEntities();
        for (Entity e : entities) {
          if (e.getName().equals("player")) {
            player = e;
            break;
          }
        }
       
        if (player == null) {
          Behaviors.wanderAimlessly(actor);
        } else {
          Vector2f myPos = new Vector2f(actor.getBox().getCenterX(), actor.getBox().getCenterY());
          Vector2f playerPos = new Vector2f(player.getBox().getCenterX(), player.getBox().getCenterY());
         
          double angle = Math.atan2(playerPos.y - myPos.y, playerPos.x - myPos.x) + Math.PI;
         
          Vector2f target = new Vector2f((float)FastTrig.cos(angle)*100 + myPos.x, (float)FastTrig.sin(angle)*100 + myPos.y);
          Behaviors.hunt(actor, target, true);
        }
      }
     
    } else if (behavior.equals("none")) {
View Full Code Here

    float xMove = xDistance / Math.abs(xDistance);
    float yMove = yDistance / Math.abs(yDistance);
   
    if (reverse) {
      if ((Math.abs(xDistance) > Math.abs(yDistance))) {
        moveToward(hunter, new Vector2f(0,yMove), new Vector2f(xMove,0));
      } else {
        moveToward(hunter, new Vector2f(xMove,0), new Vector2f(0,yMove));
      }
     
    } else {
      if ((Math.abs(xDistance) > Math.abs(yDistance))) {
        moveToward(hunter, new Vector2f(xMove,0), new Vector2f(0,yMove));
      } else {
        moveToward(hunter, new Vector2f(0,yMove), new Vector2f(xMove,0));
      }
     
    }
  }
View Full Code Here

     
    } else if (wantsToMoveInDirection(mover, secondary)) {
      mover.setMoveDirection(secondary);
      mover.setLastDirection(secondary);
     
    } else if (wantsToMoveInDirection(mover, new Vector2f(-secondary.x, -secondary.y))) {
      mover.setMoveDirection(new Vector2f(-secondary.x, -secondary.y));
      mover.setLastDirection(new Vector2f(-secondary.x, -secondary.y));
     
    } else if (wantsToMoveInDirection(mover, new Vector2f(-primary.x, -primary.y))) {
      mover.setMoveDirection(new Vector2f(-primary.x, -primary.y));
      mover.setLastDirection(new Vector2f(-primary.x, -primary.y));
    }
  }
View Full Code Here

  }
 
  public static void wanderAimlessly (Entity wanderer) {
    int rand = (int)(Math.random()*4);
   
    Vector2f direction = new Vector2f(0,0);
    if (rand == 0) {
      direction = new Vector2f(0,-1);
    } else if (rand == 1) {
      direction = new Vector2f(0,1);
    } else if (rand == 2) {
      direction = new Vector2f(1,0);
    } else if (rand == 3) {
      direction = new Vector2f(-1,0);
    }
   
    if (wantsToMoveInDirection(wanderer, direction)) {
      wanderer.setMoveDirection(direction);
      wanderer.setLastDirection(wanderer.getMoveDirection());
View Full Code Here

    canMoveIncludingEntities(mover, direction); //Only let the AI move if they think the path is clear.
  }
 
  private static boolean isDeadEnd (Entity mover, Vector2f direction) { //Direction, here, is AWAY from the "dead end"
    if (direction.y == -1) {
      return (!canMoveIncludingEntities(mover, new Vector2f(0,1)) && !canMoveIncludingEntities(mover, new Vector2f(1,0)) && !canMoveIncludingEntities(mover, new Vector2f(-1,0)));
    } else if (direction.y == 1) {
      return (!canMoveIncludingEntities(mover, new Vector2f(0,-1)) && !canMoveIncludingEntities(mover, new Vector2f(1,0)) && !canMoveIncludingEntities(mover, new Vector2f(-1,0)));
    } else if (direction.x == 1) {
      return (!canMoveIncludingEntities(mover, new Vector2f(0,1)) && !canMoveIncludingEntities(mover, new Vector2f(0,-1)) && !canMoveIncludingEntities(mover, new Vector2f(-1,0)));
    } else if (direction.x == -1) {
      return (!canMoveIncludingEntities(mover, new Vector2f(0,1)) && !canMoveIncludingEntities(mover, new Vector2f(1,0)) && !canMoveIncludingEntities(mover, new Vector2f(0,-1)));
    }
   
    return false;
  }
View Full Code Here

TOP

Related Classes of org.newdawn.slick.geom.Vector2f

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.