Changeset 348


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.

Location:
trunk/monsterz
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/monsterz/board.cpp

    r340 r348  
    317317            /* The mash becomes the new owner of the disappearing piece */
    318318            mash->AddPiece(data->pairs[i][j].piece);
    319             data->thumbs->AddCount(data->pairs[i][j].id - 1, 1);
     319            data->thumbs->AddCount(data->pairs[i][j].id, 1);
    320320
    321321#if 0 // Test for piece creation
  • 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;
  • trunk/monsterz/fusion.h

    r345 r348  
    2424{
    2525public:
    26     Fusion(int2 dim, int npieces, int maxnpieces);
     26    Fusion(int2 dim, int minnpieces, int maxnpieces);
    2727    virtual ~Fusion();
    2828
     
    3232
    3333private:
     34    int GetRandomId() const;
    3435    void Resolve();
    3536    int TagNeighbours(int list[MAX_PIECES][MAX_PIECES], int i, int j);
  • trunk/monsterz/interface.cpp

    r345 r348  
    8383            Ticker::Unref(data->title);
    8484            data->title = NULL;
    85             data->fusion = new Fusion(int2(8, 7), 4, 12);
     85            data->fusion = new Fusion(int2(8, 7), 3, 12);
    8686            Ticker::Ref(data->fusion);
    8787#if 0
  • trunk/monsterz/thumbs.cpp

    r345 r348  
    9595void Thumbs::AddCount(int id, int count)
    9696{
    97     if (id >= 0 && id < data->npieces)
    98         data->count[id] += count;
     97    if (id > 0 && id <= data->npieces)
     98        data->count[id - 1] += count;
     99}
     100
     101int Thumbs::GetCount(int id)
     102{
     103    if (id > 0 && id <= data->npieces)
     104        return data->count[id - 1];
     105    else
     106        return 0;
    99107}
    100108
  • trunk/monsterz/thumbs.h

    r345 r348  
    2929    void SetMax(int npieces);
    3030    void AddCount(int id, int count);
     31    int GetCount(int id);
    3132
    3233protected:
Note: See TracChangeset for help on using the changeset viewer.