Ignore:
Timestamp:
Feb 4, 2011, 12:42:16 AM (10 years ago)
Author:
sam
Message:

Display spawn counts in Fusion mode, and generate random pieces accordingly.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/monsterz/fusion.cpp

    r346 r348  
    3636private:
    3737    int2 dim;
    38     int npieces, maxnpieces;
     38    int minnpieces, npieces, maxnpieces;
    3939    int board, tiles;
    4040
     
    6565 */
    6666
    67 Fusion::Fusion(int2 dim, int npieces, int maxnpieces)
     67Fusion::Fusion(int2 dim, int minnpieces, int maxnpieces)
    6868  : data(new FusionData())
    6969{
    7070    data->dim = dim;
    71     data->npieces = npieces;
     71    data->minnpieces = minnpieces;
     72    data->npieces = minnpieces;
    7273    data->maxnpieces = maxnpieces;
    7374    data->board = Tiler::Register(PNG_BOARD, 384, 384, 1.0f);
     
    7778    Ticker::Ref(data->emitter);
    7879
    79     data->thumbs = new Thumbs(npieces);
     80    data->thumbs = new Thumbs(minnpieces + 1);
    8081    Ticker::Ref(data->thumbs);
    8182
     
    8485            data->pairs[i][j].id = 0;
    8586
    86     data->current[0].id = 1 + rand() % data->npieces;
    87     data->current[1].id = 1 + rand() % data->npieces;
     87    data->current[0].id = GetRandomId();
     88    data->current[1].id = GetRandomId();
    8889    data->current[0].piece = new Piece(data->emitter, int2(3, 8),
    8990                                       80 + 20 * data->current[0].id);
     
    9798    data->mashes = NULL;
    9899
    99     data->next[0] = 1 + rand() % data->npieces;
    100     data->next[1] = 1 + rand() % data->npieces;
     100    data->next[0] = GetRandomId();
     101    data->next[1] = GetRandomId();
    101102    data->rotation = 0;
    102103
     
    179180                    data->current[t].piece->Move(int2(i, j) * 48);
    180181                    data->pairs[i][j] = data->current[t];
     182                    data->thumbs->AddCount(data->current[t].id, 1);
    181183                    break;
    182184                }
     
    195197        data->current[0].piece->Move(data->current[0].piece->GetCell() * 48);
    196198        data->current[1].piece->Move(data->current[1].piece->GetCell() * 48);
    197         data->next[0] = 1 + rand() % data->npieces;
    198         data->next[1] = 1 + rand() % data->npieces;
     199        data->next[0] = GetRandomId();
     200        data->next[1] = GetRandomId();
    199201        data->rotation = 0;
    200202
     
    215217    Scene::GetDefault()->AddTile((data->board << 16) | 0,
    216218                                 position.x, position.y, 1, 0);
     219}
     220
     221int Fusion::GetRandomId() const
     222{
     223    int max = data->npieces;
     224
     225    if (max > data->minnpieces)
     226        max--;
     227
     228    return 1 + rand() % max;
    217229}
    218230
     
    292304        Ticker::Ref(data->pairs[i][j].piece);
    293305        data->pairs[i][j].piece->SetPos(int2(i, j) * 48);
     306        data->thumbs->AddCount(data->pairs[i][j].id, 1);
    294307        count[list[i][j]] = 0;
    295308        list[i][j] = -1;
Note: See TracChangeset for help on using the changeset viewer.