Exemple #1
0
  private void movement() {

    int x = getX(), y = getY(), dir = getRotation();

    if (Greenfoot.isKeyDown("left") && x > 10) {

      setLocation(x - 7, y);
      setRotation(Math.max(dir - 2, 247));
      starsDir();

    } else if (Greenfoot.isKeyDown("right") && x < 794) {

      setLocation(x + 7, y);
      setRotation(Math.min(dir + 2, 293));
      starsDir();

    } else {

      setRotation((int) Math.round(-(dir - 270) / 1.8) + dir);
      starsDir();
    }

    x = getX();

    if (Greenfoot.isKeyDown("up") && y > 70) {
      setLocation(x, y - 7);

    } else if (Greenfoot.isKeyDown("down") && y < 660) {

      setLocation(x, y + 7);
    }
  }
Exemple #2
0
 public void genLoc() {
   location = new int[2];
   int x = (int) (Math.random() * 3 + 1);
   switch (x) {
     case 1:
       location[0] = 5;
     case 2:
       location[0] = 600;
     case 3:
       location[0] = (int) (Math.random() * 600);
   }
   int y = (int) (Math.random() * 3 + 1);
   switch (x) {
     case 1:
       location[1] = 5;
     case 2:
       location[1] = 400;
     case 3:
       location[1] = (int) (Math.random() * 400);
   }
   setLocation(location[0], location[1]);
 }
 public void followHuman() {
   int dist = 400;
   Actor kill = null;
   if (!getObjectsInRange(dist, Player.class).isEmpty()) {
     for (Object obj : getObjectsInRange(dist, Player.class)) {
       Actor guy = (Actor) obj;
       int guyDist = (int) Math.hypot(guy.getX() - getX(), guy.getY() - getY());
       if (kill == null || guyDist < dist) {
         kill = guy;
         dist = guyDist;
       }
     }
     turnTowards(kill.getX(), kill.getY());
   }
 }
 /**
  * Get the distance to the ScrollingActor.
  *
  * @return The distance between this object and the ScrollingActor.
  */
 public double getDistanceToScrollingActor() {
   List<ScrollingActor> actors = getWorld().getObjects(ScrollingActor.class);
   if (actors != null && !actors.isEmpty()) {
     ScrollingActor actor = null;
     for (ScrollingActor scrollingActor : actors) {
       if (scrollingActor.isScrollingCenter()) {
         actor = scrollingActor;
       }
     }
     if (actor == null) {
       System.err.println("No scrollingActor in the world.");
       return 0;
     }
     return Math.hypot(getExactX() - actor.getExactX(), getExactY() - actor.getExactY());
   }
   return 0;
 }
Exemple #5
0
 public void genSpecs() {
   rotation = (int) (Math.random() * 180);
   setRotation(rotation);
 }
Exemple #6
0
 public Enemies(Player p) {
   speed = (int) (Math.random() * 3);
   genSpecs();
   genLoc();
   player = p;
 }
Exemple #7
0
 public void set(int fury) {
   if (!player.FURY_ENABLED) fury = 0;
   fury = Math.min(6, fury);
   setImage("fury_" + fury + ".png");
 }