Changeset 243


Ignore:
Timestamp:
Jan 19, 2011, 10:23:35 PM (10 years ago)
Author:
sam
Message:

Allow to immediately grab an ungrabbed piece if it is close enough.

Location:
trunk/monsterz
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/monsterz/board.cpp

    r238 r243  
    6666        {
    6767            int id = (35 + i + (i ^ (j + 13)) * (2 * j + 711)) % 9;
    68             data->pieces[i][j] = new Piece(game, i, j, 25 + 5 * id);
     68            data->pieces[i][j] = new Piece(game, Int2(i, j), 25 + 5 * id);
    6969            Ticker::Ref(data->pieces[i][j]);
    7070        }
  • trunk/monsterz/piece.cpp

    r241 r243  
    4949 */
    5050
    51 Piece::Piece(Game *game, int i, int j, int id)
     51Piece::Piece(Game *game, Int2 cell, int id)
    5252{
    5353    data = new PieceData();
     
    5555    Ticker::Ref(game);
    5656    data->tiler = Tiler::Register(PNG_TILES, 48, 48, 1.0f);
    57     data->cell = Int2(i, j);
    58     data->pos = Int2(i * 48, j * 48);
     57    data->cell = cell;
     58    data->pos = cell * 48;
    5959    data->id = id;
    6060    data->state = PieceData::IDLE;
     
    6767    case PieceData::IDLE:
    6868        data->state = PieceData::BLINK;
    69         data->timer = 400.0f;
     69        data->timer = 400.0f; /* Duration of a blink */
    7070        return 1;
    7171    default:
     
    7878    switch (data->state)
    7979    {
     80    case PieceData::UNGRAB:
     81        if ((data->cell * 48 - data->pos).sqlen() > 24 * 24)
     82            return 0;
     83        /* Fall through */
    8084    case PieceData::IDLE:
    8185    case PieceData::BLINK:
     
    119123        data->timer += deltams;
    120124        Int2 trip = data->cell * 48 - data->tmp;
    121         float total_time = trip.len() / 0.8f; /* Moving speed */
    122         float t = total_time ? data->timer / total_time : 1.0f;
     125        float moving_time = trip.len() / 0.8f; /* Moving speed */
     126        float t = moving_time ? data->timer / moving_time : 1.0f;
    123127        if (t >= 1.0f)
    124         {
    125128            t = 1.0f;
     129        if (data->timer > moving_time + 200.0f)
    126130            data->state = PieceData::IDLE;
    127         }
    128         data->pos = data->tmp + (t * trip + Float2(0.5f));
     131        data->pos = data->tmp + (t * trip + 0.5f);
    129132        break;
    130133    }
     
    154157        break;
    155158    case PieceData::UNGRAB:
    156         id = data->id + 2;
     159        if ((data->cell * 48 - data->tmp).sqlen() > 24 * 24)
     160            id = data->id + 2;
    157161        z = 4;
    158162        break;
    159163    }
     164
    160165    data->game->GetScene()->AddTile((data->tiler << 16) | id, x, y, z, 0);
     166
     167    if (data->state == PieceData::GRAB)
     168        data->game->GetScene()->AddTile((data->tiler << 16) | 0, x, y, z, 0);
    161169}
    162170
  • trunk/monsterz/piece.h

    r238 r243  
    2020{
    2121public:
    22     Piece(Game *game, int i, int j, int id);
     22    Piece(Game *game, Int2 cell, int id);
    2323    virtual ~Piece();
    2424
Note: See TracChangeset for help on using the changeset viewer.