Esempio n. 1
0
  public ObsBall(int x, int y, int Rad, int sideDiff, int type) {
    this.x = x;
    this.y = y;
    this.rad = Rad;
    this.sideDiff = sideDiff;
    this.type = type;

    // hero 위치에 이만큼을 더해서, 그 범위 내에서는 장애물 생성 안되게 막으려고
    offsetFromHero = Rad * 25;

    // 속도 조절
    speed[0] = MainActivity.unitSpeed * 4;
    speed[1] = (int) (MainActivity.unitSpeed * 8);
    speed[2] = (int) (MainActivity.unitSpeed * 12);

    idx_speed = 0;

    // vx 정하기.
    vx = speed[idx_speed];
    vy = speed[idx_speed];

    if (Rnd.nextInt(1) == 0) vx *= -1;
    if (Rnd.nextInt(1) == 0) vy *= -1;
    //

    inCirclePnt = new Paint();
    inCirclePnt.setAntiAlias(true);
    if (type == TYPE_OBSTACLE) { // 장애물 볼
      red[0] = 135;
      green[0] = 206;
      blue[0] = 235;
      red[1] = 28;
      green[1] = 160;
      blue[1] = 217;
      red[2] = 16;
      green[2] = 94;
      blue[2] = 126;
      inCirclePnt.setColor(Color.rgb(red[idx_color], green[idx_color], blue[idx_color]));

    } else if (type == TYPE_ENERGY) { // 노란색 볼
      inCirclePnt.setColor(Color.rgb(243, 218, 150));

    } else if (type == ICE_OBSTACLE) { // 얼음 볼
      inCirclePnt.setColor(Color.WHITE);
    }

    outCirclePnt = new Paint();
    outCirclePnt.setAntiAlias(true);
    outCirclePnt.setColor(Color.BLACK);
    outCirclePnt.setStyle(Paint.Style.STROKE);
    outCirclePnt.setStrokeWidth(rad / 5);
  }
Esempio n. 2
0
  static ObsBall create(
      int Rad, int parentWidth, int buttonStartPoint_y, int barSize, HeroBall hero) {
    int x, y;

    do {
      if (Rnd.nextInt(10) % 2 == 0) {
        // 절반 확률로 왼쪽에서 생성
        x = 0 + barSize + Rad;

      } else {
        // 절반 확률로 오른쪽에서 생성
        x = parentWidth - barSize - Rad;
      }
      y = Rad + Rnd.nextInt(buttonStartPoint_y - barSize - Rad - Rad);

      // 만약 x, y가 hero 주변이라면 다시생성
    } while ((hero.x - offsetFromHero) < x
        && x < (hero.x + offsetFromHero)
        && (hero.y - offsetFromHero) < y
        && y < (hero.y + offsetFromHero));

    ObsBall ob;

    // 에너지공과 장애물이 1:1비율로 나온다
    // 그런데 에너지 공과 장애물이 만나면 독으로 변한다.
    if (obsCnt % 2 == 0) {
      ob = new ObsBall(x, y, Rad, barSize, TYPE_ENERGY);

    } else {
      ob = new ObsBall(x, y, Rad, barSize, TYPE_OBSTACLE);
    }

    // obsball이 생성될 때마다 하나씩 증가 시킨다.
    obsCnt++;

    return ob;
  }