Changeset 746


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.

Location:
trunk/monsterz
Files:
3 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
  • trunk/monsterz/board.h

    r664 r746  
    4242    /* Hunt mode */
    4343    void Fill();
    44     void Switch(vec2i cell_a, vec2i cell_b);
     44    bool Switch(vec2i cell_a, vec2i cell_b);
    4545    int ListMashes(int list[MAX_WIDTH][MAX_HEIGHT]);
    4646    int ListMoves(int list[MAX_WIDTH][MAX_HEIGHT]);
  • trunk/monsterz/mash.cpp

    r735 r746  
    8888        for (int n = 0; n < data->npieces && allready; n++)
    8989        {
    90             /* If piece is still too high, don't start the animation */
     90            /* If piece is still too far, don't start the animation */
    9191            vec2i shift = data->pieces[n]->GetShift();
    92             if (shift.y > 2 || abs(shift.x) > 2)
     92            if (abs(shift.y) + abs(shift.x) > 0)
    9393                allready = 0;
    9494        }
Note: See TracChangeset for help on using the changeset viewer.