コード例 #1
0
  /**
   * Spawn a character on the map
   *
   * @param MiX Minimum X value
   * @param MiY Minimum Y value
   * @param MaX Maximum X value
   * @param MaY Maximum Y value
   */
  public void Spawn(int MiX, int MiY, int MaX, int MaY) {
    double Nx = 0, Ny = 0;

    // Random coordinate
    Nx = Math.random() * MaX + MiX;
    Ny = Math.random() * MaY + MiY;

    // Store block number
    int BNum = MAP.elementAt(0).getBlockNum(Nx + W / 2, Ny + H / 2);

    // if invalid block number
    if (BNum == -1) {
      Spawn(MiX, MiY, MaX, MaY);
    }

    // if invalid surface
    else if (!isValidSurface(MAP.elementAt(0).Fill[BNum])) {
      Spawn(MiX, MiY, MaX, MaY);
    }

    // if colliding with something
    else if (this.Collision(Nx + W / 2, Ny + H / 2)) {
      Spawn(MiX, MiY, MaX, MaY);
    } else {
      X = Nx;
      Y = Ny;
    }
  }
コード例 #2
0
ファイル: Hero.java プロジェクト: rweichler/wuigi
  /** @param override true if should kill even if invulerable, false if not */
  public void kill(boolean override) {
    if (!override) {
      if (star || invulerable || piped) return;
    }
    deathPos.setLocation(pos);
    if (deathPos.y < 0) {
      deathPos.y = 0;
    }
    if (metal) {
      metal = false;
      startInvulnerable();
      invulerableTime = 3000 / 15;
      Point2D.Double v = new Point2D.Double(Math.random() * 8 - 4, Math.random() * 4 + 7);

      TMetalCap cap = new TMetalCap();
      cap.setPos(pos.x, pos.y);
      cap.kill(v);
      this.addSpawn(cap);
      return;
    }
    cape = false;
    dead = true;
    numBullets = 0;
    falling = false;
    acc = new Point2D.Double();
    vel = new Point2D.Double();
    deadTime = 25;
  }
コード例 #3
0
ファイル: GUI.java プロジェクト: actorclavilis/InsaneMouse
  private void spawnRandomers() {
    for (int i = 0; i < randomN; i++) {
      float x = (float) Math.random() * width;
      float y = (float) Math.random() * height;
      float r =
          (float)
              Math.sqrt(
                  Math.pow(((Player) players.get(0)).getX() - x, 2)
                      + Math.pow(((Player) players.get(0)).getY() - x, 2));

      while (r < distanceLimit) {
        x = (float) Math.random() * width;
        y = (float) Math.random() * height;
        r =
            (float)
                Math.sqrt(
                    Math.pow(((Player) players.get(0)).getX() - x, 2)
                        + Math.pow(((Player) players.get(0)).getY() - y, 2));
      }

      enemies.add(new EnemyTypes.Random(x, y, 0.5f, borders));
    }

    spawnRandomersB = false;
  }
コード例 #4
0
 public void animate(float[] pts, float[] deltas, int index, int limit) {
   float newpt = pts[index] + deltas[index];
   if (newpt <= 0) {
     newpt = -newpt;
     deltas[index] = (float) (Math.random() * 3.0 + 2.0);
   } else if (newpt >= (float) limit) {
     newpt = 2.0f * limit - newpt;
     deltas[index] = -(float) (Math.random() * 3.0 + 2.0);
   }
   pts[index] = newpt;
 }
コード例 #5
0
ファイル: GUI.java プロジェクト: actorclavilis/InsaneMouse
 private void spawnBomb() {
   float x, y;
   for (int i = 0; i < bombN; i++) {
     if (Math.random() > .5) { // top/bottom
       y = (Math.random() > .5) ? borders[1] : borders[3];
       x = (float) Math.random() * borders[2] - borders[0]; // width
     } else {
       x = (Math.random() > .5) ? borders[0] : borders[2];
       y = (float) Math.random() * borders[3] - borders[1]; // height
     }
     enemies.add(new EnemyTypes.Bomb(x, y, 1f, borders, scbInstance));
   }
 }
コード例 #6
0
ファイル: GUI.java プロジェクト: actorclavilis/InsaneMouse
  private void levelSetup() {
    reset();

    switch (level) {
      case 1:
        distance = 600;
        monsterN = 0;
        randomN = 0;
        rainN = 30;
        defaultDistance = 600;
        timeLast = 10000;
        spawnCircleB = true;
        break;
      case 2:
        distance = 600;
        monsterN = 0;
        randomN = 30;
        rainN = 30;
        defaultDistance = 600;
        timeLast += 10000;
        spawnCircleB = true;
        break;
      case 3:
        distance = 600;
        monsterN = 30;
        randomN = 0;
        rainN = 0;
        defaultDistance = 600;
        timeLast += 10000;
        spawnCircleB = true;
        break;
      default:
        distance = (float) (Math.random() * 200 + 400 - level * 5);
        monsterN = (int) (Math.random() * 25 + 10 + level);
        randomN = (int) (Math.random() * 25 + 10 + level);
        rainN = (int) (Math.random() * 10 + 10 + level);
        defaultDistance = distance;
        timeLast += 5000 + level * 1000;
        spawnCircleB = true;
    }

    monsterN *= monsterMultiplier;
    randomN *= monsterMultiplier;
    spawnMonsterB = true;
    spawnRandomersB = true;
    spawnIncrease = true;
    spawnRainB = true;
  }
コード例 #7
0
ファイル: Hero.java プロジェクト: rweichler/wuigi
 public void onTouch(Thing t) {
   if (dead) return;
   if (star && t instanceof TEnemy) {
     new AePlayWave("sound/kick.wav").start();
     t.kill(new Point2D.Double(vel.x * 2, Math.random() * 16 + 3));
   } else if (t instanceof TGoal) {
     won = true;
   }
 }
コード例 #8
0
  /**
   * The user has clicked in the applet. Figure out where and see if a legal move is possible. If it
   * is a legal move, respond with a legal move (if possible).
   */
  public void mouseReleased(MouseEvent e) {
    int x = e.getX();
    int y = e.getY();

    switch (status()) {
      case WIN:
      case LOSE:
      case STALEMATE:
        play(getCodeBase(), "audio/return.au");
        white = black = 0;
        if (first) {
          white |= 1 << (int) (Math.random() * 9);
        }
        first = !first;
        repaint();
        return;
    }

    // Figure out the row/column
    Dimension d = getSize();
    int c = (x * 3) / d.width;
    int r = (y * 3) / d.height;
    if (yourMove(c + r * 3)) {
      repaint();

      switch (status()) {
        case WIN:
          play(getCodeBase(), "audio/yahoo1.au");
          break;
        case LOSE:
          play(getCodeBase(), "audio/yahoo2.au");
          break;
        case STALEMATE:
          break;
        default:
          if (myMove()) {
            repaint();
            switch (status()) {
              case WIN:
                play(getCodeBase(), "audio/yahoo1.au");
                break;
              case LOSE:
                play(getCodeBase(), "audio/yahoo2.au");
                break;
              case STALEMATE:
                break;
              default:
                play(getCodeBase(), "audio/ding.au");
            }
          } else {
            play(getCodeBase(), "audio/beep.au");
          }
      }
    } else {
      play(getCodeBase(), "audio/beep.au");
    }
  }
コード例 #9
0
 public void start() {
   Dimension size = getSize();
   for (int i = 0; i < animpts.length; i += 2) {
     animpts[i + 0] = (float) (Math.random() * size.width);
     animpts[i + 1] = (float) (Math.random() * size.height);
     deltas[i + 0] = (float) (Math.random() * 4.0 + 2.0);
     deltas[i + 1] = (float) (Math.random() * 4.0 + 2.0);
     if (animpts[i + 0] > size.width / 6.0f) {
       deltas[i + 0] = -deltas[i + 0];
     }
     if (animpts[i + 1] > size.height / 6.0f) {
       deltas[i + 1] = -deltas[i + 1];
     }
   }
   anim = new Thread(this);
   anim.setPriority(Thread.MIN_PRIORITY);
   anim.start();
 }
コード例 #10
0
  public int getRandomImageNum() {
    if (images.size() <= images_used.size()) return -1;
    else {
      // Calculate, based on random, if we try to get from the new images
      boolean getFromNewImages;
      if (Math.random() * 100 < percentage_of_new_images) {
        getFromNewImages = true;
      } else {
        getFromNewImages = false;
      }

      int i;
      int j = 0;
      int tries = 0;
      while (true && tries < randomImageNum_maxTries) {
        // Always try the last added pictures
        if (images_nevershown.size() > 0
            && tries < (int) (randomImageNum_maxTries / 4) // Only use 1/4 of the tries here
        ) {
          i = images_nevershown.get(0);
          tries++;
        } else if (getFromNewImages
            && images_lastadded.size() > 0
            && tries < (int) (randomImageNum_maxTries / 2) // Only use 1/2 of the tries here
        ) {
          j = (int) (images_lastadded.size() * Math.random());
          i = images_lastadded.get(j);
          tries++;
        } else {
          // Random from the rest of the pictures
          i = (int) (Math.random() * images.size());
          tries++;
        }
        if (!images_used.contains((Integer) i)) return i;
      }

      System.out.println("Max tries in randomImageNum");
      return -1;
    }

    // Original:
    // return (int)(Math.random() * images.size());
  }
コード例 #11
0
ファイル: Hero.java プロジェクト: rweichler/wuigi
  public void think() {
    if (dead && deadTime > 0) {
      deadTime -= Wuigi.time();
      if (deadTime < 0) {
        vel.x = 0;
        vel.y = 15;
      }
      return;
    }

    if (star) {
      starTime += Wuigi.time();
      if (starTime > 10000 / 15) { // if you've been in starman mode for more than 10 seconds, stop
        star = false;
        starTime = 0;
        setSpriteColor(spriteColor, true);
      } else {
        setSpriteColor((int) (Math.random() * 6), true);
      }
    }

    if (invulerable) {
      invulerableTime += Wuigi.time();
      if (invulerableTime > 5000 / 15) {
        invulerable = false;
        invulerableTime = 0;
      }
    }

    if (cape) {
      capeTime += Wuigi.time();
      if (capeTime > 10000 / 15) {
        cape = false;
        capeTime = 0;
      }
    }

    updatePosition();
    xOffset += pos.x - posLast.x;
    if (xOffset > X_OFFSET) xOffset = X_OFFSET;
    else if (xOffset < -X_OFFSET) xOffset = -X_OFFSET;

    yOffset += pos.y - posLast.y;
    if (!(dead || falling)) {
      if (yOffset > Y_OFFSET) yOffset = Y_OFFSET;
      else if (yOffset < Y_OFFSET / 8) yOffset = Y_OFFSET / 8;
    }
    updateVelocity();
    // double v = vel.y;
    // if(v > 0 && vel.y < 0){
    //	System.out.println("position: " + pos.y);
    // }
    falling = false;
  }
コード例 #12
0
ファイル: GUI.java プロジェクト: actorclavilis/InsaneMouse
  private void spawnCircles() {
    if (circular) {
      for (int i = 0; i < ballN; i++) {
        double degree = Math.random() * 2 * Math.PI;
        float x = ((Player) players.get(0)).getX() + distance * (float) Math.sin(degree * i);
        float y = ((Player) players.get(0)).getY() + distance * (float) Math.cos(degree * i);
        enemies.add(new EnemyTypes.Circle(x, y, invSpeed));
      }
    } else {
      for (int i = 1; i < (ballN / 2); i++) {
        float x = (i * 2 * width) / (ballN);
        float y = 0;
        enemies.add(new EnemyTypes.Circle(x, y, invSpeed));
      }

      for (int i = (ballN / 2) + 1; i < ballN; i++) {
        float x = ((i - ballN / 2) * 2 * width) / ballN;
        float y = height;
        enemies.add(new EnemyTypes.Circle(x, y, invSpeed));
      }
    }
    spawnIncrease = false;
  }
コード例 #13
0
    public WebcamCaptureAndFadeImagePanel(int grid_x, int grid_y, int size_x, int size_y) {

      // Set to object
      this.grid_x = grid_x;
      this.grid_y = grid_y;

      this.size_x = size_x;
      this.size_y = size_y;

      // init tables
      imagenum_now = new int[this.grid_x][this.grid_y];
      imagenum_next = new int[this.grid_x][this.grid_y];
      imagenum_now2 = new Image[this.grid_x][this.grid_y];
      imagenum_next2 = new Image[this.grid_x][this.grid_y];
      fade = new float[this.grid_x][this.grid_y];
      wait = new int[this.grid_x][this.grid_y];
      redborder = new int[this.grid_x][this.grid_y];

      for (int i = 0; i < imagenum_now.length; i++) {
        for (int j = 0; j < imagenum_now[i].length; j++) {
          imagenum_now[i][j] = getRandomImageNum();
          images_used.add((Integer) imagenum_now[i][j]);
          imagenum_next[i][j] = getRandomImageNum();
          images_used.add((Integer) imagenum_next[i][j]);

          fade[i][j] = 0.1f * i * j;
          redborder[i][j] = 0;

          wait[i][j] = (int) (number_of_frames_showimage * Math.random());

          imagenum_now2[i][j] = getImage(imagenum_now[i][j]);
          imagenum_next2[i][j] = getImage(imagenum_next[i][j]);
        }
      }

      setPreferredSize(new Dimension(this.grid_x * size_x, this.grid_y * size_y));
    }
コード例 #14
0
ファイル: Decoder.java プロジェクト: develar/flash-cocoa
  @SuppressWarnings("ResultOfMethodCallIgnored")
  public Decoder(String filepath, String output) throws IOException {
    outputDir = new File(output);
    if (outputDir.exists()) {
      outputDir.renameTo(new File(output + "_old_" + Math.random() * 100));
    }

    outputDir = new File(output);
    outputDir.mkdirs();

    final File file = new File(filepath);
    data = ByteBuffer.allocate((int) file.length());
    data.order(ByteOrder.LITTLE_ENDIAN);
    final FileInputStream inputStream = new FileInputStream(file);
    final FileChannel channel = inputStream.getChannel();
    try {
      while (data.hasRemaining()) {
        channel.read(data);
      }
      data.clear();
    } finally {
      inputStream.close();
    }

    fileCount = data.getShort();
    // skip maxDepth
    data.position(data.position() + 2);
    tagCount = data.getInt();
    tagDescriptorsOffset = data.getInt();
    tagNamesOffset = data.getInt();
    fileDescriptorsOffset = data.getInt();
    fileDataSectionOffset = data.getInt();

    // 1-based
    names = new CharSequence[tagCount + 1];
  }
コード例 #15
0
ファイル: DrawPanel.java プロジェクト: bungaca/abstools
  public void initialize() {
    buffer = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
    // #if (Black_P1)
    // @        	player_1 = new Entity(100,100, "imgs/Tank_Black.gif", "SP1");
    // #elif (Red_P1)
    // @        	player_1 = new Entity(100,100, "imgs/Tank_Red.gif", "SP1");
    // #elif (Red_Tier1_P1)
    // @        	player_1 = new Entity(100,100, "imgs/Tier1rot.gif", "SP1");
    // #elif (Yellow_Tier1_P1)
    player_1 = new Entity(100, 100, "imgs/Tier1gelb.gif", "SP1");
    // #elif (Blue_Tier2_P1)
    // @        	player_1 = new Entity(100,100, "imgs/Tier2blau.gif", "SP1");
    // #elif (Green_Tier2_P1)
    // @        	player_1 = new Entity(100,100, "imgs/Tier2gruen.gif", "SP1");
    // #endif

    // #if (Black_P2)
    // @        	player_2 = new Entity(200,100, "imgs/Tank_Black.gif", "SP2");
    // #elif (Red_P2)
    // @        	player_2 = new Entity(200,100, "imgs/Tank_Red.gif", "SP2");
    // #elif (Red_Tier1_P2)
    // @        	player_2 = new Entity(200,100, "imgs/Tier1rot.gif", "SP2");
    // #elif (Yellow_Tier1_P2)
    // @        	player_2 = new Entity(200,100, "imgs/Tier1gelb.gif", "SP2");
    // #elif (Blue_Tier2_P2)
    // @        	player_2 = new Entity(200,100, "imgs/Tier2blau.gif", "SP2");
    // #elif (Green_Tier2_P2)
    player_2 = new Entity(200, 100, "imgs/Tier2gruen.gif", "SP2");
    // #endif

    current_Player = player_1;
    other_Player = player_2;
    env = new Environment[amountEnv];
    powerUps = new PowerUp[9];

    for (int i = 0; i <= amountEnv - 1; i++) {
      // #if (Hinderniss_Set)
      // @                if (Math.random()>0.95) env[i] = new
      // Environment("imgs/HindernisseBearbeitet/_b.GIF");
      // @                else if (Math.random()>0.90)env[i] = new
      // Environment("imgs/HindernisseBearbeitet/MauerDunkelrot_b.gif");
      // @                else if (Math.random()>0.85)env[i] = new
      // Environment("imgs/mauer_hoch.gif");
      // @                else if (Math.random()>0.80)env[i] = new
      // Environment("imgs/HindernisseBearbeitet/BaumStamm.gif");
      // @                else if (Math.random()>0.75)env[i] = new
      // Environment("imgs/HindernisseBearbeitet/BaumKlein.gif");
      // @                else if (Math.random()>0.70)env[i] = new
      // Environment("imgs/HindernisseBearbeitet/BaumKlein_b.GIF");
      // @                else if (Math.random()>0.65)env[i] = new
      // Environment("imgs/HindernisseBearbeitet/BaumStamm.gif");
      // @                else if (Math.random()>0.60)env[i] = new
      // Environment("imgs/HindernisseBearbeitet/BaumStamm_b.GIF");
      // @                else if (Math.random()>0.55)env[i] = new
      // Environment("imgs/HindernisseBearbeitet/MauerDunkelrot_b.gif");
      // @                else if (Math.random()>0.50)env[i] = new
      // Environment("imgs/HindernisseBearbeitet/MauerDunkelrot.gif");
      // @                else if (Math.random()>0.45)env[i] = new
      // Environment("imgs/HindernisseBearbeitet/MauerDunkelrot_b.GIF");
      // @                else if (Math.random()>0.40)env[i] = new
      // Environment("imgs/HindernisseBearbeitet/MauerGrauKurz.gif");
      // @                else if (Math.random()>0.35)env[i] = new
      // Environment("imgs/HindernisseBearbeitet/MauerGrauKurz_b.GIF");
      // @                else if (Math.random()>0.30)env[i] = new
      // Environment("imgs/HindernisseBearbeitet/MauerGrauKurzDick.gif");
      // @                else if (Math.random()>0.25)env[i] = new
      // Environment("imgs/HindernisseBearbeitet/MauerGrauKurzDick_b.GIF");
      // @                else if (Math.random()>0.20)env[i] = new
      // Environment("imgs/Haus_vonOben.gif");
      // @                else if (Math.random()>0.15)env[i] = new
      // Environment("imgs/HindernisseBearbeitet/MauerGrauLangDick.gif");
      // @                else if (Math.random()>0.10)env[i] = new
      // Environment("imgs/HindernisseBearbeitet/MauerGrauLangDick_b.GIF");
      // @                else if (Math.random()>0.05)env[i] = new
      // Environment("imgs/HindernisseBearbeitet/MauerRot.gif");
      // @                else env[i] = new Environment("imgs/Haus_vonOben_b.GIF");
      // @            //}
      // #else
      if (Math.random() > 0.75)
        env[i] = new Environment("imgs/HindernisseBearbeitet/Pfuetze1.gif.gif");
      else if (Math.random() > 0.50)
        env[i] = new Environment("imgs/HindernisseBearbeitet/PfuetzeGross.gif");
      else if (Math.random() > 0.25)
        env[i] = new Environment("imgs/HindernisseBearbeitet/PfuetzeKlein.gif");
      else env[i] = new Environment("imgs/HindernisseBearbeitet/PfuetzeMittel.gif");
      // #endif

      env[i].setX((int) (150 + Math.random() * (w - 200)));
      env[i].setY((int) (50 + Math.random() * (h - 200)));
    }
    int i = 0;
    while (true) {
      // #if (Flower)
      if (i == 9) break;
      powerUps[i] = new PowerUp(i, "imgs/PowerUpsBearbeitet/PowerUpBlume.gif");
      i++;
      // #endif
      // #if (Blue_Flower)
      if (i == 9) break;
      powerUps[i] = new PowerUp(i, "imgs/PowerUpsBearbeitet/PowerUpBlumeBlau.gif");
      i++;
      // #endif
      // #if (Copy)
      if (i == 9) break;
      powerUps[i] = new PowerUp(i, "imgs/PowerUpsBearbeitet/PowerUpCopy.gif");
      i++;
      // #endif
      // #if (Fire)
      // @        	if (i == 9) break;
      // @    	powerUps[i] = new PowerUp(i, "imgs/PowerUpsBearbeitet/PowerUpFeuer.gif");
      // @        i++;
      // #endif
      // #if (Light_Bulb_Round)
      if (i == 9) break;
      powerUps[i] = new PowerUp(i, "imgs/PowerUpsBearbeitet/PowerUpGluehbirneRund.gif");
      i++;
      // #endif
      // #if (Green)
      // @        	if (i == 9) break;
      // @    	powerUps[i] = new PowerUp(i, "imgs/PowerUpsBearbeitet/PowerUpGruen.gif");
      // @        i++;
      // #endif
      // #if (Heart)
      // @        	if (i == 9) break;
      // @    	powerUps[i] = new PowerUp(i, "imgs/PowerUpsBearbeitet/PowerUpHerz.gif");
      // @        i++;
      // #endif
      // #if (Circle)
      // @        	if (i == 9) break;
      // @    	powerUps[i] = new PowerUp(i, "imgs/PowerUpsBearbeitet/PowerUpKreis.gif");
      // @        i++;
      // #endif
      // #if (Cow)
      // @        	if (i == 9) break;
      // @    	powerUps[i] = new PowerUp(i, "imgs/PowerUpsBearbeitet/PowerUpKuh.gif");
      // @        i++;
      // #endif
      // #if (Light_Bulb)
      if (i == 9) break;
      powerUps[i] = new PowerUp(i, "imgs/PowerUpsBearbeitet/PowerUpLightbulb.gif");
      i++;
      // #endif
      // #if (Octagonal)
      // @        	if (i == 9) break;
      // @    	powerUps[i] = new PowerUp(i, "imgs/PowerUpsBearbeitet/PowerUpOctagonal.gif");
      // @        i++;
      // #endif
      // #if (Mushroom)
      if (i == 9) break;
      powerUps[i] = new PowerUp(i, "imgs/PowerUpsBearbeitet/PowerUpPilz.gif");
      i++;
      // #endif
      // #if (Pumpkin_Pie)
      // @	       if (i == 9) break;
      // @	    	powerUps[i] = new PowerUp(i, "imgs/PowerUpsBearbeitet/PowerUpPumpkinPie.gif");
      // @	        i++;
      // #endif
      // #if (Ring)
      if (i == 9) break;
      powerUps[i] = new PowerUp(i, "imgs/PowerUpsBearbeitet/PowerUpRing.gif");
      i++;
      // #endif
      // #if (Ring_2)
      if (i == 9) break;
      powerUps[i] = new PowerUp(i, "imgs/PowerUpsBearbeitet/PowerUpRingeZwei.gif");
      i++;
      // #endif
      // #if (Ring_Oval)
      if (i == 9) break;
      powerUps[i] = new PowerUp(i, "imgs/PowerUpsBearbeitet/PowerUpRingOval.gif");
      i++;
      // #endif
      // #if (Ring_Oval_Small)
      if (i == 9) break;
      powerUps[i] = new PowerUp(i, "imgs/PowerUpsBearbeitet/PowerUpRingOvalKlein.gif");
      i++;
      // #endif
      // #if (Sponge)
      // @    	if (i == 9) break;
      // @    	powerUps[i] = new PowerUp(i, "imgs/PowerUpsBearbeitet/PowerUpSchwamm.gif");
      // @    	i++;
      // #endif
      // #if (Spiral)
      // @    	if (i == 9) break;
      // @    	powerUps[i] = new PowerUp(i, "imgs/PowerUpsBearbeitet/PowerUpSpiral.gif");
      // @    	i++;
      // #endif
      // #if (Star_Oval)
      if (i == 9) break;
      powerUps[i] = new PowerUp(i, "imgs/PowerUpsBearbeitet/PowerUpSternOval.gif");
      i++;
      // #endif
      // #if (Star_Oval_Small)
      if (i == 9) break;
      powerUps[i] = new PowerUp(i, "imgs/PowerUpsBearbeitet/PowerUpSternOvalKlein.gif");
      i++;
      // #endif
      // #if (Star_Ring)
      if (i == 9) break;
      powerUps[i] = new PowerUp(i, "imgs/PowerUpsBearbeitet/PowerUpSternRing.gif");
      i++;
      // #endif
    }
    // #if (Nr1)
    powerUps[0].setX(50 + (int) (Math.random() * (w - 100)));
    powerUps[0].setY(50 + (int) (Math.random() * (h - 150)));
    // #else
    // @            powerUps[0].setX(-100);
    // @            powerUps[0].setY(-100);
    // #endif

    // #if (Nr2)
    powerUps[1].setX(50 + (int) (Math.random() * (w - 100)));
    powerUps[1].setY(50 + (int) (Math.random() * (h - 150)));
    // #else
    // @            powerUps[1].setX(-100);
    // @            powerUps[1].setY(-100);
    // #endif

    // #if (Nr3)
    powerUps[2].setX(50 + (int) (Math.random() * (w - 100)));
    powerUps[2].setY(50 + (int) (Math.random() * (h - 150)));
    // #else
    // @            powerUps[2].setX(-100);
    // @            powerUps[2].setY(-100);
    // #endif

    // #if (Nr4)
    powerUps[3].setX(50 + (int) (Math.random() * (w - 100)));
    powerUps[3].setY(50 + (int) (Math.random() * (h - 150)));
    // #else
    // @            powerUps[3].setX(-100);
    // @            powerUps[3].setY(-100);
    // #endif

    // #if (Nr5)
    powerUps[4].setX(50 + (int) (Math.random() * (w - 100)));
    powerUps[4].setY(50 + (int) (Math.random() * (h - 150)));
    // #else
    // @            powerUps[4].setX(-100);
    // @            powerUps[4].setY(-100);
    // #endif

    // #if (Nr6)
    powerUps[5].setX(50 + (int) (Math.random() * (w - 100)));
    powerUps[5].setY(50 + (int) (Math.random() * (h - 150)));
    // #else
    // @            powerUps[5].setX(-100);
    // @            powerUps[5].setY(-100);
    // #endif

    // #if (Nr7)
    powerUps[6].setX(50 + (int) (Math.random() * (w - 100)));
    powerUps[6].setY(50 + (int) (Math.random() * (h - 150)));
    // #else
    // @            powerUps[6].setX(-100);
    // @            powerUps[6].setY(-100);
    // #endif

    // #if (Nr8)
    powerUps[7].setX(50 + (int) (Math.random() * (w - 100)));
    powerUps[7].setY(50 + (int) (Math.random() * (h - 150)));
    // #else
    // @            powerUps[7].setX(-100);
    // @            powerUps[7].setY(-100);
    // #endif

  }
コード例 #16
0
ファイル: ScalarImage.java プロジェクト: JoeyPrink/TEALsim
  public BufferedImage getBufferedImage(int type, Color c) {

    BufferedImage image = null;
    float[] colComp = new float[3];
    c.getRGBColorComponents(colComp);
    double red = (double) colComp[0];
    double green = (double) colComp[1];
    double blue = (double) colComp[2];
    // System.out.println("blue, green, red = "+ blue +", " + green + ", " + red);

    double x = 0.0;
    double x2;
    switch (type) {
      case ScalarImage.TYPE_BYTE_RANDOM:
        {
          int numCol = 256;
          byte[] bBuf = new byte[numCol * 3];
          blue *= 255 * 4.;
          green *= 255 * 4.;
          red *= 255 * 4.;
          double delta = 1.0 / (double) (numCol + 1);
          int j = 0;
          for (int i = 0; i < numCol; i++) {
            if (i % 5 == 0) x = 0.7 * Math.random() + 0.3 * x;
            x2 = x * x;
            bBuf[j++] = (byte) clamp((510 - red) * x2 + (red - 255) * x);
            bBuf[j++] = (byte) clamp((510 - green) * x2 + (green - 255) * x);
            bBuf[j++] = (byte) clamp((510 - blue) * x2 + (blue - 255) * x);
            // x += delta;
          }
          IndexColorModel cm = new IndexColorModel(8, numCol, bBuf, 0, false);
          // image = new
          // BufferedImage(width,height,BufferedImage.TYPE_BYTE_INDEXED,cm);
          byte[] idxBuffer = new byte[size];
          for (int i = 0; i < size; i++) {
            idxBuffer[i] = (byte) (clamp(f[i] * 255.));
          }
          DataBufferByte dataBuffer = new DataBufferByte(idxBuffer, size);
          int idxOffset[] = {0};
          int idxBits[] = {8};
          try {
            ComponentSampleModel idxSampleModel =
                new ComponentSampleModel(DataBuffer.TYPE_BYTE, width, height, 1, width, idxOffset);
            WritableRaster rasterIdx =
                java.awt.image.Raster.createWritableRaster(
                    idxSampleModel, dataBuffer, new Point(0, 0));
            image = new BufferedImage(cm, rasterIdx, false, null);
          } catch (Exception e) {
            System.out.println("Exception caught while acquiring image:");
            System.out.println(e.getMessage());
          }
        }
        break;
      case BufferedImage.TYPE_BYTE_INDEXED:
        {
          int numCol = 256;
          byte[] bBuf = new byte[numCol * 3];
          blue *= 255 * 4.;
          green *= 255 * 4.;
          red *= 255 * 4.;
          double delta = 1.0 / (double) (numCol + 1);
          int j = 0;
          for (int i = 0; i < numCol; i++) {
            x2 = x * x;
            bBuf[j++] = (byte) clamp((510 - red) * x2 + (red - 255) * x);
            bBuf[j++] = (byte) clamp((510 - green) * x2 + (green - 255) * x);
            bBuf[j++] = (byte) clamp((510 - blue) * x2 + (blue - 255) * x);
            x += delta;
          }
          IndexColorModel cm = new IndexColorModel(8, numCol, bBuf, 0, false);
          // image = new
          // BufferedImage(width,height,BufferedImage.TYPE_BYTE_INDEXED,cm);
          byte[] idxBuffer = new byte[size];
          for (int i = 0; i < size; i++) {
            idxBuffer[i] = (byte) (clamp(f[i] * 255.));
          }
          DataBufferByte dataBuffer = new DataBufferByte(idxBuffer, size);
          int idxOffset[] = {0};
          int idxBits[] = {8};
          try {
            ComponentSampleModel idxSampleModel =
                new ComponentSampleModel(DataBuffer.TYPE_BYTE, width, height, 1, width, idxOffset);
            WritableRaster rasterIdx =
                java.awt.image.Raster.createWritableRaster(
                    idxSampleModel, dataBuffer, new Point(0, 0));
            image = new BufferedImage(cm, rasterIdx, false, null);
          } catch (Exception e) {
            System.out.println("Exception caught while acquiring image:");
            System.out.println(e.getMessage());
          }
        }
        break;
      case BufferedImage.TYPE_BYTE_GRAY:
        break;
      case BufferedImage.TYPE_3BYTE_BGR:
      default:
        byte[] byteBuffer = new byte[size * 3];
        blue *= 255 * 4.;
        green *= 255 * 4.;
        red *= 255 * 4.;

        int j = 0;
        for (int i = 0; i < size; i++) {
          x = f[i];
          x2 = x * x;
          /*
          byteBuffer[j++] = (byte)clamp( ( 2 * 255 - 4 * red ) * x * x + ( 4 * red - 255 ) * x);
          byteBuffer[j++] = (byte)clamp( ( 2 * 255 - 4 * green ) * x * x + ( 4 * green - 255 ) * x);
          byteBuffer[j++] = (byte)clamp( ( 2 * 255 - 4 * blue ) * x * x + ( 4 * blue - 255 ) * x);
          */
          byteBuffer[j++] = (byte) clamp((510 - red) * x2 + (red - 255) * x);
          byteBuffer[j++] = (byte) clamp((510 - green) * x2 + (green - 255) * x);
          byteBuffer[j++] = (byte) clamp((510 - blue) * x2 + (blue - 255) * x);
        }
        DataBufferByte dataBuffer = new DataBufferByte(byteBuffer, size * 3);
        int componentOffset[] = {0, 1, 2};
        int componentBits[] = {8, 8, 8};
        try {
          WritableRaster raster =
              java.awt.image.Raster.createWritableRaster(
                  new PixelInterleavedSampleModel(
                      DataBuffer.TYPE_BYTE, width, height, 3, width * 3, componentOffset),
                  dataBuffer,
                  new Point(0, 0));
          image =
              new BufferedImage(
                  new ComponentColorModel(
                      ColorSpace.getInstance(ColorSpace.CS_LINEAR_RGB),
                      componentBits,
                      false,
                      false,
                      ColorModel.OPAQUE,
                      DataBuffer.TYPE_BYTE),
                  raster,
                  false,
                  null);

        } catch (Exception e) {
          System.out.println("Exception caught while acquiring image:");
          System.out.println(e.getMessage());
        }
        break;
    }
    return image;
  }
コード例 #17
0
  /**
   * Constructor to create a character
   *
   * @param x X Position
   * @param y Y Position
   * @param w Width of Image
   * @param h Height of Image
   * @param FileN Name of image file
   * @param S Max number of frames
   */
  public GameCharacter(
      double x, double y, double w, double h, String FileN, int S, int Ty, String c) {
    // Set position and size
    X = x;
    Y = y;
    W = w;
    H = h;

    BASIC_PROCESS = new ProgressBar(new Font("Arial", 36, 36), this);
    BASIC_EFFECTS = new ProgressBar(new Font("Arial", 36, 36), this);
    // Add magic attacks
    // Fireball
    for (int i = 0; i < FIREBALL.length; i++) {
      FIREBALL[i] = new MagicAttack(-500, -500, 39, 41, "Fireball.png", 3, 1, 2, "Fireball");
      FIREBALL[i].STATS.setStats(new String[] {"Damage=10", "Points=10"});
      FIREBALL[i].CASTER = this;
    }
    // Shock
    for (int i = 0; i < SHOCK.length; i++) {
      SHOCK[i] = new MagicAttack(-500, -500, 39, 41, "Shock.png", 2, 1, 0, "Shock");
      SHOCK[i].STATS.setStats(new String[] {"Damage=20", "Points=15"});
      SHOCK[i].CASTER = this;
    }
    // Darkness
    for (int i = 0; i < DARKNESS.length; i++) {
      DARKNESS[i] = new MagicAttack(-500, -500, 165, 164, "Darkness.png", 3, 1, 2, "Darkness");
      DARKNESS[i].STATS.setStats(new String[] {"Damage=100", "Points=50"});
      DARKNESS[i].CASTER = this;
    }
    // Life Drain
    for (int i = 0; i < LIFE_DRAIN.length; i++) {
      LIFE_DRAIN[i] = new MagicAttack(-500, -500, 32, 32, "Life Drain.png", 7, 1, 0, "Life Drain");
      LIFE_DRAIN[i].STATS.setStats(new String[] {"Damage=50", "Points=25"});
      LIFE_DRAIN[i].CASTER = this;
    }
    // Get Image
    try {

      if (isJar()) {
        // Character
        imgCHARAC = getImage("/Graphics/Character/", FileN);

        // Blood
        int BloodType = (int) Math.round(Math.random() * 3) + 1;
        imgBLOOD = getImage("/Graphics/Effects/", "Dead" + BloodType + ".png");

        // Quest
        imgQStart = getImage("/Graphics/Effects/", "Quest_Start.png");
        imgQEnd = getImage("/Graphics/Effects/", "Quest_Complete.png");

      } else {
        // Character
        imgCHARAC = ImageIO.read(Paths.get(DIRECT + FileN).toFile());

        // Blood
        int BloodType = (int) Math.round(Math.random() * 3) + 1;
        imgBLOOD = ImageIO.read(Paths.get(DIRECT2 + "Dead" + BloodType + ".png").toFile());

        // Quest
        imgQStart = ImageIO.read(Paths.get(DIRECT2 + "Quest_Start.png").toFile());
        imgQEnd = ImageIO.read(Paths.get(DIRECT2 + "Quest_Complete.png").toFile());
      }

    } catch (Exception e) {
    }

    // Max number of frames
    SIZE = S;

    // Sprite type
    TYPE = Ty;

    // Assign class
    CLASS = c;
    Cl = c;

    // Add items and attacks according to class
    if (CLASS.equals("Player")) {

      // Add items
      INVENTORY.addItem(
          "Health Potion", 25, 1, "Health Pot.png", "Potion", new String[] {"Points=50"});
      INVENTORY.addItem(
          "Rusted Dagger",
          20,
          1,
          "Dagger_4.png",
          "Meele",
          new String[] {"Damage=10", "Attack Speed=1"});
      INVENTORY.addItem(
          "Wooden Staff",
          20,
          1,
          "Staff_1.png",
          "Meele",
          new String[] {"Damage=5", "Attack Speed=1"});

      // Equip items
      INVENTORY.ItemEffect(1, this);
      // MEELE_WEAPON=null;
      // Assign Magic
      SPELL_LIST.add(FIREBALL);

      // Inventory type
      INVENTORY.Type = "Player";
    } else if (CLASS.equals("Citizen")) {

      // Add items
      INVENTORY.addItem(
          "Health Potion", 25, 1, "Health Pot.png", "Potion", new String[] {"Points=50"});

      // Add Ai
      NAI = new NPCAI(this);

      // Add Gold
      this.GOLD = (int) Math.round(Math.random() * 15 + 5);

      INVENTORY.Type = "Friendly";
    } else if (CLASS.equals("Blacksmith")) {

      // Add items
      INVENTORY.addItem(
          "Silver Dagger",
          250,
          1,
          "Dagger_3.png",
          "Meele",
          new String[] {"Damage=10", "Attack Speed=1"});
      INVENTORY.addItem(
          "Steel Dagger",
          450,
          1,
          "Dagger_5.png",
          "Meele",
          new String[] {"Damage=35", "Attack Speed=1"});
      // INVENTORY.addItem("Assassin blade", 750,1, "Dagger_6.png","Meele",new
      // String[]{"Damage=45","Attack Speed=1"});
      // INVENTORY.addItem("Serpent Dagger", 5000,1, "Dagger_2.png","Meele",new
      // String[]{"Damage=50","Attack Speed=1"});
      // INVENTORY.addItem("Dagger of Time", 5050,1, "Dagger_1.png","Meele",new
      // String[]{"Damage=75","Attack Speed=1"});

      INVENTORY.addItem(
          "Steel Sword",
          450,
          1,
          "Sword_1.png",
          "Meele",
          new String[] {"Damage=30", "Attack Speed=0.65"});
      INVENTORY.addItem(
          "Iron Sword",
          50,
          1,
          "Sword_2.png",
          "Meele",
          new String[] {"Damage=15", "Attack Speed=0.65"});
      INVENTORY.addItem(
          "Silver Sword",
          100,
          1,
          "Sword_5.png",
          "Meele",
          new String[] {"Damage=20", "Attack Speed=0.5"});
      // INVENTORY.addItem("Iron Scimitar", 150,1, "Sword_7.png","Meele",new
      // String[]{"Damage=15","Attack Speed=0.75"});
      // INVENTORY.addItem("Steel Scimitar", 500,1, "Sword_4.png","Meele",new
      // String[]{"Damage=50","Attack Speed=0.75"});
      // INVENTORY.addItem("Steel Katana", 450,1, "Sword_6.png","Meele",new
      // String[]{"Damage=40","Attack Speed=0.95"});
      // INVENTORY.addItem("Butcher's Sword", 5000,1, "Sword_3.png","Meele",new
      // String[]{"Damage=100","Attack Speed=0.55"});
      // INVENTORY.addItem("Blood Thirster", 6000,1, "Sword_8.png","Meele",new
      // String[]{"Damage=200","Attack Speed=0.75"});

      INVENTORY.addItem(
          "Iron Hammer",
          150,
          1,
          "Hammer_1.png",
          "Meele",
          new String[] {"Damage=40", "Attack Speed=0.15"});
      // INVENTORY.addItem("Steel Hammer", 450,1, "Hammer_0.png","Meele",new
      // String[]{"Damage=60","Attack Speed=0.15"});
      // INVENTORY.addItem("Iron Mace", 50,1, "Mace_1.png","Meele",new String[]{"Damage=15","Attack
      // Speed=0.5"});

      INVENTORY.addItem("Steel Helmet", 250, 1, "Head_1.png", "H_armor", new String[] {"Armor=20"});
      INVENTORY.addItem("Iron Helmet", 150, 1, "Head_2.png", "H_armor", new String[] {"Armor=5"});
      // INVENTORY.addItem("Iron Horn Helmet", 350,1, "Head_6.png","H_armor",new
      // String[]{"Armor=50","Magic Resist=0"});
      // INVENTORY.addItem("Steel Horn Helmet", 500,1, "Head_7.png","H_armor",new
      // String[]{"Armor=80","Magic Resist=0"});
      // INVENTORY.addItem("Skysteel Helmet", 4000,1, "Head_4.png","H_armor",new
      // String[]{"Armor=60","Magic Resist=25"});

      INVENTORY.addItem(
          "Iron Cuirass", 250, 1, "Chest_4.png", "C_armor", new String[] {"Armor=20"});
      INVENTORY.addItem(
          "Steel Cuirass", 350, 1, "Chest_1.png", "C_armor", new String[] {"Armor=30"});
      // INVENTORY.addItem("Scale Cuirass", 550,1, "Chest_3.png","C_armor",new
      // String[]{"Armor=50"});
      // INVENTORY.addItem("Dark metal Cuirass", 750,1, "Chest_6.png","C_armor",new
      // String[]{"Armor=70"});
      // INVENTORY.addItem("Master Cuirass", 3050,1, "Chest_5.png","C_armor",new
      // String[]{"Armor=80","Magic Resist=25"});
      // INVENTORY.addItem("Legendary Cuirass", 3050,1, "Chest_2.png","C_armor",new
      // String[]{"Armor=100","Magic Resist=100"});

      INVENTORY.addItem(
          "Wooden Shield",
          50,
          1,
          "Shield_1.png",
          "Shield",
          new String[] {"Armor=5", "Magic Resist=0"});

      // Add AI
      NAI = new NPCAI(this);

      // Identify as trader
      INVENTORY.Type = "Trader";

      // Set Stats
      STATS.setStats(new String[] {"Level = 5 "});
      MAX_HEALTH = 200;
      HEALTH = (int) MAX_HEALTH;
    } else if (CLASS.equals("Alchemist")) {
      // Add Items
      INVENTORY.addItem(
          "Health Potion", 25, 50, "Health Pot.png", "Potion", new String[] {"Points=50"});
      INVENTORY.addItem(
          "Mana Potion", 20, 50, "Mana Pot.png", "Potion", new String[] {"Points=50"});
      INVENTORY.addItem(
          "Speed Potion", 10, 50, "Speed Pot.png", "Potion", new String[] {"Points=5"});
      // INVENTORY.addItem("Invisib Potion", 50, 10, "Invisibility Pot.png","Potion",new
      // String[]{"Points=5"});

      // Add AI
      NAI = new NPCAI(this);

      // Identify as trader
      INVENTORY.Type = "Trader";
    } else if (CLASS.equals("Inn Keeper")) {
      // Add Items
      INVENTORY.addItem("Roasted Fish", 15, 10, "Fish.png", "Food", new String[] {"Points=5"});
      INVENTORY.addItem("Apple", 15, 10, "Apple.png", "Food", new String[] {"Points=2"});

      // Add AI
      NAI = new NPCAI(this);

      // Identify as trader
      INVENTORY.Type = "Trader";
    } else if (CLASS.equals("Mage")) {

      INVENTORY.addItem(
          "Leather Cap",
          250,
          1,
          "Head_8.png",
          "H_armor",
          new String[] {"Armor=5", "Magic Resist=25"});
      INVENTORY.addItem(
          "Dark Leather Cap",
          300,
          1,
          "Head_9.png",
          "H_armor",
          new String[] {"Armor=5", "Magic Resist=50"});
      // INVENTORY.addItem("Jesters Cap", 500,1, "Head_5.png","H_armor",new
      // String[]{"Armor=10","Magic Resist=90"});
      // INVENTORY.addItem("Skull Helmet", 5000,1, "Head_3.png","H_armor",new
      // String[]{"Armor=100","Magic Resist=100"});
      INVENTORY.addItem(
          "Shock Spell Stone",
          250,
          1,
          "Stone_1.png",
          "SpellStoner",
          new String[] {"Damage=" + SHOCK[0].STATS.DAMAGE});
      // INVENTORY.addItem("Darkness Spell Stone", 500,1, "Stone_1.png","SpellStoner",new
      // String[]{"Damage="+DARKNESS[0].STATS.DAMAGE});
      INVENTORY.addItem(
          "Life Drain Spell Stone",
          300,
          1,
          "Stone_1.png",
          "SpellStoner",
          new String[] {"Damage=" + LIFE_DRAIN[0].STATS.DAMAGE});

      // Add AI
      NAI = new NPCAI(this);

      // Identify as trader
      INVENTORY.Type = "Trader";

    } else if (CLASS.equals("Skeleton")) {

      // Add items
      INVENTORY.addItem(
          "Bone Club", 5, 1, "Mace_2.png", "Meele", new String[] {"Damage=5", "Attack Speed=1"});

      // Add Gold
      this.GOLD = (int) Math.round(Math.random() * 10 + 2);

      // Use Item
      INVENTORY.ItemEffect(0, this);

      // Add AI
      EAI = new EnemyAI(this);
    } else if (CLASS.equals("Skeleton Chieftan")) {

      // Add Item
      INVENTORY.addItem(
          "Iron Sword",
          50,
          1,
          "Sword_2.png",
          "Meele",
          new String[] {"Damage=15", "Attack Speed=0.65"});
      INVENTORY.addItem(
          "Health Potion", 25, 1, "Health Pot.png", "Potion", new String[] {"Points=50"});

      // Add Gold
      this.GOLD = (int) Math.round(Math.random() * 50 + 25);

      // Use Item
      INVENTORY.ItemEffect(0, this);

      // Assign Stats
      STATS.LEVEL = 3;
      HEALTH = 250;
      MAX_HEALTH = 250;

      // Opify
      Opify(1 / 1.25);

      // Add AI
      EAI = new EnemyAI(this);
    } else if (CLASS.equals("Shaman")) {

      // Add items
      INVENTORY.addItem(
          "Health Potion", 25, 1, "Health Pot.png", "Potion", new String[] {"Points=50"});

      // Add Ai
      NAI = new NPCAI(this);

    } else if (CLASS.equals("Dark Elf")) {

      // Add items
      INVENTORY.addItem(
          "Rusted Dagger",
          20,
          1,
          "Dagger_4.png",
          "Meele",
          new String[] {"Damage=10", "Attack Speed=1"});
      INVENTORY.addItem("Iron Helmet", 150, 1, "Head_2.png", "H_armor", new String[] {"Armor=5"});

      // Assign Stats
      STATS.LEVEL = 2;
      HEALTH = 150;
      MAX_HEALTH = 150;

      // Add Gold
      this.GOLD = (int) Math.round(Math.random() * 15 + 2);

      // Use Item
      INVENTORY.ItemEffect(0, this);
      INVENTORY.ItemEffect(1, this);

      // Add Ai
      EAI = new EnemyAI(this);

    } else if (CLASS.equals("Prisoner")) {
      INVENTORY.addItem("Key", 0, 1, "Key.png", "Key", new String[] {});
      // NAI= new NPCAI(this);
    }
  }
コード例 #18
0
  // NB For images  0,0 is the top left corner.
  public int[] doLabel(int[] src1_1d, int[] dest_1d, int width, int height) {

    int nextlabel = 1;
    int nbs[] = new int[4];
    int nbls[] = new int[4];

    // Get size of image and make 1d_arrays
    d_w = width;
    d_h = height;

    labels = new int[d_w * d_h / 3]; // the most there can be is 9/25 of the point

    int src1rgb;
    int result = 0;
    int px, py, count, found;

    labelsValid = false; // only set to true once we've complete the task
    // initialise labels
    for (int i = 0; i < labels.length; i++) labels[i] = i;

    // now Label the image
    for (int i = 0; i < src1_1d.length; i++) {

      src1rgb = src1_1d[i] & 0x000000ff;

      if (src1rgb == 0) {
        result = 0; // nothing here
      } else {

        // The 4 visited neighbours
        nbs[0] = getNeighbour(src1_1d, i, -1, 0);
        nbs[1] = getNeighbour(src1_1d, i, 0, -1);
        nbs[2] = getNeighbour(src1_1d, i, -1, -1);
        nbs[3] = getNeighbour(src1_1d, i, 1, -1);

        // Their corresponding labels
        nbls[0] = getNeighbour(dest_1d, i, -1, 0);
        nbls[1] = getNeighbour(dest_1d, i, 0, -1);
        nbls[2] = getNeighbour(dest_1d, i, -1, -1);
        nbls[3] = getNeighbour(dest_1d, i, 1, -1);

        // label the point
        if ((nbs[0] == nbs[1]) && (nbs[1] == nbs[2]) && (nbs[2] == nbs[3]) && (nbs[0] == 0)) {
          // all neighbours are 0 so gives this point a new label
          result = nextlabel;
          nextlabel++;
        } else { // one or more neighbours have already got labels
          count = 0;
          found = -1;
          for (int j = 0; j < 4; j++) {
            if (nbs[j] != 0) {
              count += 1;
              found = j;
            }
          }
          if (count == 1) {
            // only one neighbour has a label, so assign the same label to this.
            result = nbls[found];
          } else {
            // more than 1 neighbour has a label
            result = nbls[found];
            // Equivalence the connected points
            for (int j = 0; j < 4; j++) {
              if ((nbls[j] != 0) && (nbls[j] != result)) {
                associate(nbls[j], result);
              }
            }
          }
        }
      }

      dest_1d[i] = result;
    }

    // reduce labels ie 76=23=22=3 -> 76=3
    // done in reverse order to preserve sorting
    for (int i = labels.length - 1; i > 0; i--) {
      labels[i] = reduce(i);
    }

    /*now labels will look something like 1=1 2=2 3=2 4=2 5=5.. 76=5 77=5
    this needs to be condensed down again, so that there is no wasted
    space eg in the above, the labels 3 and 4 are not used instead it jumps
    to 5.
    */
    int condensed[] = new int[nextlabel]; // cant be more than nextlabel labels

    count = 0;
    for (int i = 0; i < nextlabel; i++) {
      if (i == labels[i]) condensed[i] = count++;
    }
    // Record the number of labels
    numberOfLabels = count - 1;

    // now run back through our preliminary results, replacing the raw label
    // with the reduced and condensed one, and do the scaling and offsets too

    // Now generate an array of colours which will be used to label the image
    int[] labelColors = new int[numberOfLabels + 1];
    int[] labelCnt = new int[numberOfLabels + 1];

    // Variable used to check if the color generated is acceptable
    boolean acceptColor = false;

    for (int i = 0; i < labelColors.length; i++) {
      labelCnt[i] = 0;
      acceptColor = false;
      while (!acceptColor) {
        double tmp = Math.random();
        labelColors[i] = (int) (tmp * 16777215);
        if (((labelColors[i] & 0x000000ff) < 200)
            && (((labelColors[i] & 0x0000ff00) >> 8) < 64)
            && (((labelColors[i] & 0x00ff0000) >> 16) < 64)) {
          // Color to be rejected so don't set acceptColor
        } else {
          acceptColor = true;
        }
      }
      if (i == 0) labelColors[i] = 0;
    }

    countMax = 0;
    for (int i = 0; i < src1_1d.length; i++) {
      result = condensed[labels[dest_1d[i]]];
      labelCnt[result]++;
      if (countMax < labelCnt[result] && result != 0) {
        countMax = labelCnt[result];
        colorMax = labelColors[result] + 0xff000000;
      }

      // result = (int) ( scale * (float) result + oset );
      // truncate if necessary
      // if( result > 255 ) result = 255;
      // if( result <  0  ) result = 0;
      // produce grayscale
      // dest_1d[i] =  0xff000000 | (result + (result << 16) + (result << 8));
      dest_1d[i] = labelColors[result] + 0xff000000;
    }

    labelsValid = true; // only set to true now we've complete the task
    return dest_1d;
  }