Exemple #1
0
 private float randomX(GameContainer c, Shape s) throws MushroomFactoryException {
   float x = -1;
   int numTries = 0;
   while (x < 0 || x >= c.getWidth()) {
     x = (float) (s.getMaxX() - s.getX() * Math.random());
     x += s.getX();
     numTries++;
     if (numTries > 6) {
       throw new MushroomFactoryException("Can't find valid point.");
     }
   }
   return x;
 }
  // propagate logic
  public void moveBullet(float ms) {
    // the bigger amount of pixels to move.
    float steps =
        (Math.abs(xVel * ms) > Math.abs(yVel * ms)) ? Math.abs(xVel * ms) : Math.abs(yVel * ms);

    steps += 1;

    float deltaX = (xVel * ms) / steps;
    float deltaY = (yVel * ms) / steps;

    for (int i = 0; i != (int) (steps + 1); i++) {
      shape.setX(shape.getX() + deltaX);
      shape.setY(shape.getY() + deltaY);

      for (SPlayer p : SState.players) {

        if (p != null) {
          if (p.intersects(shape)) {
            p.hurt(damage);
            live = false;
            return;
          }
        }
      }

      if (SState.map.checkCollide(getShape())) {
        live = false;
        return;
      }
    }
  }
Exemple #3
0
 /**
  * @see org.newdawn.slick.gui.AbstractComponent#render(org.newdawn.slick.gui.GUIContext,
  *     org.newdawn.slick.Graphics)
  */
 public void render(GUIContext container, Graphics g) {
   if (currentImage != null) {
     currentImage.draw(area.getX(), area.getY(), currentColor);
   } else {
     g.setColor(currentColor);
     g.fill(area);
   }
   updateImage();
 }
Exemple #4
0
 /** @see org.newdawn.slick.gui.AbstractComponent#getWidth() */
 public int getWidth() {
   return (int) (area.getMaxX() - area.getX());
 }
Exemple #5
0
 /**
  * Returns the position in the X coordinate
  *
  * @return x
  */
 public int getX() {
   return (int) area.getX();
 }
Exemple #6
0
 public void setSize(int width, int height) {
   Shape shape = new Rectangle(area.getX(), area.getY(), width, height);
   this.area = shape;
 }
 public static float getMaxX(Shape rectangle) {
   return rectangle.getX() + rectangle.getWidth() - 1;
 }