Ignore:
Timestamp:
Mar 28, 2011, 1:31:29 AM (10 years ago)
Author:
sam
Message:

monsterz: perform move as soon as the grabbed piece is close to its
destination cell.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/monsterz/board.cpp

    r740 r746  
    237237            }
    238238        }
     239
     240        /* Move initiated: if valid, perform immediately. */
     241        if (data->dst_cell != vec2i(-1))
     242        {
     243            vec2i cell_a = data->src_cell;
     244            vec2i cell_b = data->dst_cell;
     245
     246            if (Switch(cell_a, cell_b))
     247                data->state = BoardData::HUNT_IDLE;
     248        }
     249
     250        /* Mouse released, or exited window, or dragged too far. */
    239251        if (!buttons[0] || mousepos.x == -1
    240252             || (data->src_cell * data->size - data->grabbed.piece->GetPos()
    241253                  - data->grabbed.piece->GetOffset()).sqlen() > 100 * 100)
    242254        {
    243             /* Mouse released, or exited window, or dragged too far. */
    244             data->grabbed.piece->Ungrab(data->grabbed.piece->GetCell() * data->size);
     255            vec2i cell_a = data->src_cell;
     256            BoardData::Pair a = data->pairs[cell_a.i][cell_a.j];
     257            a.piece->Ungrab(cell_a * data->size);
     258
    245259            if (data->dst_cell != vec2i(-1))
    246                 Switch(data->src_cell, data->dst_cell);
     260            {
     261                vec2i cell_b = data->dst_cell;
     262                BoardData::Pair b = data->pairs[cell_b.i][cell_b.j];
     263                b.piece->Ungrab(cell_b * data->size);
     264            }
     265
    247266            data->state = BoardData::HUNT_IDLE;
    248267        }
     
    392411}
    393412
    394 void Board::Switch(vec2i cell_a, vec2i cell_b)
     413bool Board::Switch(vec2i cell_a, vec2i cell_b)
    395414{
    396415    BoardData::Pair a = data->pairs[cell_a.i][cell_a.j];
     
    407426        data->pairs[cell_a.i][cell_a.j] = a;
    408427        data->pairs[cell_b.i][cell_b.j] = b;
    409         a.piece->Ungrab(cell_a * data->size);
    410         b.piece->Ungrab(cell_b * data->size);
    411         return;
     428        return false;
    412429    }
    413430
     
    541558            data->pairs[i][0].piece->SetBelow(below[i]);
    542559    }
     560
     561    return true;
    543562}
    544563
Note: See TracChangeset for help on using the changeset viewer.