コード例 #1
0
 /**
  * Find the distance between two characters
  *
  * @param Targ Target character
  * @return distance
  */
 public double Dist(GameObject Targ) {
   // find x squared and y squared
   double dx =
       Math.pow(((X + W / 2 * GROWTHFACTOR) - (Targ.X + Targ.W / 2 * Targ.GROWTHFACTOR)), 2);
   double dy =
       Math.pow(((Y + H / 2 * GROWTHFACTOR) - (Targ.Y + Targ.H / 2 * Targ.GROWTHFACTOR)), 2);
   // find distance
   return (Math.sqrt(dx + dy));
 }
コード例 #2
0
  /**
   * do damage to character
   *
   * @param Dmg Amount of Damage
   */
  public void Damage(int Dmg, int Type) {
    // If character is already dead then dont do damage
    if (ISDEAD) return;

    // Do damage
    if (Type == 1) {
      // DAMAGE FROM PHYSICAL ATTACK
      if (STATS.ARMOR > Dmg) return;
      HEALTH = HEALTH - Dmg + STATS.ARMOR;
    } else if (Type == 2) {
      // DAMAGE FROM MAGIC ATTACK
      if (STATS.MAGIC_RESIST > Dmg) return;
      HEALTH = HEALTH - Dmg + STATS.MAGIC_RESIST;
    }
    // If an Npc then run and hide
    if (NAI != null) {
      NAI.State = "alarmed";
    }

    // Death condition
    if (HEALTH <= 0) {
      // If player is dead
      if (this.CLASS.equals("Player")) {

        HEALTH = 0;

        // Quit game
        JOptionPane.showMessageDialog(null, "You are dead");
        X = 100;
        Y = 100;
        Opify(50);
        HEALTH = (int) MAX_HEALTH;

      } else {
        // If other character
        // set Death stats
        ISDEAD = true;
        HEALTH = 0;
        // display death
        CLASS = Cl + " (Dead)";

        // Rot effect
        for (int i = 0; i < imgCHARAC.getWidth(); i++) {
          for (int j = 0; j < imgCHARAC.getHeight(); j++) {
            imgCHARAC.setRGB(i, j, imgCHARAC.getRGB(i, j) * (int) Math.pow(3, 3));
          }
        }

        // Make inventory open to looting
        INVENTORY.OPEN_INVEN = true;
      }
    }
  }
コード例 #3
0
ファイル: Reading.java プロジェクト: Locitao/jsf32week14
  public double loadBinaryFile() throws IOException {
    double time = System.nanoTime();
    File file = new File("C:\\Users\\rvanduijnhoven\\Documents\\jsfoutput\\jsfweek14.bin");
    FileChannel fileChannel = null;
    MappedByteBuffer map = null;
    int counter = 0;
    // Now read every edge from the file and draw it.
    try {
      //            fileIn = new FileInputStream(file);
      //            inPut = new DataInputStream(fileIn);
      fileChannel = new RandomAccessFile(file, "r").getChannel();
      map = fileChannel.map(FileChannel.MapMode.READ_ONLY, 0, 4096 * 128 * 128);
      double d = map.getDouble();
      currentLevel = (int) d;
      counter = (int) (3 * Math.pow(4, currentLevel - 1));
      for (int i = 0; i <= counter; i++) {
        double X1 = map.getDouble();
        double Y1 = map.getDouble();
        double X2 = map.getDouble();
        double Y2 = map.getDouble();
        double red = map.getDouble();
        double green = map.getDouble();
        double blue = map.getDouble();

        Edge e = new Edge(X1, Y1, X2, Y2, new Color(red, green, blue, 1));
        drawEdge(e);
      }
    } catch (Exception ex) {
      ex.printStackTrace();
    } finally {
      fileChannel.close();
      map.clear();
    }

    return System.nanoTime() - time;
  }
コード例 #4
0
ファイル: Reading.java プロジェクト: Locitao/jsf32week14
  public void watchForNewEdges() {
    // File file = new File("C:\\Users\\rvanduijnhoven\\Documents\\jsfoutput\\jsfweek14.bin");

    // Get the file system
    // FileSystem fs = path.getFileSystem();

    // Create the watchservice
    try {
      Path path = Paths.get("C:/Users/rvanduijnhoven/Documents/jsfoutput/");
      WatchService service = FileSystems.getDefault().newWatchService();
      path.register(service, ENTRY_CREATE, ENTRY_DELETE, ENTRY_MODIFY);
      WatchKey key;
      while (true) {
        key = service.take();
        for (WatchEvent<?> event : key.pollEvents()) {
          // Code here that does something when new edges have been generated
          System.out.println(event.context().toString());
          WatchEvent<Path> ev = (WatchEvent<Path>) event;
          WatchEvent.Kind kind = ev.kind();

          if (kind == OVERFLOW) {
            continue; // just to demonstrate
          }

          Path changed = ev.context();
          Path child = path.resolve(changed);
          if (changed.toString().equals("jsfweek14.bin")) {

            clearKochPanel();
            File file = new File("C:\\Users\\rvanduijnhoven\\Documents\\jsfoutput\\jsfweek14.bin");
            FileChannel fileChannel = null;
            MappedByteBuffer map = null;
            int counter = 0;
            // Now read every edge from the file and draw it.
            try {
              fileChannel = new RandomAccessFile(file, "r").getChannel();
              map = fileChannel.map(FileChannel.MapMode.READ_ONLY, 0, 4096 * 128 * 128);
              double d = map.getDouble();
              currentLevel = (int) d;
              counter = (int) (3 * Math.pow(4, currentLevel - 1));
              for (int i = 0; i <= counter; i++) {
                double X1 = map.getDouble();
                double Y1 = map.getDouble();
                double X2 = map.getDouble();
                double Y2 = map.getDouble();
                double red = map.getDouble();
                double green = map.getDouble();
                double blue = map.getDouble();
                Edge e = new Edge(X1, Y1, X2, Y2, new Color(red, green, blue, 1));
                drawEdge(e);
              }
              key.reset();

            } catch (Exception ex) {
              ex.printStackTrace();
            } finally {
              fileChannel.close();
              map.clear();
            }
          }
          key.reset();
        }
      }

    } catch (IOException ioe) {
      ioe.printStackTrace();
    } catch (Exception ie) {
      ie.printStackTrace();
    }
  }