コード例 #1
0
ファイル: Simulation.java プロジェクト: RuthRainbow/anemone
  public void mouseMoved() {
    if (PLACE_MODE) {
      int simMouseX = (int) ((float) (mouseX - offsetX) / zoomLevel);
      int simMouseY = (int) ((float) (mouseY - offsetY) / zoomLevel);
      ArrayList<Wall> walls = env.getAllWalls();
      Wall w = walls.get(walls.size() - 1);

      w.getEnd().x = simMouseX;
      w.getEnd().y = simMouseY;
    }
  }
コード例 #2
0
ファイル: Simulation.java プロジェクト: RuthRainbow/anemone
  private void drawSimulation(PApplet canvas) {
    pushMatrix();
    translate(offsetX, offsetY);
    scale(zoomLevel);

    ArrayList<Agent> agents = env.getAllAgents(); // Returns an arraylist of agents
    ArrayList<Food> food = env.getAllFood(); // Returns an arraylist of all the food on the map
    ArrayList<Wall> walls = env.getAllWalls(); // Returns an arraylist of all walls
    ArrayList<Seaweed> seaweed = env.getAllSeaweed();

    for (int i = 0;
        i < agents.size();
        i++) { // Runs through arraylist of agents, will draw them on the canvas
      Agent ag = agents.get(i);

      // draw the field of view for the agent
      if (selectedAgent == null || !agentFocused || (agentFocused && ag == selectedAgent))
        stroke(128);
      else stroke(128, 100); // , (float) ag.getHealth()*200+55
      noFill();
      double range = ag.getVisionRange() * 2;

      pushMatrix();
      translate(ag.getX(), ag.getY());
      rotate((float) Utilities.toRadians(ag.getViewHeading() - ag.getFOV()));
      line(0, 0, (int) (range / 2), 0);
      popMatrix();

      pushMatrix();
      translate(ag.getX(), ag.getY());
      rotate((float) Utilities.toRadians(ag.getViewHeading() + ag.getFOV()));
      line(0, 0, (int) (range / 2), 0);
      popMatrix();

      arc(
          (float) ag.getX(),
          (float) ag.getY(),
          (float) range,
          (float) range,
          (float) Utilities.toRadians(ag.getViewHeading() - ag.getFOV()),
          (float) Utilities.toRadians(ag.getViewHeading() + ag.getFOV()));

      // draw our circle representation for the agent
      noStroke();
      // if(selectedAgent == null || !agentFocused || (agentFocused && ag == selectedAgent))
      // fill(theme.getColor((ag instanceof Enemy ? Types.SHARK : Types.FISH)));
      // else fill(theme.getColor((ag instanceof Enemy ? Types.SHARK : Types.FISH)), 100); //,
      // (float) ag.getHealth()*200 +55); // Alpha was severly impacting performance of simulation
      if (ag instanceof Enemy) {
        fill(
            ((ag.getSpeciesId() + 1) * 25) % 256,
            ((ag.getSpeciesId() + 1) * 47) % 256,
            ((ag.getSpeciesId() + 1) * 69) % 256,
            (agentFocused && ag == selectedAgent ? 100 : 256));
        pushMatrix();
        translate(ag.getX(), ag.getY());
        rotate((float) Utilities.toRadians(ag.getViewHeading()));
        rect(-10, -10, 20, 20);
        popMatrix();
      } else {
        fill(
            ((ag.getSpeciesId() + 1) * 25) % 256,
            ((ag.getSpeciesId() + 1) * 47) % 256,
            ((ag.getSpeciesId() + 1) * 69) % 256,
            (agentFocused && ag == selectedAgent ? 100 : 256));
        ellipse(ag.getX(), ag.getY(), 20, 20);
      }

      if (agentFocused
          && ag == selectedAgent) { // keep agent on screen if in focused / tracking mode
        int simAgX =
            (int) ((ag.getX() * zoomLevel) + offsetX); // screen coordinates of the selected agent
        int simAgY = (int) ((ag.getY() * zoomLevel) + offsetY);

        if (simAgX < trackingBounds) offsetX += trackingBounds - simAgX;
        else if (simAgX > draw_width - trackingBounds)
          offsetX -= simAgX - draw_width + trackingBounds;

        if (simAgY < trackingBounds) offsetY += trackingBounds - simAgY;
        else if (simAgY > draw_height - trackingBounds)
          offsetY -= simAgY - draw_height + trackingBounds;
      }
    }

    noStroke();
    fill(theme.getColor(Types.FOOD));
    for (int i = 0;
        i < food.size();
        i++) { // Runs through arraylist of food, will draw them on the canvas
      Food fd = food.get(i);
      ellipse(fd.getX(), fd.getY(), 5, 5);
    }

    noStroke();
    fill(201, 23, 134);
    for (int i = 0;
        i < seaweed.size();
        i++) { // Runs through arraylist of food, will draw them on the canvas
      Seaweed fd = seaweed.get(i);
      ellipse(fd.getX(), fd.getY(), 5, 5);
    }

    stroke(theme.getColor(Types.WALL));
    noFill();
    for (Wall wl : walls) { // Runs through arraylist of walls, will draw them on the canvas
      switch (wl.getWallType()) {
        case Collision.TYPE_WALL_AGENT:
          stroke(theme.getColor(Types.FISH));
          break;
        case Collision.TYPE_WALL_ENEMY:
          stroke(theme.getColor(Types.SHARK));
          break;
        default:
          stroke(theme.getColor(Types.WALL));
      }

      line(
          (float) wl.getStart().x,
          (float) wl.getStart().y,
          (float) wl.getEnd().x,
          (float) wl.getEnd().y);
    }

    popMatrix();

    fill(0);
    // rect(draw_width - 50, 0, 250, draw_height);
  }