Ejemplo n.º 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;
 }
Ejemplo n.º 2
0
  // 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;
      }
    }
  }
Ejemplo n.º 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();
 }
Ejemplo n.º 4
0
 /** @see org.newdawn.slick.gui.AbstractComponent#getWidth() */
 public int getWidth() {
   return (int) (area.getMaxX() - area.getX());
 }
Ejemplo n.º 5
0
 /**
  * Returns the position in the X coordinate
  *
  * @return x
  */
 public int getX() {
   return (int) area.getX();
 }
Ejemplo n.º 6
0
 public void setSize(int width, int height) {
   Shape shape = new Rectangle(area.getX(), area.getY(), width, height);
   this.area = shape;
 }
Ejemplo n.º 7
0
 public static float getMaxX(Shape rectangle) {
   return rectangle.getX() + rectangle.getWidth() - 1;
 }