Beispiel #1
0
 private float randomY(GameContainer c, Shape s) throws MushroomFactoryException {
   float y = -1;
   int numTries = 0;
   while (y < 0 || y >= c.getHeight()) {
     y = (float) (s.getMaxY() - s.getY() * Math.random());
     y += s.getY();
     numTries++;
     if (numTries > 6) {
       throw new MushroomFactoryException("Can't find valid point.");
     }
   }
   return y;
 }
  // 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;
      }
    }
  }
Beispiel #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();
 }
Beispiel #4
0
 /** @see org.newdawn.slick.gui.AbstractComponent#getHeight() */
 public int getHeight() {
   return (int) (area.getMaxY() - area.getY());
 }
Beispiel #5
0
 /**
  * Returns the position in the Y coordinate
  *
  * @return y
  */
 public int getY() {
   return (int) area.getY();
 }
Beispiel #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 getMaxY(Shape rectangle) {
   return rectangle.getY() + rectangle.getHeight() - 1;
 }