コード例 #1
0
ファイル: Ex24.java プロジェクト: schoenm1/maze
 public void mouseTouched(Actor actor, GGMouse mouse, Point spot) {
   switch (mouse.getEvent()) {
     case GGMouse.lPress:
       startLocation = toLocation(mouse.getX(), mouse.getY());
       actor.setOnTop();
       hotSpot = spot;
       break;
     case GGMouse.lDrag:
       Point imageCenter = new Point(mouse.getX() - hotSpot.x, mouse.getY() - hotSpot.y);
       actor.setPixelLocation(imageCenter);
       refresh();
       break;
     case GGMouse.lRelease:
       if (spot.x == -1) // Cursor is outside image
       actor.setLocation(startLocation);
       else {
         actor.setPixelLocation(new Point(mouse.getX(), mouse.getY()));
         nbMoves++;
         if (isOver()) setStatusText("Total #: " + nbMoves + ". Done.");
         else setStatusText("#: " + nbMoves);
       }
       actor.setLocationOffset(new Point(0, 0));
       hotSpot = null;
       refresh();
       break;
   }
 }
コード例 #2
0
ファイル: Actor.java プロジェクト: rooseveltcs/ant-simulator
 /**
  * Checks if this is the same as the given
  *
  * @param other The actor this is being compared to
  * @return returns true if they are the same, false if not
  */
 public boolean isSame(Actor other) {
   if (other.getColor().equals(getColor())) {
     if (other.getDirection() == getDirection()) {
       if (other.getLocation().isSameLocation(other.getLocation())) {
         return true;
       }
     }
   }
   return false;
 }
コード例 #3
0
ファイル: GGNimPlayer.java プロジェクト: schoenm1/maze
 public void mouseTouched(Actor actor, GGMouse mouse, Point pix) {
   if (!isMouseEnabled) return;
   if (nbTaken == 3) setStatusText("Take a maximum of 3. Click 'OK' to continue");
   else {
     agent.sendCommand(agentName, Command.REPORT_POSITION, actor.getLocation().x);
     actor.removeSelf();
     nbMatches--;
     setStatusText(nbMatches + " matches remaining. Click 'OK' to continue");
     nbTaken++;
     refresh();
   }
 }
コード例 #4
0
  private void checkActorPosition(ResourceEntry entry, Actor actor, BmpResource searchMap) {
    String anim = actor.getAttribute("Animation").toString();
    ResourceEntry creEntry;
    CreResource creature = null;

    if (actor.getAttribute("Character") instanceof ResourceRef
        && actor.getAttribute("Character").toString() != "None") {
      creEntry =
          ResourceFactory.getInstance()
              .getResourceEntry(((ResourceRef) actor.getAttribute("Character")).getResourceName());

      creature = (CreResource) ResourceFactory.getResource(creEntry);
    } else if (actor.getAttribute("CRE file") != null)
      creature = (CreResource) actor.getAttribute("CRE file");

    if (creature == null
        || ((IdsFlag) creature.getAttribute("Status")).isFlagSet(0)
        || ((IdsFlag) creature.getAttribute("Status")).isFlagSet(11)) return;

    if (!exclude.contains(anim.substring(0, anim.indexOf(" ")))) {
      int x = ((DecNumber) actor.getAttribute("Position: X")).getValue() / 16;
      int y = ((DecNumber) actor.getAttribute("Position: Y")).getValue() / 12;
      if (!Passable[searchMap.getPalette().getIndex(searchMap.getImage().getRGB(x, y) & 0xFFFFFF)])
        errorTable.addTableItem(
            new AreaTableLine(
                entry,
                actor,
                "Impassable actor position (" + creature.getAttribute("Name").toString() + ")"));
    }
  }
コード例 #5
0
  public ArrayList<String> attackDamageAndKnockBack(
      Actor source,
      Arc2D.Double arc,
      Point mapPoint,
      int damage,
      int knockBackX,
      int knockBackY,
      int maxHits,
      String weaponType) {
    int dmg = 0;
    int hits = 0;
    Monster monster = null;
    ArrayList<String> monstersHit = new ArrayList<String>();

    try {
      for (String key : monsters.keySet()) {
        monster = (Monster) monsters.get(key);

        if (weaponType != null) {
          if (weaponType.equals("Net")) {
            damage = 1;
          }
        }

        dmg =
            monster.attackDamageAndKnockBack(
                source, arc, mapPoint, damage, knockBackX, knockBackY, weaponType);
        if (dmg > 0) {
          if (weaponType != null) {
            if (weaponType.equals("FangClaw")) {
              monster.poison(10);
            }
          }
          monstersHit.add(monster.getName());
          hits++;
        }
        if (hits >= maxHits) {
          break;
        }
      }
    } catch (ConcurrentModificationException concEx) {
      // another thread was trying to modify monsters while iterating
      // we'll continue and the new item can be grabbed on the next update
    }

    if (hits == 0) {
      if (source != null) {
        SoundClip cl = new SoundClip(registry, "Weapon/Miss", source.getCenterPoint());
      } else {
        SoundClip cl = new SoundClip("Weapon/Miss");
      }
    }

    return monstersHit;
  }
コード例 #6
0
ファイル: Hw2.java プロジェクト: citrit/ECSE4750
 public boolean action(Event evt, Object what) {
   if (evt.target instanceof MenuItem) {
     // Since we didn't save references to each of the menu objects,
     // we check which one was pressed by comparing labels.
     if (((String) evt.arg).equals("Run")) {
       for (int i = 0; i < 360; i++) {
         act.rotateX(1);
         renderer.render();
       }
     }
   }
   System.out.println("Event: " + evt + " Object: " + what);
   return super.action(evt, what);
 }
コード例 #7
0
  /**
   * Show the current status of the field.
   *
   * @param step Which iteration step it is.
   * @param field The field whose status is to be displayed.
   */
  public void showStatus(int step, Field field) {
    if (!isVisible()) setVisible(true);

    stepLabel.setText(STEP_PREFIX + step);
    stats.reset();

    fieldView.preparePaint();

    for (int row = 0; row < field.getDepth(); row++) {
      for (int col = 0; col < field.getWidth(); col++) {
        Actor actor = field.getActorAt(row, col);
        if (actor != null) {
          stats.incrementCount(actor.getClass());
          fieldView.drawMark(col, row, getColor(actor.getClass()));
        } else {
          fieldView.drawMark(col, row, EMPTY_COLOR);
        }
      }
    }
    stats.countFinished();

    population.setText(POPULATION_PREFIX + stats.getPopulationDetails(field));
    fieldView.repaint();
  }
コード例 #8
0
  @Override
  public void run() {
    // TODO Auto-generated method stub
    while (runner.isAlive()) {
      actors = one.getActors();

      // one.go();
      for (int z = 0; z < AList.size(); z++) {
        Actor a = AList.get(z);
        if (a.equals(background) && a.topy() >= 350) {
          a.setLocation(-5, -360);
        }
        if (a.equals(background2) && a.topy() >= 350) {
          a.setLocation(-5, -360);
        }

        if (a.equals(ammo) && a.topy() >= 350) {
          a.setLocation((int) (330 * Math.random()) + 30, (int) (-1000 * Math.random()) + -1);
        }
        if (a.equals(r) && a.topy() >= 350) {

          a.setLocation(-85, -361);
        }
        if (a.equals(r2) && a.topy() >= 350) {

          a.setLocation(-85, -361);
        }
        if (a.equals(r3) && a.topy() >= 350) {

          a.setLocation(355, -361);
        }
        if (a.equals(r4) && a.topy() >= 350) {

          a.setLocation(355, -361);
        }
        for (int ctr = 0; ctr < rs.length; ctr++) {
          if (a.equals(rs[ctr]) && a.topy() >= 350) {
            a.setLocation((int) (330 * Math.random()) + 30, (int) (-370 * Math.random()) + -1);
          }
        }
        if (a instanceof Ammo) {

          if (a.getRect().intersects(one.getLeft()) == true
              || a.getRect().intersects(one.getRight()) == true
              || a.getRect().intersects(one.getBottom()) == true) {
            a.setLocation((int) (330 * Math.random()) + 30, (int) (-370 * Math.random()) + -1);
            Laser laser = new Laser(one.getX(), one.getY(), "images/laser2.png");
            one.arsenal.add(laser);
            // a.removeSelf();
            one.ammohit = true;
          }
        }

        if (a instanceof Rock) {
          //  System.out.println("PodR: "+one.getRect());
          // System.out.println("Rock :"+a.getRect());

          if (a.getRect().intersects(one.getLeft()) == true
              || a.getRect().intersects(one.getRight()) == true) {
            // System.out.println("collision");
            one.collision = true;
            one.newImage("images/Explosion1.gif");
            one.y -= 60;
            tstop = true;

            speed = one.backSpeed;
            runner.stop();
          }

          //  if(one.collision(a)==true){
          //     System.out.println("collide");
          // }

        }
        if (a instanceof PodRacer) {

          while (a.getY() <= 0) {
            a.y += 1;
          }
          while (a.getY() >= 288) {
            a.y += -1;
          }

        } else {

          a.move();
        }

        if (a instanceof Laser) {
          Laser temp = (Laser) a;
          for (int ctr = 0; ctr < rs.length; ctr++) {
            if (a.getRect().intersects(rs[ctr].getRect()) == false || a.boty() >= 0) {
              // System.out.println("test");
              temp.Shot();
            }

            if (a.boty() <= 0) {
              mtemp = temp;
              laserremove = true;
            }
            if (a.getRect().intersects(rs[ctr].getRect())) {
              mtemp = temp;
              laserremove = true;
              rs[ctr].setLocation(
                  (int) (330 * Math.random()) + 30, (int) (-370 * Math.random()) + -1);
              one.rockhit = true;
            }
          }
        }
      }
      if (laserremove == true) {
        laserremove = false;
        // System.out.println("test");
        // one.arsenal.remove(0);
        mtemp.removeSelf();
      }

      try {
        speed = one.backSpeed;
        runner.sleep(speed);
      } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
      // run();
    }
  }
コード例 #9
0
  public void run() {
    WindowBlocker blocker = new WindowBlocker(NearInfinity.getInstance());
    blocker.setBlocked(true);
    BmpResource searchMap = null;
    List<ResourceEntry> files = ResourceFactory.getInstance().getResources("ARE");
    ProgressMonitor progress =
        new ProgressMonitor(NearInfinity.getInstance(), "Checking areas...", null, 0, files.size());
    errorTable =
        new SortableTable(
            new String[] {"Area", "Object", "Message"},
            new Class[] {Object.class, Object.class, Object.class},
            new int[] {100, 200, 200});
    long startTime = System.currentTimeMillis();

    exclude.clear();
    exclude.add("BIRD");
    exclude.add("EAGLE");
    exclude.add("SEAGULL");
    exclude.add("VULTURE");
    exclude.add("DOOM_GUARD");
    exclude.add("DOOM_GUARD_LARGER");
    exclude.add("BAT_INSIDE");
    exclude.add("BAT_OUTSIDE");

    //		exclude.add("CAT");
    //		exclude.add("MOOSE");
    //		exclude.add("RABBIT");
    exclude.add("SQUIRREL");
    exclude.add("RAT");
    //		exclude.add("STATIC_PEASANT_MAN_MATTE");
    //		exclude.add("STATIC_PEASANT_WOMAN_MATTE");

    for (int i = 0; i < files.size(); i++) {
      try {
        ResourceEntry entry = files.get(i);
        Resource area = ResourceFactory.getResource(entry);

        if (typeButtons[3].isSelected()) checkAreasConnectivity(entry, area);

        if (typeButtons[1].isSelected()) {
          String[] name = ((AreResource) area).getAttribute("WED resource").toString().split("\\.");
          ResourceEntry searchEntry =
              ResourceFactory.getInstance().getResourceEntry(name[0] + "SR.BMP");

          if (searchEntry == null) {
            searchMap = null;
            errorTable.addTableItem(
                new AreaTableLine(
                    entry,
                    ((AreResource) area).getAttribute("WED resource"),
                    "Area don't have search map"));
          } else {
            searchMap = (BmpResource) ResourceFactory.getResource(searchEntry);
          }
        }

        List<StructEntry> list = ((AreResource) area).getList();
        for (int j = 0; j < list.size(); j++) {
          if (list.get(j) instanceof Actor) {
            Actor actor = (Actor) list.get(j);
            StructEntry time = actor.getAttribute("Expiry time");
            if (typeButtons[0].isSelected() && ((DecNumber) time).getValue() != -1)
              errorTable.addTableItem(
                  new AreaTableLine(
                      entry, actor, "Actor expiry time is: " + ((DecNumber) time).getValue()));

            if (searchMap != null) checkActorPosition(entry, actor, searchMap);
          }

          if (typeButtons[2].isSelected() && list.get(j) instanceof Container) {
            ResourceRef keyRes = (ResourceRef) ((AbstractStruct) list.get(j)).getAttribute("Key");
            if (!keyRes.getResourceName().equalsIgnoreCase("None.ITM")
                && !ResourceFactory.getInstance().resourceExists(keyRes.getResourceName())) {
              errorTable.addTableItem(
                  new AreaTableLine(
                      entry,
                      list.get(j),
                      "Non existent key item for container: " + keyRes.getResourceName()));
            }
            checkContainedItem(entry, list.get(j));
          }
        }
      } catch (Exception e) {
        e.printStackTrace();
      }

      progress.setProgress(i + 1);
      if (progress.isCanceled()) {
        JOptionPane.showMessageDialog(
            NearInfinity.getInstance(),
            "Operation canceled",
            "Info",
            JOptionPane.INFORMATION_MESSAGE);
        blocker.setBlocked(false);
        return;
      }
    }
    System.out.println("Check took " + (System.currentTimeMillis() - startTime) + "ms");
    if (errorTable.getRowCount() == 0)
      JOptionPane.showMessageDialog(
          NearInfinity.getInstance(), "No errors found", "Info", JOptionPane.INFORMATION_MESSAGE);
    else {
      errorTable.tableComplete();
      resultFrame = new ChildFrame("Result", true);
      resultFrame.setIconImage(Icons.getIcon("Find16.gif").getImage());
      bopen = new JButton("Open", Icons.getIcon("Open16.gif"));
      bopennew = new JButton("Open in new window", Icons.getIcon("Open16.gif"));
      bopen.setMnemonic('o');
      bopennew.setMnemonic('n');
      resultFrame.getRootPane().setDefaultButton(bopennew);
      JPanel panel = new JPanel(new FlowLayout(FlowLayout.CENTER));
      panel.add(bopen);
      panel.add(bopennew);
      JLabel count = new JLabel(errorTable.getRowCount() + " errors found", JLabel.CENTER);
      count.setFont(count.getFont().deriveFont((float) count.getFont().getSize() + 2.0f));
      JScrollPane scrollTable = new JScrollPane(errorTable);
      scrollTable.getViewport().setBackground(errorTable.getBackground());
      JPanel pane = (JPanel) resultFrame.getContentPane();
      pane.setLayout(new BorderLayout(0, 3));
      pane.add(count, BorderLayout.NORTH);
      pane.add(scrollTable, BorderLayout.CENTER);
      pane.add(panel, BorderLayout.SOUTH);
      bopen.setEnabled(false);
      bopennew.setEnabled(false);
      errorTable.setFont(BrowserMenuBar.getInstance().getScriptFont());
      errorTable.addMouseListener(
          new MouseAdapter() {
            public void mouseReleased(MouseEvent event) {
              if (event.getClickCount() == 2) {
                int row = errorTable.getSelectedRow();
                if (row != -1) {
                  ResourceEntry resourceEntry = (ResourceEntry) errorTable.getValueAt(row, 0);
                  Resource resource = ResourceFactory.getResource(resourceEntry);
                  new ViewFrame(resultFrame, resource);
                  ((AbstractStruct) resource)
                      .getViewer()
                      .selectEntry((String) errorTable.getValueAt(row, 1));
                }
              }
            }
          });
      bopen.addActionListener(this);
      bopennew.addActionListener(this);
      pane.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3));
      errorTable.getSelectionModel().addListSelectionListener(this);
      resultFrame.pack();
      Center.center(resultFrame, NearInfinity.getInstance().getBounds());
      resultFrame.setVisible(true);
    }
    blocker.setBlocked(false);
  }
コード例 #10
0
ファイル: Hw2.java プロジェクト: citrit/ECSE4750
  public static void main(String argv[]) {
    PolylineCell polyLCell = new PolylineCell(); // new class
    TriangleCell triCell = new TriangleCell(); // new class
    PointSet myPts = new PointSet();
    PointCell ptCell = new PointCell();
    LineCell lCell = new LineCell();
    LineCell sCell = new LineCell();
    PolygonCell pCell = new PolygonCell();
    Material mat;
    MaterialSet matSet = new MaterialSet();
    Actor actor = new Actor();
    OGLRenderer aren = new OGLRenderer();
    int count, shape, j, i, k;
    float tmp[] = new float[3];
    float rgba[] = new float[3];
    objectReader in = new objectReader(argv[0]);
    PointType data;

    while (!in.eof()) {
      shape = in.getInt();
      count = in.getInt();
      for (i = 0; i < 3; i++) rgba[i] = in.getFloat(); // get color

      switch (shape) {
        case 0: // coord. of points
          myPts = new PointSet();
          for (i = 0; i < count; i++) {
            for (j = 0; j < 3; j++) tmp[j] = in.getFloat(); // get the x,y,z coord.
            data = new PointType(tmp);
            myPts.addPoint(data);
          }
          break;
        case 1: // a point
          ptCell = new PointCell();
          matSet = new MaterialSet();
          mat = new Material(rgba[0], rgba[1], rgba[2], 0);
          matSet.addMaterial(mat); // set color
          for (i = 0; i < count; i++) ptCell.addVal(in.getInt()); // get point
          ptCell.setMaterials(matSet);
          ptCell.setPoints(myPts);
          actor.addCell(ptCell); // add it to the entity
          break;
        case 2: // a line
          lCell = new LineCell();
          matSet = new MaterialSet();
          mat = new Material(rgba[0], rgba[1], rgba[2], 0);
          matSet.addMaterial(mat); // set color
          for (i = 0; i < count; i++) // read 2 numbers
          for (j = 0; j < 2; j++) lCell.addVal(in.getInt());
          lCell.setMaterials(matSet);
          lCell.setPoints(myPts);
          actor.addCell(lCell); // add to entity
          break;
        case 3: // a polygon
          pCell = new PolygonCell();
          matSet = new MaterialSet();
          mat = new Material(rgba[0], rgba[1], rgba[2], 0);
          matSet.addMaterial(mat); // set color
          for (i = 0; i < count; i++)
            while ((j = in.getInt()) != -1) // read until -1 for each set
            pCell.addVal(j);
          pCell.setMaterials(matSet);
          pCell.setPoints(myPts);
          actor.addCell(pCell); // add to entity
          break;
        case 4: // a triangle
          triCell = new TriangleCell();
          matSet = new MaterialSet();
          mat = new Material(rgba[0], rgba[1], rgba[2], 0);
          matSet.addMaterial(mat); // set color
          for (i = 0; i < count; i++)
            for (k = 0; k < 3; k++) triCell.addVal(in.getInt()); // read 3 numbers
          triCell.setMaterials(matSet);
          triCell.setPoints(myPts);
          actor.addCell(triCell); // add to entity
          break;
        case 5: // a polyline
          polyLCell = new PolylineCell();
          matSet = new MaterialSet();
          mat = new Material(rgba[0], rgba[1], rgba[2], 0); // set color
          matSet.addMaterial(mat);
          for (i = 0; i < count; i++)
            while ((j = in.getInt()) != -1) // read until -1 for each set
            polyLCell.addVal(j);
          polyLCell.setMaterials(matSet);
          polyLCell.setPoints(myPts);
          actor.addCell(polyLCell); // add to entity
          break;
      }
    }

    // Add this  DataSet to the Renderers collection.
    aren.addActor(actor);
    aren.addCamera(new OGLCamera());
    aren.addLight(new OGLLight(0));

    Hw2 hw2 = new Hw2();
    hw2.renderer = aren;
    hw2.act = actor;
    // Make it visible and set size
    aren.setVisible(true);
    aren.setSize(300, 300);
    aren.getCamera().setFrom(0.0F, 5.0F, 15.0F);
    System.out.println("Here we go");

    // Add the canvas to the frame and make it show
    hw2.add("Center", aren);
    hw2.pack();

    // Set up the menu
    MenuBar mb = new MenuBar();
    Menu file = new Menu("File");
    file.add(new MenuItem("Run"));
    mb.add(file);
    hw2.setMenuBar(mb);

    hw2.show();
  }