Пример #1
0
 public void mouseTouched(Actor actor, GGMouse mouse, Point spot) {
   switch (mouse.getEvent()) {
     case GGMouse.lPress:
       startLocation = toLocation(mouse.getX(), mouse.getY());
       actor.setOnTop();
       hotSpot = spot;
       break;
     case GGMouse.lDrag:
       Point imageCenter = new Point(mouse.getX() - hotSpot.x, mouse.getY() - hotSpot.y);
       actor.setPixelLocation(imageCenter);
       refresh();
       break;
     case GGMouse.lRelease:
       if (spot.x == -1) // Cursor is outside image
       actor.setLocation(startLocation);
       else {
         actor.setPixelLocation(new Point(mouse.getX(), mouse.getY()));
         nbMoves++;
         if (isOver()) setStatusText("Total #: " + nbMoves + ". Done.");
         else setStatusText("#: " + nbMoves);
       }
       actor.setLocationOffset(new Point(0, 0));
       hotSpot = null;
       refresh();
       break;
   }
 }
 /**
  * Set the players location if possible.
  *
  * @param x The new x location of the actor.
  * @param y The new y location of the actor.
  */
 public void setLocation(double x, double y) {
   if (ScrollingWorld.WORLD_WIDTH != 0) {
     if (getDistanceToScrollingActor('x') - getWorld().getTotalXMovement()
         > ScrollingWorld.WORLD_WIDTH / 2) {
       x = getStartingPoint().getX() + ScrollingWorld.WORLD_WIDTH / 2;
     } else if (getDistanceToScrollingActor('x') - getWorld().getTotalXMovement()
         < -ScrollingWorld.WORLD_WIDTH / 2) {
       x = getStartingPoint().getX() - ScrollingWorld.WORLD_WIDTH / 2;
     }
   }
   if (ScrollingWorld.WORLD_HEIGHT != 0) {
     if (getDistanceToScrollingActor('y') - getWorld().getTotalYMovement()
         > ScrollingWorld.WORLD_HEIGHT / 2) {
       y = getStartingPoint().getY() + ScrollingWorld.WORLD_HEIGHT / 2;
     } else if (getDistanceToScrollingActor('y') - getWorld().getTotalYMovement()
         < -ScrollingWorld.WORLD_HEIGHT / 2) {
       y = getStartingPoint().getY() - ScrollingWorld.WORLD_HEIGHT / 2;
     }
   }
   exactX = x;
   exactY = y;
   super.setLocation((int) x, (int) y);
 }
  @Override
  public void run() {
    // TODO Auto-generated method stub
    while (runner.isAlive()) {
      actors = one.getActors();

      // one.go();
      for (int z = 0; z < AList.size(); z++) {
        Actor a = AList.get(z);
        if (a.equals(background) && a.topy() >= 350) {
          a.setLocation(-5, -360);
        }
        if (a.equals(background2) && a.topy() >= 350) {
          a.setLocation(-5, -360);
        }

        if (a.equals(ammo) && a.topy() >= 350) {
          a.setLocation((int) (330 * Math.random()) + 30, (int) (-1000 * Math.random()) + -1);
        }
        if (a.equals(r) && a.topy() >= 350) {

          a.setLocation(-85, -361);
        }
        if (a.equals(r2) && a.topy() >= 350) {

          a.setLocation(-85, -361);
        }
        if (a.equals(r3) && a.topy() >= 350) {

          a.setLocation(355, -361);
        }
        if (a.equals(r4) && a.topy() >= 350) {

          a.setLocation(355, -361);
        }
        for (int ctr = 0; ctr < rs.length; ctr++) {
          if (a.equals(rs[ctr]) && a.topy() >= 350) {
            a.setLocation((int) (330 * Math.random()) + 30, (int) (-370 * Math.random()) + -1);
          }
        }
        if (a instanceof Ammo) {

          if (a.getRect().intersects(one.getLeft()) == true
              || a.getRect().intersects(one.getRight()) == true
              || a.getRect().intersects(one.getBottom()) == true) {
            a.setLocation((int) (330 * Math.random()) + 30, (int) (-370 * Math.random()) + -1);
            Laser laser = new Laser(one.getX(), one.getY(), "images/laser2.png");
            one.arsenal.add(laser);
            // a.removeSelf();
            one.ammohit = true;
          }
        }

        if (a instanceof Rock) {
          //  System.out.println("PodR: "+one.getRect());
          // System.out.println("Rock :"+a.getRect());

          if (a.getRect().intersects(one.getLeft()) == true
              || a.getRect().intersects(one.getRight()) == true) {
            // System.out.println("collision");
            one.collision = true;
            one.newImage("images/Explosion1.gif");
            one.y -= 60;
            tstop = true;

            speed = one.backSpeed;
            runner.stop();
          }

          //  if(one.collision(a)==true){
          //     System.out.println("collide");
          // }

        }
        if (a instanceof PodRacer) {

          while (a.getY() <= 0) {
            a.y += 1;
          }
          while (a.getY() >= 288) {
            a.y += -1;
          }

        } else {

          a.move();
        }

        if (a instanceof Laser) {
          Laser temp = (Laser) a;
          for (int ctr = 0; ctr < rs.length; ctr++) {
            if (a.getRect().intersects(rs[ctr].getRect()) == false || a.boty() >= 0) {
              // System.out.println("test");
              temp.Shot();
            }

            if (a.boty() <= 0) {
              mtemp = temp;
              laserremove = true;
            }
            if (a.getRect().intersects(rs[ctr].getRect())) {
              mtemp = temp;
              laserremove = true;
              rs[ctr].setLocation(
                  (int) (330 * Math.random()) + 30, (int) (-370 * Math.random()) + -1);
              one.rockhit = true;
            }
          }
        }
      }
      if (laserremove == true) {
        laserremove = false;
        // System.out.println("test");
        // one.arsenal.remove(0);
        mtemp.removeSelf();
      }

      try {
        speed = one.backSpeed;
        runner.sleep(speed);
      } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
      // run();
    }
  }