Changeset 248


Ignore:
Timestamp:
Jan 20, 2011, 2:59:43 PM (12 years ago)
Author:
sam
Message:

Make swaps effective now, just for testing purposes.

Location:
trunk/monsterz
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/monsterz/board.cpp

    r245 r248  
    121121            if (cur_cell.i < 0 || cur_cell.i >= 8
    122122                 || cur_cell.j < 0 || cur_cell.j >= 8
    123                  || (cur_pos - cur_cell * 48).sqlen() > 24 * 24)
     123                 || (cur_pos - cur_cell * 48).sqlen() > 24 * 24
     124                 || (cur_cell - data->src_cell).sqlen() != 1)
    124125                cur_cell = Int2(-1);
    125             /* If target cell changed, change destinations. */
     126            /* If potential target changed, update our cache. */
    126127            if (cur_cell != data->dst_cell)
    127128            {
     
    129130                    data->pieces[data->dst_cell.i]
    130131                                [data->dst_cell.j]->Goto(data->dst_cell * 48);
    131                 if (cur_cell != Int2(-1)
    132                      && (cur_cell - data->src_cell).sqlen() == 1)
     132                if (cur_cell != Int2(-1))
    133133                    data->pieces[cur_cell.i]
    134134                                [cur_cell.j]->Goto(data->src_cell * 48);
     
    136136            }
    137137        }
    138         if (!buttons[0] || mouse.x < 0 || mouse.y < 0)
     138        if (!buttons[0] || mouse.x < 0 || mouse.y < 0
     139             || (data->src_cell * 48
     140                  - data->grabbed->GetPos()).sqlen() > 100 * 100)
    139141        {
     142            if (data->dst_cell != Int2(-1))
     143            {
     144                Piece *src = data->pieces[data->src_cell.i][data->src_cell.j];
     145                Piece *dst = data->pieces[data->dst_cell.i][data->dst_cell.j];
     146                data->pieces[data->src_cell.i][data->src_cell.j] = dst;
     147                data->pieces[data->dst_cell.i][data->dst_cell.j] = src;
     148                src->SetCell(data->dst_cell);
     149                src->Goto(data->dst_cell * 48);
     150                dst->SetCell(data->src_cell);
     151                dst->Goto(data->src_cell * 48);
     152            }
    140153            data->grabbed->Ungrab();
    141             if (data->dst_cell != Int2(-1))
    142                 data->pieces[data->dst_cell.i]
    143                             [data->dst_cell.j]->Goto(data->dst_cell * 48);
    144154            data->state = BoardData::IDLE;
    145155        }
  • trunk/monsterz/piece.cpp

    r245 r248  
    6262}
    6363
     64void Piece::SetCell(Int2 cell)
     65{
     66    data->cell = cell;
     67}
     68
    6469Int2 Piece::GetPos() const
    6570{
  • trunk/monsterz/piece.h

    r245 r248  
    2323    virtual ~Piece();
    2424
     25    void SetCell(Int2 cell);
    2526    Int2 GetPos() const;
    2627
Note: See TracChangeset for help on using the changeset viewer.