コード例 #1
0
ファイル: Score.java プロジェクト: praetore/Project-2
 public void act() {
   GreenfootImage img = new GreenfootImage(50, 50);
   getScore();
   String i = Integer.toString(score);
   img.drawString(i, 20, 20);
   this.setImage(img);
 }
コード例 #2
0
ファイル: Pizza.java プロジェクト: objetos15161/Delicious
 /** constructor de variables de la clase pizza */
 public Pizza() {
   dir = 1;
   vel = 3;
   GreenfootImage image = getImage();
   image.scale(30, 30);
   setImage(image);
 }
コード例 #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
  }
コード例 #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
  }
コード例 #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();
  }
コード例 #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();
  }
コード例 #7
0
ファイル: World.java プロジェクト: rma93/greenfoot
  /**
   * 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;
    }
  }
コード例 #8
0
  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;
    }
  }
コード例 #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
  }
コード例 #10
0
ファイル: Player.java プロジェクト: extendsLcc/Space-Shooter
  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)]);
  }
コード例 #11
0
ファイル: Shield.java プロジェクト: ThiGod/CMPE202DoodleDown
  public Shield() {
    super();

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

    effectiveTimeLeft = 500;
  }
コード例 #12
0
ファイル: Helpbt.java プロジェクト: objetos15161/Survival-Z
 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);
 }
コード例 #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));
   }
 }
コード例 #14
0
ファイル: FadeIn.java プロジェクト: jsoncylu/kumbala
 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);
 }
コード例 #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);
  }
コード例 #16
0
ファイル: World.java プロジェクト: rma93/greenfoot
 /**
  * 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;
 }
コード例 #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);
  }
コード例 #18
0
ファイル: World.java プロジェクト: rma93/greenfoot
  /**
   * 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);
  }
コード例 #19
0
ファイル: Virus.java プロジェクト: fnitschmann/Kill-Windows
 // constructor Virus
 public Virus(Score score) {
   counter = score;
   virus = getImage();
   virus.mirrorHorizontally();
   int level = counter.level;
   speed = level + 2;
 }
コード例 #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);
  }
コード例 #21
0
ファイル: Minimap.java プロジェクト: felixmo/CitySim
  // 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);
  }
コード例 #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);
  }
コード例 #23
0
ファイル: GifImage.java プロジェクト: Zackel/Soul-Medievil
  /** 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();
  }
コード例 #24
0
ファイル: Helpbt.java プロジェクト: objetos15161/Survival-Z
 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);
 }
コード例 #25
0
ファイル: ASWidget.java プロジェクト: ahrennsiva/HealthWidget
 // 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.
 }
コード例 #26
0
ファイル: ASWidget.java プロジェクト: ahrennsiva/HealthWidget
 // 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.
 }
コード例 #27
0
ファイル: Player.java プロジェクト: Conanap/HS-Projects
  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++;
    }
  }
コード例 #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);
  }
コード例 #29
0
  /** Draws the count down bar for status duration */
  private void drawBar() {

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