Beispiel #1
0
 private void drawTooltip(FishState fishUnderMouse) {
   int tooltipHeight = 20, tooltipBottomMargin = 10;
   bufferGraphics.setColor(Color.WHITE);
   bufferGraphics.fillRect(
       0, buffer.getHeight() - tooltipHeight, buffer.getWidth(), tooltipHeight);
   bufferGraphics.setColor(Color.BLACK);
   if (fishUnderMouse != null) {
     bufferGraphics.drawString(
         String.format(
             "Frame %d ID %d, Nut %.2f, Change %.2f, Speed %.2f, Dir %s",
             state.seqID,
             fishUnderMouse.fish_id,
             fishUnderMouse.getNutrients(),
             Rules.decay(fishUnderMouse),
             fishUnderMouse.getSpeed(),
             fishUnderMouse.getRudderVector()),
         5,
         buffer.getHeight() - tooltipBottomMargin);
   } else {
     bufferGraphics.drawString(
         String.format(
             "Frame %d, Fish %d, Controllers %d, Max fish %d, Max nut %.2f",
             state.seqID,
             state.getNumFish(),
             state.getNumControllers(),
             state.getMaxFish(),
             state.getMaxNutrients()),
         5,
         buffer.getHeight() - tooltipBottomMargin);
   }
 }
Beispiel #2
0
 private FishState drawFish() {
   FishState fishUnderMouse = null;
   for (FishState fs : state.getFish()) {
     if (fs.isAlive()) {
       Vector pos = fs.getPosition();
       // Draw tail and outline according to speed
       int tailBrightness = (int) ((double) fs.getSpeed() / Rules.MAX_SPEED * 255);
       bufferGraphics.setColor(Color.BLACK);
       bufferGraphics.drawLine(
           (int) pos.x,
           (int) pos.y,
           (int) (pos.x - fs.getRudderVector().x * fs.getRadius() * 2),
           (int) (pos.y - fs.getRudderVector().y * fs.getRadius() * 2));
       bufferGraphics.fillOval(
           (int) pos.x - fs.getRadius(),
           (int) pos.y - fs.getRadius(),
           2 * fs.getRadius(),
           2 * fs.getRadius());
       bufferGraphics.setColor(fishtank.getColor(fs.fish_id));
       bufferGraphics.fillOval(
           (int) pos.x - fs.getRadius() + 1,
           (int) pos.y - fs.getRadius() + 1,
           2 * fs.getRadius() - 2,
           2 * fs.getRadius() - 2);
     }
     if (fs.getPosition().minus(mousePosition).length() < fs.getRadius()) {
       fishUnderMouse = fs;
     }
   }
   return fishUnderMouse;
 }