示例#1
0
    public float calcDirOffset(Vector2 position, Tile.DIR4 dir)
    {
        float offset = 0.0f;
        // 지정된 위치와 블록의 현재 위치의 차를 나타내는 벡터.
        Vector2 v = position - new Vector2(
            this.transform.position.x, this.transform.position.y);

        switch (dir)
        {         // 지정된 방향에 따라 갈라진다.
        case Tile.DIR4.RIGHT:
            offset = v.x;
            break;

        case Tile.DIR4.LEFT:
            offset = -v.x;
            break;

        case Tile.DIR4.UP:
            offset = v.y;
            break;

        case Tile.DIR4.DOWN:
            offset = -v.y;
            break;
        }
        return(offset);
    }
示例#2
0
    public void swapTile(TileControl tile0, Tile.DIR4 dir, TileControl tile1)
    {
        // 각각의 블록 색을 기억해 둔다.
        Tile.COLOR color0 = tile0.color;
        //Tile.COLOR color1 = tile1.color;

        // 각각의 블록의.확대율을 기억해 둔다.
        Vector3 scale0 = tile0.transform.localScale;
        Vector3 scale1 = tile1.transform.localScale;

        // 각각의 블록의 사라지는 시간을 기억해 둔다.
        float vanish_timer0 = tile0.vanish_timer;
        float vanish_timer1 = tile1.vanish_timer;

        // 각각의 블록의 이동할 곳을 구한다.
        Vector3 offset0 = GamePlay.getDirVector(dir);
        Vector3 offset1 = GamePlay.getDirVector(GamePlay.getOppositDir(dir));

        //tile0.setColor(color1); // 색을 교체한다.
        tile1.setColor(color0);
        tile0.transform.localScale = scale1;        // 확대율을 교체한다.
        tile1.transform.localScale = scale0;
        tile0.vanish_timer         = vanish_timer1; // '사라지는 시간'을 교체한다.
        tile1.vanish_timer         = vanish_timer0;
        tile0.beginSlide(offset0);                  // 원래 블록 이동을 시작.
        tile1.beginSlide(offset1);                  // 이동할 위치의 블록 이동을 시작.
    }
示例#3
0
    public static Tile.DIR4 getOppositDir(Tile.DIR4 dir)
    {
        Tile.DIR4 opposit = dir;
        switch (dir)
        {
        case Tile.DIR4.RIGHT: opposit = Tile.DIR4.LEFT; break;

        case Tile.DIR4.LEFT: opposit = Tile.DIR4.RIGHT; break;

        case Tile.DIR4.UP: opposit = Tile.DIR4.DOWN; break;

        case Tile.DIR4.DOWN: opposit = Tile.DIR4.UP; break;
        }
        return(opposit);
    }
示例#4
0
    public static Vector3 getDirVector(Tile.DIR4 dir)
    {
        Vector3 v = Vector3.zero;

        switch (dir)
        {
        case Tile.DIR4.RIGHT: v = Vector3.right; break; // 오른쪽으로 1단위 이동.

        case Tile.DIR4.LEFT: v = Vector3.left; break;   // 왼쪽으로 1단위 이동.

        case Tile.DIR4.UP: v = Vector3.up; break;       // 위로 1단위 이동.

        case Tile.DIR4.DOWN: v = Vector3.down; break;   // 아래로 1단위 이동.
        }
        v *= Tile.COLLISION_SIZE;                       // 블록 크기를 곱한다.
        return(v);
    }
示例#5
0
    public TileControl getNextTile(
        TileControl tile, Tile.DIR4 dir)
    {
        // 슬라이드할 곳의 타일을 여기에 저장.
        TileControl next_tile = null;

        switch (dir)
        {
        case Tile.DIR4.RIGHT:
            if (tile.i_pos.x < Tile.TILE_NUM_X - 1)
            {
                next_tile = this.tiles[tile.i_pos.x + 1, tile.i_pos.y];
            }
            break;

        case Tile.DIR4.LEFT:
            if (tile.i_pos.x > 0)
            {
                next_tile = this.tiles[tile.i_pos.x - 1, tile.i_pos.y];
            }
            break;

        case Tile.DIR4.UP:
            if (tile.i_pos.y < Tile.TILE_NUM_Y - 1)
            {
                next_tile = this.tiles[tile.i_pos.x, tile.i_pos.y + 1];
            }
            break;

        case Tile.DIR4.DOWN:
            if (tile.i_pos.y > 0)
            {
                next_tile = this.tiles[tile.i_pos.x, tile.i_pos.y - 1];
            }
            break;
        }
        return(next_tile);
    }
示例#6
0
    public Tile.DIR4 calcSlideDir(Vector2 mouse_position)
    {
        Tile.DIR4 dir = Tile.DIR4.NONE;
        // 지정된 mouse_position과 현재 위치의 차를 나타내는 벡터.
        Vector2 v = mouse_position -
                    new Vector2(this.transform.position.x, this.transform.position.y);

        // 벡터의 크기가 0.1보다 크면.
        // (그보다 작으면 슬라이드 하지 않은 걸로 간주한다).
        if (v.magnitude > 0.1f)
        {
            if (v.y > v.x)
            {
                if (v.y > -v.x)
                {
                    dir = Tile.DIR4.UP;
                }
                else
                {
                    dir = Tile.DIR4.LEFT;
                }
            }
            else
            {
                if (v.y > -v.x)
                {
                    dir = Tile.DIR4.RIGHT;
                }
                else
                {
                    dir = Tile.DIR4.DOWN;
                }
            }
        }
        return(dir);
    }
示例#7
0
    void Update()
    {
        Vector3 mouse_position;         // 마우스 위치.

        this.tile_root.unprojectMousePosition(out mouse_position, Input.mousePosition);
        // 획득한 마우스 위치를 X와 Y만으로 한다.
        Vector2 mouse_position_xy = new Vector2(mouse_position.x, mouse_position.y);

        this.step_timer += Time.deltaTime;
        float slide_time = 0.2f;

        if (this.next_step == Tile.STEP.NONE)
        {         // '상태정보 없음'의 경우.
            switch (this.step)
            {
            case Tile.STEP.SLIDE:
                if (this.step_timer >= slide_time)
                {
                    // vanish_timer(사라질 때까지의 시간)이 0이면 VACANT(사라지는)상태로 이행.
                    if (this.vanish_timer == 0.0f)
                    {
                        this.next_step = Tile.STEP.VACANT;
                        // vanish_timer가 0이 아니면 IDLE(대기) 상태로 이행.
                    }
                    else
                    {
                        this.next_step = Tile.STEP.IDLE;
                    }
                }
                break;
            }
        }



        // 다음 블록 상태가 정보 없음 이외인 동안 -> 다음 블록 상태가 변경된 경우
        while (this.next_step != Tile.STEP.NONE)
        {
            this.step      = this.next_step;
            this.next_step = Tile.STEP.NONE;
            switch (this.step)
            {
            case Tile.STEP.IDLE:                     // 대기 상태
                this.position_offset      = Vector3.zero;
                this.transform.localScale = Vector3.one * 1.0f;
                break;

            case Tile.STEP.GRABBED:                     // 잡힌 상태
                this.transform.localScale = Vector3.one * 1.2f;
                break;

            case Tile.STEP.RELEASED:                     // 떨어져 있는 상태
                this.position_offset      = Vector3.zero;
                this.transform.localScale = Vector3.one * 1.0f;
                break;

            case Tile.STEP.VACANT:
                this.position_offset = Vector3.zero;
                break;
            }
            this.step_timer = 0.0f;
        }


        switch (this.step)
        {
        case Tile.STEP.GRABBED:                 // 잡힌 상태.
            // 잡힌 상태일 때는 항상 슬라이드 방향을 체크.
            this.slide_dir = this.calcSlideDir(mouse_position_xy);
            break;

        case Tile.STEP.SLIDE:                 // 슬라이드(교체) 중.
            // 블록을 서서히 이동하는 처리.
            float rate = this.step_timer / slide_time;
            rate = Mathf.Min(rate, 1.0f);
            rate = Mathf.Sin(rate * Mathf.PI / 2.0f);
            this.position_offset = Vector3.Lerp(this.position_offset_initial, Vector3.zero, rate);
            break;
        }


        //그리드 좌표를 실제 좌표로 변환
        Vector3 position = GamePlay.calcTilePosition(this.i_pos) + this.position_offset;

        // 실제 위치를 새로운 위치로 변경.
        this.transform.position = position;
    }