Ignore:
Timestamp:
Jan 24, 2011, 2:45:58 AM (10 years ago)
Author:
sam
Message:

Implement vertical blocking of falling pieces.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/monsterz/piece.cpp

    r274 r276  
    197197}
    198198
    199 int Piece::Ungrab()
    200 {
    201     switch (data->state)
    202     {
    203     case PieceData::GRAB:
     199int Piece::Ungrab(Int2 pos)
     200{
     201    switch (data->state)
     202    {
     203    case PieceData::IDLE:
     204    case PieceData::BLINK:
     205    case PieceData::GRAB:
     206    case PieceData::UNGRAB:
     207    case PieceData::MOVE:
    204208        data->state = PieceData::UNGRAB;
     209        data->speed = 0.4f;
     210        data->timer = 0.0f;
     211        data->src = data->pos;
     212        data->dst = pos;
     213        return 1;
     214    default:
     215        return 0;
     216    }
     217}
     218
     219int Piece::Move(Int2 pos)
     220{
     221    switch (data->state)
     222    {
     223    case PieceData::IDLE:
     224    case PieceData::BLINK:
     225    case PieceData::UNGRAB:
     226    case PieceData::MOVE:
     227        data->state = PieceData::MOVE;
    205228        data->speed = 0.3f;
    206229        data->timer = 0.0f;
    207230        data->src = data->pos;
    208         data->dst = data->cell * 48;
    209         return 1;
    210     default:
    211         return 0;
    212     }
    213 }
    214 
    215 int Piece::Goto(Int2 pos, float speed)
    216 {
    217     switch (data->state)
    218     {
    219     case PieceData::IDLE:
    220     case PieceData::BLINK:
    221     case PieceData::UNGRAB:
    222     case PieceData::MOVE:
    223         data->state = PieceData::MOVE;
    224         data->timer = 0.0f;
    225         data->src = data->pos;
    226231        data->dst = pos;
    227         data->speed = speed;
    228232        return 1;
    229233    case PieceData::GRAB:
     
    255259        if (t >= 1.0f)
    256260            t = 1.0f;
     261        data->pos = data->src + (t * trip + 0.5f);
     262        /* If the piece below is blocking us, clamp our position and
     263         * start falling again. */
     264        if (data->state == PieceData::MOVE && data->below
     265             && data->pos.y < data->below->data->pos.y + 48)
     266        {
     267            data->pos.y = data->below->data->pos.y + 48;
     268            data->src = data->pos;
     269            data->timer = 0.0f;
     270        }
    257271        if (data->timer > moving_time + 200.0f)
    258272            data->state = PieceData::IDLE;
    259         data->pos = data->src + (t * trip + 0.5f);
    260273        break;
    261274    }
Note: See TracChangeset for help on using the changeset viewer.