Example #1
0
    // 새로운 도형을 목록에 추가한다.
    void AddNewShape() {
      Shape shape = new Shape();
      int idx;
      boolean bFindIntersect;
      Rect rt = new Rect();

      // 기존 도형과 겹치지 않는 새 위치를 찾는다.
      for (; ; ) {
        // 크기는 32, 48, 64 중 하나 선택
        int Size = 32 + 16 * Rnd.nextInt(3);

        // 위치는 난수로 선택
        rt.left = Rnd.nextInt(getWidth());
        rt.top = Rnd.nextInt(getHeight());
        rt.right = rt.left + Size;
        rt.bottom = rt.top + Size;

        // 화면을 벗어나면 안된다.
        if (rt.right > getWidth() || rt.bottom > getHeight()) {
          continue;
        }

        // 기존 도형 순회하며 겹치는지 조사한다.
        bFindIntersect = false;
        for (idx = 0; idx < arShape.size(); idx++) {
          if (rt.intersect(arShape.get(idx).rt) == true) {
            bFindIntersect = true;
          }
        }

        // 겹치지 않을 때 확정한다. 겹치면 계속 새 위치 선정한다.
        if (bFindIntersect == false) {
          break;
        }
      }

      // 새 도형 정보 작성. 모양, 색상 등을 난수 선택한다.
      shape.what = Rnd.nextInt(3);

      switch (Rnd.nextInt(5)) {
        case 0:
          shape.color = Color.WHITE;
          break;
        case 1:
          shape.color = Color.RED;
          break;
        case 2:
          shape.color = Color.GREEN;
          break;
        case 3:
          shape.color = Color.BLUE;
          break;
        case 4:
          shape.color = Color.YELLOW;
          break;
      }

      shape.rt = rt;
      arShape.add(shape);
    }
Example #2
0
  // 새로운 볼 생성
  static Ball Create(int x, int y, int Rad) {
    Random Rnd = new Random();
    Ball NewBall = new Ball();

    NewBall.x = x;
    NewBall.y = y;
    NewBall.rad = Rad;
    do {
      NewBall.dx = Rnd.nextInt(11) - 5;
      NewBall.dy = Rnd.nextInt(11) - 5;
    } while (NewBall.dx == 0 || NewBall.dy == 0);

    NewBall.count = 0;
    NewBall.color = Color.rgb(Rnd.nextInt(256), Rnd.nextInt(256), Rnd.nextInt(256));

    return NewBall;
  }
Example #3
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);
  }
Example #4
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;
  }