public void setupPortrayals() {
    AgentsForage af = (AgentsForage) state;
    // obstacle portrayal needs no setup
    foodPortrayal.setField(af.ground);
    foodPortrayal.setPortrayalForAll(
        new CircledPortrayal2D(
            new LabelledPortrayal2D(
                new OvalPortrayal2D(Color.blue, af.FOOD_DIAMETER, true),
                af.AGENT_DIAMETER,
                null,
                Color.red,
                true), // 'null' means to display toString() for underlying object, rather than a
                       // predefined label
            0,
            af.FOOD_DIAMETER + 10,
            Color.DARK_GRAY,
            true));

    agentPortrayal.setField(af.agentgrid);
    agentPortrayal.setPortrayalForAll(
        new CircledPortrayal2D(
            new LabelledPortrayal2D(
                new OrientedPortrayal2D(
                    new OvalPortrayal2D(af.AGENT_DIAMETER), 0, af.AGENT_DIAMETER),
                af.AGENT_DIAMETER,
                null,
                Color.blue,
                true), // 'null' means to display toString() for underlying object, rather than a
                       // predefined label
            0,
            af.AGENT_DIAMETER + 10,
            Color.green,
            true));

    summaryPortrayal.setField(af.summarygrid);
    // summaryPortrayal.setPortrayalForAll( new
    // sim.portrayal.simple.RectanglePortrayal2D(Color.green) );
    summaryPortrayal.setMap(
        new sim.util.gui.SimpleColorMap(0, 100, new Color(0, 0, 0, 0), new Color(0, 255, 0, 255)));

    // reschedule the displayer
    display.reset();
    display2.reset();
    // redraw the display
    display.repaint();
    display2.repaint();
  }
Example #2
0
  public void setupPortrayals() {
    PacMan pacman = (PacMan) state;

    // Create the agent portrayal
    agentPortrayal.setField(pacman.agents);

    // The Pac.  Note that you can have multiple pacs, each with different tags, and set it up like
    // below to display them with different colors.  For now we've got it set to one pac.
    agentPortrayal.setPortrayalForClass(
        Pac.class,
        new PacPortrayal(pacman, Color.yellow) {
          public void draw(Object object, Graphics2D graphics, DrawInfo2D info) {
            if (((Pac) object).tag == 0) color = Color.yellow;
            else color = Color.green;
            super.draw(object, graphics, info);
          }
        });

    // Blinky is a red ghos unless he's scared, then he's a blue ghost.
    agentPortrayal.setPortrayalForClass(
        Blinky.class,
        new FacetedPortrayal2D(
            new SimplePortrayal2D[] {
              new ImagePortrayal2D(this.getClass(), "images/blinkyu.png", 2),
              new ImagePortrayal2D(this.getClass(), "images/blinkyl.png", 2),
              new ImagePortrayal2D(this.getClass(), "images/blinkyd.png", 2),
              new ImagePortrayal2D(this.getClass(), "images/blinkyr.png", 2),
              new ImagePortrayal2D(this.getClass(), "images/frightened.png", 2),
              new ImagePortrayal2D(this.getClass(), "images/frightened2.png", 2),
            }));

    // Pinky is a pink ghost unless he's scared, then he's a blue ghost.
    agentPortrayal.setPortrayalForClass(
        Pinky.class,
        new FacetedPortrayal2D(
            new SimplePortrayal2D[] {
              new ImagePortrayal2D(this.getClass(), "images/pinkyu.png", 2),
              new ImagePortrayal2D(this.getClass(), "images/pinkyl.png", 2),
              new ImagePortrayal2D(this.getClass(), "images/pinkyd.png", 2),
              new ImagePortrayal2D(this.getClass(), "images/pinkyr.png", 2),
              new ImagePortrayal2D(this.getClass(), "images/frightened.png", 2),
              new ImagePortrayal2D(this.getClass(), "images/frightened2.png", 2),
            }));

    // Inky is a cyan ghost unless he's scared, then he's a blue ghost.
    agentPortrayal.setPortrayalForClass(
        Inky.class,
        new FacetedPortrayal2D(
            new SimplePortrayal2D[] {
              new ImagePortrayal2D(this.getClass(), "images/inkyu.png", 2),
              new ImagePortrayal2D(this.getClass(), "images/inkyl.png", 2),
              new ImagePortrayal2D(this.getClass(), "images/inkyd.png", 2),
              new ImagePortrayal2D(this.getClass(), "images/inkyr.png", 2),
              new ImagePortrayal2D(this.getClass(), "images/frightened.png", 2),
              new ImagePortrayal2D(this.getClass(), "images/frightened2.png", 2),
            }));

    // Clyde is a orange ghost unless he's scared, then he's a ghost rectangle.
    agentPortrayal.setPortrayalForClass(
        Clyde.class,
        new FacetedPortrayal2D(
            new SimplePortrayal2D[] {
              new ImagePortrayal2D(this.getClass(), "images/clydeu.png", 2),
              new ImagePortrayal2D(this.getClass(), "images/clydel.png", 2),
              new ImagePortrayal2D(this.getClass(), "images/clyded.png", 2),
              new ImagePortrayal2D(this.getClass(), "images/clyder.png", 2),
              new ImagePortrayal2D(this.getClass(), "images/frightened.png", 2),
              new ImagePortrayal2D(this.getClass(), "images/frightened2.png", 2),
            }));

    // Create the dot portrayal (also the energizers)
    dotPortrayal.setField(pacman.dots);

    // Energizers are big
    dotPortrayal.setPortrayalForClass(Energizer.class, new OvalPortrayal2D(Color.white, 1));

    // dots are small
    dotPortrayal.setPortrayalForClass(Dot.class, new OvalPortrayal2D(Color.white, 0.4));

    // set up the maze portrayal
    mazePortrayal.setPortrayalForAll(new MazeCellPortrayal(pacman.maze));
    mazePortrayal.setField(pacman.maze);

    // add the RateAdjuster
    scheduleRepeatingImmediatelyAfter(new RateAdjuster(FRAMES_PER_SECOND));

    // reschedule the displayer
    display.reset();

    // redraw the display
    display.repaint();
  }