public void mousePressed() { ArrayList<Agent> agents = env.getAllAgents(); Agent agent_clicked = null; if (win.mousePressed()) return; if (!Utilities.isPointInBox(mouseX, mouseY, 0, 0, draw_width, draw_height)) return; /* * Mouse Modes are as follows: * 0 = Click tool - Select agents to see information on them in the top left hand corner * 1 = Food tool - Place food where you click * 2 = Agent tool - Place agent where you click * 3 = Thrust tool - Thrusts the agent clicked on by 2 * 4 = Wall tool - Place a new wall in the environment */ // coordinates of the mouse within the simulation environment int simMouseX = (int) ((float) (mouseX - offsetX) / zoomLevel); int simMouseY = (int) ((float) (mouseY - offsetY) / zoomLevel); if (!Utilities.isPointInBox(simMouseX, simMouseY, 0, 0, Environment.width, Environment.height)) return; // A wall has been placed -> add to the world if (PLACE_MODE) { PLACE_MODE = false; ArrayList<Wall> walls = env.getAllWalls(); Wall wl = walls.get(walls.size() - 1); wl.addToWorld(); return; } switch (mouseMode) { case 0: agent_clicked = getClickedAgent(agents, simMouseX, simMouseY); if (agent_clicked != null) { // agent was clicked so update selected selectedAgent = agent_clicked; } break; case 1: env.addSeaweed(new Point2D.Double(simMouseX, simMouseY)); break; case 2: int heading = (int) Math.floor(Math.random() * 360); env.addFish(new Point2D.Double(simMouseX, simMouseY), heading); break; case 3: agent_clicked = getClickedAgent(agents, simMouseX, simMouseY); if (agent_clicked != null) { // agent was clicked so update selected agent_clicked.thrust(2); } break; case 4: env.addWall( new Point2D.Double(simMouseX, simMouseY), new Point2D.Double(simMouseX, simMouseY)); PLACE_MODE = true; } }
public void setup() { frameRate(30); size(screen.width, screen.height, P3D); textMode(SCREEN); setupUI(); draw_width = screen.width - 250; draw_height = screen.height; for (int i = 0; i < numStartingAgents; i++) { int x = (int) Math.floor(Math.random() * Environment.width * 0.2); int y = (int) Math.floor(Math.random() * Environment.height * 0.2); int heading = (int) Math.floor(Math.random() * 360); env.addFish(new Point2D.Double(x, y), heading); } env.getAllAgents().get(0).thrust(2); selectedAgent = env.getAllAgents().get(0); for (int i = 0; i < maxSeaweed; i++) { int x = (int) Math.floor(Math.random() * Environment.width); int y = (int) Math.floor(Environment.height * 0.2 + Math.random() * Environment.height * 0.6); env.addSeaweed(new Point2D.Double(x, y)); } // Top wall env.addWall(new Point2D.Double(0, 0), new Point2D.Double(Environment.width, 0)); // Right wall env.addWall( new Point2D.Double(Environment.width, 0), new Point2D.Double(Environment.width, Environment.height)); // Bottom wall env.addWall( new Point2D.Double(0, Environment.height), new Point2D.Double(Environment.width, Environment.height)); // Left wall env.addWall(new Point2D.Double(0, 0), new Point2D.Double(0, Environment.height)); // TODO: Spawn area walls env.addWall( new Point2D.Double(Environment.width * 0.2, 0), new Point2D.Double(Environment.width * 0.2, Environment.height * 0.2), Collision.TYPE_WALL_AGENT); env.addWall( new Point2D.Double(0, Environment.height * 0.2), new Point2D.Double(Environment.width * 0.2, Environment.height * 0.2), Collision.TYPE_WALL_AGENT); env.addWall( new Point2D.Double(Environment.width * 0.8, Environment.height), new Point2D.Double(Environment.width * 0.8, Environment.height * 0.8), Collision.TYPE_WALL_ENEMY); env.addWall( new Point2D.Double(Environment.width, Environment.height * 0.8), new Point2D.Double(Environment.width * 0.8, Environment.height * 0.8), Collision.TYPE_WALL_ENEMY); // internal walls // env.addWall(new Point2D.Double(Environment.width/3,Environment.height/5),new // Point2D.Double(Environment.width/2,Environment.height/5)); // env.addWall(new Point2D.Double(Environment.width/2,Environment.height/2),new // Point2D.Double(Environment.width/2,3*Environment.height/4)); // env.addWall(new Point2D.Double(Environment.width/4, Environment.height / 4),new // Point2D.Double(3 * Environment.width/4, 3 * Environment.height / 4)); }