Ejemplo n.º 1
0
 public void act() {
   GreenfootImage img = new GreenfootImage(50, 50);
   getScore();
   String i = Integer.toString(score);
   img.drawString(i, 20, 20);
   this.setImage(img);
 }
Ejemplo n.º 2
0
 /** constructor de variables de la clase pizza */
 public Pizza() {
   dir = 1;
   vel = 3;
   GreenfootImage image = getImage();
   image.scale(30, 30);
   setImage(image);
 }
Ejemplo n.º 3
0
  /** Draws status bar for Fire Power */
  private void drawIce() {

    myImage.setColor(Color.RED); // Set the color of myImage blue
    myImage.drawString("Fire Power", 10, 30); // display text "Fire Power" at a location on myImage
    bar.setColor(Color.RED); // set the color of the image bar as blue
    bar.fill(); // fill the image bar with blue
  }
Ejemplo n.º 4
0
  /** Draws status bar for Flight */
  private void drawFire() {

    myImage.setColor(Color.BLUE); // Set the color of myImage red
    myImage.drawString("Flight", 10, 30); // display text "Flight" at a location on myImage
    bar.setColor(Color.BLUE); // set the color of the image bar as red
    bar.fill(); // fill the image bar with red
  }
Ejemplo n.º 5
0
  /** Draws status bar for Invincibility */
  private void drawStun() {

    myImage.setColor(Color.YELLOW);
    myImage.drawString("Invincibility", 10, 30);
    bar.setColor(Color.YELLOW);
    bar.fill();
  }
Ejemplo n.º 6
0
  /** Draws status bar for Black Hole */
  private void drawPoison() {

    myImage.setColor(Color.BLACK);
    myImage.drawString("Black Hole", 10, 30);
    bar.setColor(Color.BLACK);
    bar.fill();
  }
Ejemplo n.º 7
0
  /**
   * Set a background image for the world. If the image size is larger than the world in pixels, it
   * is clipped. If it is smaller than the world, it is tiled. A pattern showing the cells can
   * easily be shown by setting a background image with a size equal to the cell size.
   *
   * @see #setBackground(String)
   * @param image The image to be shown
   */
  public final void setBackground(GreenfootImage image) {
    if (image != null) {
      int imgWidth = image.getWidth();
      int imgHeight = image.getHeight();
      int worldWidth = getWidthInPixels();
      int worldHeight = getHeightInPixels();
      boolean tile = imgWidth < worldWidth || imgHeight < worldHeight;

      if (tile) {
        backgroundIsClassImage = false;
        backgroundImage = new GreenfootImage(worldWidth, worldHeight);
        backgroundImage.setColor(DEFAULT_BACKGROUND_COLOR);
        backgroundImage.fill();

        for (int x = 0; x < worldWidth; x += imgWidth) {
          for (int y = 0; y < worldHeight; y += imgHeight) {
            backgroundImage.drawImage(image, x, y);
          }
        }
      } else {
        // To make it behave exactly the same way as when tiling we
        // should make a clone here. But it performs better when not
        // cloning.
        // Performance will be an issue for people changing the
        // background image all the time for animated backgrounds
        backgroundImage = image;
      }
    } else {
      backgroundIsClassImage = false;
      backgroundImage = null;
    }
  }
  public SpriteAnimation(String imageFile, int numFrames, int ticksPerFrame) {
    try {
      // Load the raw frames into a frame buffer
      GreenfootImage baseImg = new GreenfootImage(imageFile);
      GreenfootImage[] baseFrames = new GreenfootImage[numFrames];
      int frameWidth = baseImg.getWidth() / numFrames;
      int frameHeight = baseImg.getHeight();
      BufferedImage rawImg = baseImg.getAwtImage();
      for (int x = 0; x < numFrames; x++) {
        baseFrames[x] = new GreenfootImage(frameWidth, frameHeight);
        baseFrames[x]
            .getAwtImage()
            .setData(rawImg.getSubimage(x * frameWidth, 0, frameWidth, frameHeight).getData());
      }

      // Re-use object references to save from copying the images multiple times
      frames = new GreenfootImage[numFrames * ticksPerFrame];
      flipped = new GreenfootImage[numFrames * ticksPerFrame];
      for (int f = 0; f < numFrames; f++) {
        for (int t = 0; t < ticksPerFrame; t++) {
          frames[f * ticksPerFrame + t] = baseFrames[f];
          flipped[f * ticksPerFrame + t] = new GreenfootImage(baseFrames[f]);
          flipped[f * ticksPerFrame + t].mirrorHorizontally();
        }
      }
    } catch (IllegalArgumentException e) {
      frames = flipped = new GreenfootImage[1];
      frames[0] = ERROR_IMAGE;
    }
  }
Ejemplo n.º 9
0
  /**
   * Decreases the count down value of status duration, bar width and displays the percentate of
   * status duration left If there is a target, When status duration reaches zero, the status
   * disappears.
   *
   * @param change The Change in status duration value each Act
   */
  public void update(int change) {

    if (currCountDown > 0) {
      currCountDown -= change; // decreases the current countdown by the change value
      percentCountdown =
          (double) currCountDown
              / maxCountDown; // set a double value of percent countdown by dividing current
                              // countdown by maximum countdown
      currBarWidth =
          (int)
              (percentCountdown
                  * barWidth); // set a interger value of current bar width by multiplying percent
                               // countdown and bar width and casting them into a interger value
      percentDisplay =
          (int)
              (percentCountdown
                  * 100); // set a interget value of percentDisplay by multiplying percentCountdown
                          // by 100.
      percentCounter =
          Integer.toString(
              percentDisplay); // cast the interger percentDisplay into a string and store it in
                               // percentCouner
      myImage.clear(); // clears the image
      myImage.drawString(percentCounter + "%", 70, 30); // draws the percentCounter on myImage
      if (currBarWidth > 1) bar.scale(currBarWidth, BAR_HEIGHT); // rescale the bar size
      if (selection == true) if (currCountDown == 1) currCountDown += 1;
      update(); // redraw the image
    }
    if (selection == false)
      if (currCountDown == 0) // if current countdown is 0
      removeStatus(); // remove status
  }
Ejemplo n.º 10
0
  private void ammoChange(AmmoData ad) {

    ammoICO.setImage(ad.image);
    GreenfootImage i = ammoICO.getImage();
    i.scale((int) (ad.width * 1.75), (int) (ad.height * 1.75));
    playerAmmo = ad;
    ammoUI.setPoints(ammo[playerAmmunition.indexOf(ad)]);
  }
Ejemplo n.º 11
0
  public Shield() {
    super();

    GreenfootImage image = getImage();
    image.scale(50, 50);
    setImage(image);

    effectiveTimeLeft = 500;
  }
Ejemplo n.º 12
0
 private void printText() {
   laranjaEscuro = new Color(214, 95, 0);
   imgHelp.setColor(laranjaEscuro);
   Font play = new Font("sanserif", Font.BOLD, 30);
   imgHelp.setFont(play);
   int x = imgHelp.getWidth() - 130;
   int y = imgHelp.getHeight() - 16;
   imgHelp.drawString("Help", x, y);
 }
Ejemplo n.º 13
0
 /**
  * Add the scores for the individual maps to the score board. 'scores' is an array with all
  * scores, 'mapNo' is the number of the current map (array entries past this value have no valid
  * value).
  */
 private void addMapScores(int mapNo, int[] scores) {
   GreenfootImage image = getImage();
   Font font = image.getFont();
   font = font.deriveFont(20.0f);
   image.setFont(font);
   image.setColor(Color.WHITE);
   for (int i = 0; i <= mapNo; i++) {
     image.drawString("Map " + (i + 1) + ": " + scores[i], 460, 80 + (i * 28));
   }
 }
Ejemplo n.º 14
0
 public void fade(int f) {
   if (f > 255) {
     f = 255;
   } else if (f < 0) {
     f = 0;
   }
   fadeColor = new Color(0, 0, 0, f);
   fade.clear();
   fade.setColor(fadeColor);
   fade.fillRect(0, 0, 1280, 720);
   setImage(fade);
 }
Ejemplo n.º 15
0
  /**
   * Change the background colour of this Button
   *
   * @param background The colour to use
   */
  public void update(Color background) {
    GreenfootImage tempTextImage =
        new GreenfootImage(buttonText, textSize, Color.BLACK, background);

    myImage = new GreenfootImage(tempTextImage.getWidth() + 8, tempTextImage.getHeight() + 8);
    myImage.setColor(Color.BLACK);
    myImage.fill();
    myImage.drawImage(tempTextImage, 4, 4);

    myImage.setColor(Color.BLACK);
    myImage.drawRect(0, 0, tempTextImage.getWidth() + 7, tempTextImage.getHeight() + 7);
    setImage(myImage);
  }
Ejemplo n.º 16
0
 /**
  * Return the world's background image. The image may be used to draw onto the world's background.
  *
  * @return The background image
  */
 public GreenfootImage getBackground() {
   if (backgroundImage == null) {
     backgroundImage = new GreenfootImage(getWidthInPixels(), getHeightInPixels());
     backgroundImage.setColor(DEFAULT_BACKGROUND_COLOR);
     backgroundImage.fill();
     backgroundIsClassImage = false;
   } else if (backgroundIsClassImage) {
     // Make the image a copy of the original to avoid modifications
     // to the original.
     backgroundImage = backgroundImage.getCopyOnWriteClone();
     backgroundIsClassImage = false;
   }
   return backgroundImage;
 }
Ejemplo n.º 17
0
  /**
   * Change the text displayed on this Button
   *
   * @param text String to display
   */
  public void update(String text) {
    Color buttonFill = new Color(242, 206, 27); // yellow fill colour

    buttonText = text;
    GreenfootImage tempTextImage = new GreenfootImage(text, 20, Color.BLACK, buttonFill);
    myImage = new GreenfootImage(tempTextImage.getWidth() + 8, tempTextImage.getHeight() + 8);
    myImage.setColor(Color.BLACK);
    myImage.fill();
    myImage.drawImage(tempTextImage, 4, 4);

    myImage.setColor(Color.BLACK);
    myImage.drawRect(0, 0, tempTextImage.getWidth() + 7, tempTextImage.getHeight() + 7);
    setImage(myImage);
  }
Ejemplo n.º 18
0
  /**
   * Return the color at the centre of the cell. To paint a color, you need to get the background
   * image for the world and paint on that.
   *
   * @param x The x coordinate of the cell.
   * @param y The y coordinate of the cell.
   * @see #getBackground()
   * @throws IndexOutOfBoundsException If the location is not within the world bounds. If there is
   *     no background image at the location it will return Color.WHITE.
   */
  public Color getColorAt(int x, int y) {
    ensureWithinXBounds(x);
    ensureWithinYBounds(y);

    int xPixel = (int) Math.floor(getCellCenter(x));
    int yPixel = (int) Math.floor(getCellCenter(y));

    if (xPixel >= backgroundImage.getWidth()) {
      return DEFAULT_BACKGROUND_COLOR;
    }
    if (yPixel >= backgroundImage.getHeight()) {
      return DEFAULT_BACKGROUND_COLOR;
    }

    return backgroundImage.getColorAt(xPixel, yPixel);
  }
Ejemplo n.º 19
0
 // constructor Virus
 public Virus(Score score) {
   counter = score;
   virus = getImage();
   virus.mirrorHorizontally();
   int level = counter.level;
   speed = level + 2;
 }
Ejemplo n.º 20
0
  public AnswerMedium(String txt) {

    ansmed = txt;

    // First we create an image that will hold our largest answer, so that we can
    // align all the text to the left.
    GreenfootImage imgTxt = new GreenfootImage(300, 30);
    // if we include "java.awt." in the next line, we don't have to import the class
    // See http://www.greenfoot.org/topics/187
    imgTxt.setColor(java.awt.Color.black);

    imgTxt.setFont(new java.awt.Font("Helvetica", java.awt.Font.PLAIN, 14));
    imgTxt.drawString(ansmed, 1, 15);

    // TextImage t=new TextImage(ans);
    setImage(imgTxt);
  }
Ejemplo n.º 21
0
  // Draws the minimap
  public void draw() {

    // A new image is created for the minimap, drawn onto, and the applied as the Actor's image
    // Drawing of the minimap is done this way so that there won't be any artifacting when draw() is
    // called by a thread other than the main thread
    GreenfootImage image = new GreenfootImage(FRAME.width, FRAME.height);
    image.setTransparency(150);

    // Get map
    ArrayList<ArrayList<Tile>> map = Data.tiles();

    // Position of the minimap tile being drawn
    int x = 0;
    int y = 0;

    // Iterate through every map tile and draw it onto minimap, adjusting the position for the next
    // tile with each iteration
    // Minimap is drawn column by column
    for (int i = 0; i < Map.getInstance().SIZE_COLUMNS; i++) {
      for (int j = 0; j < Map.getInstance().SIZE_ROWS; j++) {

        Tile tile = (Tile) map.get(i).get(j);
        // Get the color to draw based on either the tile's type or zone (if zoned)
        if (tile.zone() > 0) {
          image.setColor(colorForTileOfZone(tile.zone()));
        } else {
          image.setColor(colorForTileOfType(tile.type()));
        }

        image.fillRect(x, y, tileSize, tileSize); // Minimap tiles are 2px * 2px
        y += tileSize;
      }

      // Reset Y to top of the column
      y = 0;

      x += tileSize;
    }

    setImage(image);
  }
Ejemplo n.º 22
0
  /**
   * Return the color at the center of the cell. To paint a color, you need to get the background
   * image for the world and paint on that.
   *
   * @see #getBackground()
   * @throws IndexOutOfBoundsException If the location is not within the world bounds. If there is
   *     no background image at the location it will return Color.WHITE.
   */
  public Color getColorAt(int x, int y) {
    ensureWithinXBounds(x);
    ensureWithinYBounds(y);

    int xPixel = (int) Math.floor(getCellCenter(x));
    int yPixel = (int) Math.floor(getCellCenter(y));

    // Take tiling into account
    if (isTiled()) {
      xPixel = xPixel % backgroundImage.getWidth();
      yPixel = yPixel % backgroundImage.getHeight();
    }

    // TODO if it is not tiled, and outside, what should be returned? BGcolor? Null?
    if (xPixel >= backgroundImage.getWidth()) {
      return Color.WHITE;
    }
    if (yPixel >= backgroundImage.getHeight()) {
      return Color.WHITE;
    }

    return backgroundImage.getColorAt(xPixel, yPixel);
  }
Ejemplo n.º 23
0
  /** Load the images */
  private void loadImages() {
    GifDecoder decode = new GifDecoder();
    decode.read(file);
    int numFrames = decode.getFrameCount();
    if (numFrames > 0) {
      images = new GreenfootImage[numFrames];
      delay = new int[numFrames];
    } else {
      images = new GreenfootImage[1];
      images[0] = new GreenfootImage(1, 1);
    }

    for (int i = 0; i < numFrames; i++) {
      GreenfootImage image =
          new GreenfootImage(decode.getFrame(i).getWidth(), decode.getFrame(i).getHeight());
      BufferedImage frame = image.getAwtImage();
      Graphics2D g = (Graphics2D) frame.getGraphics();
      g.drawImage(decode.getFrame(i), null, 0, 0);
      delay[i] = decode.getDelay(i);
      images[i] = image;
    }
    time = System.currentTimeMillis();
  }
Ejemplo n.º 24
0
 private void drawBox() {
   amarelo = new Color(255, 188, 0);
   laranja = new Color(255, 133, 0);
   imgHelp = getImage();
   imgHelp.setColor(laranja);
   imgHelp.fill();
   imgHelp.scale(200, 50);
   imgHelp.setColor(amarelo);
   int margem = 5;
   int largura = imgHelp.getWidth() - 2 * margem;
   int altura = imgHelp.getHeight() - 2 * margem;
   imgHelp.fillRect(margem, margem, largura, altura);
 }
Ejemplo n.º 25
0
 // Method runs to update number of hearts on screen.
 private void updateImage() {
   int heightOne = (int) height; // value of height for hearts recasted
   GreenfootImage image =
       new GreenfootImage(fullLives * heightOne + 64, heightOne); // create the image's object
   image.drawRect(0, 0, image.getWidth() - 1, image.getHeight() - 1); // frame added to the object
   GreenfootImage hearts = new GreenfootImage("hearts_Ahrenn.png"); // obtains image of heart
   hearts.scale(4 * heightOne / 6, 4 * heightOne / 6); // resizes image of heart
   for (int i = 0; i < lives; i++) {
     image.drawImage(
         hearts,
         4 * +4 + i * 9 * 4,
         4); // adds a specific number of hearts to image based on number of lives remaining
   }
   setImage(image); // Actually makes the image look like how the values above desire it to be.
 }
Ejemplo n.º 26
0
 // Method runs to update number of mana potions on screen.
 private void updateImageTwo() {
   GreenfootImage imageTwo =
       new GreenfootImage(fullMana * heightTwo + 64, heightTwo); // create the image's object
   imageTwo.drawRect(
       0, 0, imageTwo.getWidth() - 1, imageTwo.getHeight() - 1); // frame added to the object
   GreenfootImage potions = new GreenfootImage("mana_Ahrenn.png"); // obtains image of potion
   potions.scale(4 * heightTwo / 6, 4 * heightTwo / 6); // resizes image of potion
   for (int i = 0; i < mana; i++) {
     imageTwo.drawImage(
         potions,
         4 * +4 + i * 9 * 4,
         4); // adds a specific number of potions to image based on amount of mana remaining
   }
   setImage(imageTwo); // Actually makes the image look like how the values above desire it to be.
 }
Ejemplo n.º 27
0
  private void animatePlayer(boolean moveDir) {
    if (moveDir == true && Greenfoot.isKeyDown("d")) {
      if (frame < 1 * delay) {
        setImage(base);
      } else if (frame < 2 * delay) {
        setImage(run2r);
      } else if (frame < 3 * delay) {
        setImage(run3r);
      } else if (frame < 4 * delay) {
        setImage(run4r);
        frame = 1;
        return;
      }
      frame++;
    }

    if (moveDir == false && Greenfoot.isKeyDown("a")) {
      if (frame < 1 * delay) {
        setImage(base);
      } else if (frame < 2 * delay) {
        GreenfootImage run2l = new GreenfootImage(run2r);
        run2l.mirrorHorizontally();
        setImage(run2l);
      } else if (frame < 3 * delay) {
        GreenfootImage run3l = new GreenfootImage(run3r);
        run3l.mirrorHorizontally();
        setImage(run3l);
      } else if (frame < 4 * delay) {
        GreenfootImage run4l = new GreenfootImage(run4r);
        run4l.mirrorHorizontally();
        setImage(run4l);
        frame = 1;
        return;
      }
      frame++;
    }
  }
Ejemplo n.º 28
0
  /** Update the image on screen to show the current value. */
  private void updateImage() {
    GreenfootImage image = new GreenfootImage(background);
    GreenfootImage text =
        new GreenfootImage(prefix + "Points: " + value, 22, Color.MAGENTA, transparent);

    if (text.getWidth() > image.getWidth() - 20) {
      image.scale(text.getWidth() + 20, image.getHeight());
    }

    image.drawImage(
        text, (image.getWidth() - text.getWidth()) / 2, (image.getHeight() - text.getHeight()) / 2);
    setImage(image);
  }
Ejemplo n.º 29
0
  /** Draws the count down bar for status duration */
  private void drawBar() {

    myImage.drawImage(bar, 0, 40); // draws the bar image on myImage
  }
 public AmericanFootball() {
   GreenfootImage image = getImage();
   image.scale(75, 75);
   setImage(image);
 }