Ejemplo n.º 1
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.º 2
0
  @Subscribe
  public void listen(MenuItemEvent event) {
    CSLogger.sharedLogger().finer("\"" + event.message() + "\" was selected.");

    // * ZONING *
    if (event.message() == ResidentialZone.NAME) {
      Map.getInstance().selection().setSelectionMode(true);
      Map.getInstance().selection().setUnacceptedTypes(new int[] {Tile.WATER});
      Map.getInstance()
          .selection()
          .setUnacceptedZones(
              new int[] {ResidentialZone.TYPE_ID, CommercialZone.TYPE_ID, IndustrialZone.TYPE_ID});
      Map.getInstance()
          .selection()
          .setSize(ResidentialZone.SIZE_WIDTH, ResidentialZone.SIZE_HEIGHT);
      Zone.setPendingOp(ResidentialZone.TYPE_ID);
      City.getInstance()
          .setHint(
              new Hint("Select the areas you wish to zone as residential. Press 'ESC' when done."));
    } else if (event.message() == IndustrialZone.NAME) {
      Map.getInstance().selection().setSelectionMode(true);
      Map.getInstance().selection().setAcceptedTypes(new int[] {Tile.GROUND});
      Map.getInstance()
          .selection()
          .setUnacceptedZones(
              new int[] {ResidentialZone.TYPE_ID, CommercialZone.TYPE_ID, IndustrialZone.TYPE_ID});
      Map.getInstance().selection().setSize(IndustrialZone.SIZE_WIDTH, IndustrialZone.SIZE_HEIGHT);
      Zone.setPendingOp(IndustrialZone.TYPE_ID);
      City.getInstance()
          .setHint(
              new Hint("Select the areas you wish to zone as industrial. Press 'ESC' when done."));
    } else if (event.message() == CommercialZone.NAME) {
      Map.getInstance().selection().setSelectionMode(true);
      Map.getInstance().selection().setAcceptedTypes(new int[] {Tile.GROUND});
      Map.getInstance()
          .selection()
          .setUnacceptedZones(
              new int[] {ResidentialZone.TYPE_ID, CommercialZone.TYPE_ID, IndustrialZone.TYPE_ID});
      Map.getInstance().selection().setSize(CommercialZone.SIZE_WIDTH, CommercialZone.SIZE_HEIGHT);
      Zone.setPendingOp(CommercialZone.TYPE_ID);
      City.getInstance()
          .setHint(
              new Hint("Select the areas you wish to zone as commercial. Press 'ESC' when done."));
    }
    // * TRANSPORTATION *
    else if (event.message() == Street.NAME) {
      Map.getInstance().selection().setSelectionMode(true);
      Map.getInstance()
          .selection()
          .setAcceptedTypes(
              new int[] {Tile.GROUND, Tile.POWERLINE_H, Tile.POWERLINE_V, Tile.WATER});
      Map.getInstance()
          .selection()
          .setUnacceptedZones(
              new int[] {ResidentialZone.TYPE_ID, CommercialZone.TYPE_ID, IndustrialZone.TYPE_ID});
      Map.getInstance().selection().setSize(Street.SIZE_WIDTH, Street.SIZE_HEIGHT);
      Road.setPendingOp(Street.TYPE_ID);
      City.getInstance()
          .setHint(
              new Hint("Click on the areas you wish to build a road on. Press 'ESC' when done."));
    }
    // * POWER *
    else if (event.message() == PowerLine.NAME) {
      Map.getInstance().selection().setSelectionMode(true);
      Map.getInstance()
          .selection()
          .setAcceptedTypes(new int[] {Tile.GROUND, Tile.STREET_H, Tile.STREET_V});
      Map.getInstance()
          .selection()
          .setUnacceptedZones(
              new int[] {ResidentialZone.TYPE_ID, CommercialZone.TYPE_ID, IndustrialZone.TYPE_ID});
      Map.getInstance().selection().setSize(PowerLine.SIZE_WIDTH, PowerLine.SIZE_HEIGHT);
      PowerGrid.setPendingOp(PowerLine.TYPE_ID);
      City.getInstance()
          .setHint(
              new Hint(
                  "Click on the areas you wish to build a power line on. Press 'ESC' when done."));
    } else if (event.message() == CoalPowerPlant.NAME) {
      Map.getInstance().selection().setSelectionMode(true);
      Map.getInstance().selection().setAcceptedTypes(new int[] {Tile.GROUND});
      Map.getInstance()
          .selection()
          .setUnacceptedZones(
              new int[] {ResidentialZone.TYPE_ID, CommercialZone.TYPE_ID, IndustrialZone.TYPE_ID});
      Map.getInstance().selection().setSize(CoalPowerPlant.SIZE_WIDTH, CoalPowerPlant.SIZE_HEIGHT);
      Zone.setPendingOp(CoalPowerPlant.TYPE_ID);
      City.getInstance()
          .setHint(
              new Hint(
                  "Select the areas where you wish to build a coal power plant. Press 'ESC' when done."));
    } else if (event.message() == NuclearPowerPlant.NAME) {
      Map.getInstance().selection().setSelectionMode(true);
      Map.getInstance().selection().setAcceptedTypes(new int[] {Tile.GROUND});
      Map.getInstance()
          .selection()
          .setUnacceptedZones(
              new int[] {ResidentialZone.TYPE_ID, CommercialZone.TYPE_ID, IndustrialZone.TYPE_ID});
      Map.getInstance()
          .selection()
          .setSize(NuclearPowerPlant.SIZE_WIDTH, NuclearPowerPlant.SIZE_HEIGHT);
      Zone.setPendingOp(NuclearPowerPlant.TYPE_ID);
      City.getInstance()
          .setHint(
              new Hint(
                  "Select the areas where you wish to build a nuclear power plant. Press 'ESC' when done."));
    }
    // * PROTECTION *
    else if (event.message() == FireStation.NAME) {
      Map.getInstance().selection().setSelectionMode(true);
      Map.getInstance().selection().setAcceptedTypes(new int[] {Tile.GROUND});
      Map.getInstance()
          .selection()
          .setUnacceptedZones(
              new int[] {ResidentialZone.TYPE_ID, CommercialZone.TYPE_ID, IndustrialZone.TYPE_ID});
      Map.getInstance().selection().setSize(FireStation.SIZE_WIDTH, FireStation.SIZE_HEIGHT);
      Zone.setPendingOp(FireStation.TYPE_ID);
      City.getInstance()
          .setHint(
              new Hint(
                  "Select the areas where you wish to build a fire station. Press 'ESC' when done."));
    } else if (event.message() == PoliceStation.NAME) {
      Map.getInstance().selection().setSelectionMode(true);
      Map.getInstance().selection().setAcceptedTypes(new int[] {Tile.GROUND});
      Map.getInstance()
          .selection()
          .setUnacceptedZones(
              new int[] {ResidentialZone.TYPE_ID, CommercialZone.TYPE_ID, IndustrialZone.TYPE_ID});
      Map.getInstance().selection().setSize(PoliceStation.SIZE_WIDTH, PoliceStation.SIZE_HEIGHT);
      Zone.setPendingOp(PoliceStation.TYPE_ID);
      City.getInstance()
          .setHint(
              new Hint(
                  "Select the areas where you wish to build a police station. Press 'ESC' when done."));
    }
    // * RECREATION *
    else if (event.message() == Park.NAME) {
      Map.getInstance().selection().setSelectionMode(true);
      Map.getInstance().selection().setAcceptedTypes(new int[] {Tile.GROUND});
      Map.getInstance()
          .selection()
          .setUnacceptedZones(
              new int[] {ResidentialZone.TYPE_ID, CommercialZone.TYPE_ID, IndustrialZone.TYPE_ID});
      Map.getInstance().selection().setSize(Park.SIZE_WIDTH, Park.SIZE_HEIGHT);
      Recreation.setPendingOp(Park.TYPE_ID);
      City.getInstance()
          .setHint(
              new Hint("Select the areas where you wish to build a park. Press 'ESC' when done."));
    } else if (event.message() == Stadium.NAME) {
      Map.getInstance().selection().setSelectionMode(true);
      Map.getInstance().selection().setAcceptedTypes(new int[] {Tile.GROUND});
      Map.getInstance()
          .selection()
          .setUnacceptedZones(
              new int[] {ResidentialZone.TYPE_ID, CommercialZone.TYPE_ID, IndustrialZone.TYPE_ID});
      Map.getInstance().selection().setSize(Stadium.SIZE_WIDTH, Stadium.SIZE_HEIGHT);
      Zone.setPendingOp(Stadium.TYPE_ID);
      City.getInstance()
          .setHint(
              new Hint(
                  "Select the areas where you wish to build a stadium. Press 'ESC' when done."));
    }
    // * TOOLS *
    else if (event.message() == Bulldozer.NAME) {
      Map.getInstance().selection().setSelectionMode(true);
      Map.getInstance().selection().setUnacceptedTypes(new int[] {Tile.WATER});
      Map.getInstance().selection().setSize(Bulldozer.SIZE_WIDTH, Bulldozer.SIZE_HEIGHT);
      Tool.setPendingOp(Bulldozer.TYPE_ID);
      City.getInstance()
          .setHint(new Hint("Select the areas you wish to bulldoze. Press 'ESC' when done."));
    } else if (event.message() == Query.NAME) {
      Map.getInstance().selection().setSelectionMode(true);
      Tool.setPendingOp(Query.TYPE_ID);
      City.getInstance()
          .setHint(
              new Hint(
                  "Click on zones to query them. Click on the popup to dismiss it. Press 'ESC' when done."));
    }
  }