public void Checkplanets() {
   GreenfootImage star = new GreenfootImage("Images/star.png");
   starW = star.getWidth(); // = 10
   starH = star.getHeight(); // = 10
   if (!topleft) { // 3 random stars if planets are not in the top left
     for (int x = 0; x < 3; x++) {
       starX = rgen.nextInt(Q1X);
       starY = rgen.nextInt(Q1Y);
       getBackground().drawImage(star, starX, starY);
     }
   }
   if (!topright) {
     for (int x = 0; x < 3; x++) {
       starX = rgen.nextInt(Q2X - Q1X) + Q1X;
       starY = rgen.nextInt(Q2Y);
       getBackground().drawImage(star, starX, starY);
     }
   }
   if (!bottomleft) {
     for (int x = 0; x < 3; x++) {
       starX = rgen.nextInt(Q1X);
       starY = rgen.nextInt(Q2Y) + Q2Y;
       getBackground().drawImage(star, starX, starY);
     }
   }
   if (!bottomright) {
     for (int x = 0; x < 3; x++) {
       starX = rgen.nextInt(Q1X) + Q1X;
       starY = rgen.nextInt(Q2Y) + Q2Y;
       getBackground().drawImage(star, starX, starY);
     }
   }
 }
Beispiel #2
0
 /** constructor de variables de la clase pizza */
 public Pizza() {
   dir = 1;
   vel = 3;
   GreenfootImage image = getImage();
   image.scale(30, 30);
   setImage(image);
 }
  public TrafficWorld() {
    super(WORLD_WIDTH, WORLD_HEIGHT, CELL_SIZE);
    GreenfootImage background = this.getBackground();
    background.setColor(Color.GREEN);
    background.fill();

    for (int n = 0; n < Y_ROADS; n++) {
      int Y_INC = (((Road.Y_GAP_SIZE + Road.ROAD_HEIGHT) * n) + (Road.ROAD_HEIGHT / 2));

      HorizontalRoads[n] = new Road();
      this.addObject(HorizontalRoads[n], (WORLD_WIDTH / 2), Y_INC);
    }

    for (int n = 0; n < X_ROADS; n++) {
      int X_INC = (((Road.X_GAP_SIZE + Road.ROAD_HEIGHT) * n) + (Road.ROAD_HEIGHT / 2));

      VerticalRoads[n] = new Road();
      this.addObject(VerticalRoads[n], X_INC, (WORLD_HEIGHT / 2));
      VerticalRoads[n].turn(90);
    }

    for (int x = 0; x < X_ROADS; x++) {
      for (int y = 0; y < Y_ROADS; y++) {
        Intersection intersection = new Intersection();
        this.addObject(intersection, VerticalRoads[x].getX(), HorizontalRoads[y].getY());
        intersection.addLights();
      }
    }
  }
  /** 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
  }
  /** 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
  }
  /** Draws status bar for Invincibility */
  private void drawStun() {

    myImage.setColor(Color.YELLOW);
    myImage.drawString("Invincibility", 10, 30);
    bar.setColor(Color.YELLOW);
    bar.fill();
  }
Beispiel #7
0
 public void act() {
   GreenfootImage img = new GreenfootImage(50, 50);
   getScore();
   String i = Integer.toString(score);
   img.drawString(i, 20, 20);
   this.setImage(img);
 }
  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;
    }
  }
  /** 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();
  }
Beispiel #10
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
  }
Beispiel #11
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)]);
  }
Beispiel #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);
 }
Beispiel #13
0
  public Shield() {
    super();

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

    effectiveTimeLeft = 500;
  }
 /**
  * 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));
   }
 }
Beispiel #15
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);
 }
Beispiel #16
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);
  }
Beispiel #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);
  }
Beispiel #18
0
 // constructor Virus
 public Virus(Score score) {
   counter = score;
   virus = getImage();
   virus.mirrorHorizontally();
   int level = counter.level;
   speed = level + 2;
 }
  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);
  }
  /**
   * Paints all the objects.
   *
   * <p>Must be synchronized on the World.lock.
   */
  public void paintObjects(Graphics2D g) {
    Set<Actor> objects = WorldVisitor.getObjectsListInPaintOrder(world);
    int paintSeq = 0;
    for (Iterator<Actor> iter = objects.iterator(); iter.hasNext(); ) {
      Actor thing = iter.next();
      int cellSize = WorldVisitor.getCellSize(world);

      GreenfootImage image = ActorVisitor.getDisplayImage(thing);
      if (image != null) {
        ActorVisitor.setLastPaintSeqNum(thing, paintSeq++);

        double halfWidth = image.getWidth() / 2.;
        double halfHeight = image.getHeight() / 2.;

        AffineTransform oldTx = null;
        try {
          int ax = ActorVisitor.getX(thing);
          int ay = ActorVisitor.getY(thing);
          double xCenter = ax * cellSize + cellSize / 2.;
          int paintX = (int) Math.floor(xCenter - halfWidth);
          double yCenter = ay * cellSize + cellSize / 2.;
          int paintY = (int) Math.floor(yCenter - halfHeight);

          int rotation = ActorVisitor.getRotation(thing);
          if (rotation != 0) {
            // don't bother transforming if it is not rotated at
            // all.
            oldTx = g.getTransform();
            g.rotate(Math.toRadians(rotation), xCenter, yCenter);
          }

          ImageVisitor.drawImage(image, g, paintX, paintY, this, true);
        } catch (IllegalStateException e) {
          // We get this if the object has been removed from the
          // world. That can happen when interactively invoking a
          // method that removes an object from the world, while the
          // scenario is executing.
        }

        // Restore the old state of the graphics
        if (oldTx != null) {
          g.setTransform(oldTx);
        }
      }
    }
  }
Beispiel #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);
  }
Beispiel #22
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();
  }
Beispiel #23
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);
 }
Beispiel #24
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.
 }
Beispiel #25
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.
 }
Beispiel #26
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++;
    }
  }
Beispiel #27
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);
 }
Beispiel #29
0
 private void drawImage() {
   GreenfootImage image = getImage();
   image.clear();
   image.drawImage(new GreenfootImage("images/Ticker.png"), 0, 0);
   image.drawString(Integer.toString(seconds), 52, 75);
 }
  /** 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);
  }