Changeset 320


Ignore:
Timestamp:
Jan 31, 2011, 12:24:56 PM (10 years ago)
Author:
sam
Message:

Display mashed monsterz statistics, up to 12 icons.

Location:
trunk
Files:
1 added
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/monsterz/board.cpp

    r314 r320  
    3535    int2 dim;
    3636    int npieces;
    37     int screen, board, tiles;
     37    int screen, board, tiles, icons;
    3838    int click, whip;
    3939
     
    4545    pairs[MAX_WIDTH][MAX_HEIGHT], grabbed;
    4646    int nmoves;
     47
     48    Text *counticons[MAX_PIECES];
     49    int counts[MAX_PIECES];
    4750
    4851    Mash *mashes;
     
    7578    data->board = Tiler::Register(PNG_BOARD, 384, 384, 1.0f);
    7679    data->tiles = Tiler::Register(PNG_TILES, 48, 48, 1.0f);
     80    data->icons = Tiler::Register(PNG_ICONS, 24, 24, 1.0f);
    7781    data->click = Sampler::Register(WAV_CLICK);
    7882    data->whip = Sampler::Register(WAV_WHIP);
     
    8791    data->whipdelay = 0.0f;
    8892    data->state = BoardData::IDLE;
     93
     94    for (int n = 0; n < MAX_PIECES; n++)
     95    {
     96        data->counts[n] = 0;
     97        data->counticons[n] = new Text(NULL, "monsterz/gfx/font2.png");
     98        int3 p = int3(476, 383 - 28 * n, 1);
     99        data->counticons[n]->SetPos(p);
     100    }
    89101}
    90102
     
    117129        else
    118130            it = &(*it)->nextmash;
     131    }
     132
     133    /* Update statistics */
     134    for (int n = 0; n < MAX_PIECES; n++)
     135    {
     136        char buf[128];
     137        sprintf(buf, "%i", data->counts[n]);
     138        data->counticons[n]->SetText(buf);
    119139    }
    120140
     
    202222    Scene::GetDefault()->AddTile((data->board << 16) | 0, 24, 72, 1, 0);
    203223
     224    /* Mini monsterz */
     225    for (int n = 0; n < MAX_PIECES; n++)
     226    {
     227        int2 p = int2(444, 380 - 28 * n);
     228        Scene::GetDefault()->AddTile((data->icons << 16) | n, p.x, p.y, 1, 0);
     229    }
     230
     231    /* Mouse pointer */
    204232    if (data->mouse.x >= 0 && data->mouse.y >= 0)
    205233    {
     
    309337            /* The mash becomes the new owner of the disappearing piece */
    310338            mash->AddPiece(data->pairs[i][j].piece);
     339            data->counts[data->pairs[i][j].id - 1]++;
    311340
    312341#if 0 // Test for piece creation
     
    513542    Tiler::Deregister(data->screen);
    514543    Tiler::Deregister(data->tiles);
     544    Tiler::Deregister(data->icons);
    515545    Sampler::Deregister(data->click);
    516546    Sampler::Deregister(data->whip);
  • trunk/monsterz/monsterz.h

    r314 r320  
    1515static char const * const PNG_BOARD = "monsterz/gfx/board.png";
    1616static char const * const PNG_TILES = "monsterz/gfx/tiles.png";
     17static char const * const PNG_ICONS = "monsterz/gfx/icons.png";
    1718
    1819static char const * const WAV_CLICK = "monsterz/sound/click.wav";
     
    2122static char const * const WAV_WHIP = "monsterz/sound/whip.wav";
    2223
    23 /* Maximum board size */
     24/* Maximum board size and number of piece types */
    2425static int const MAX_WIDTH = 8;
    2526static int const MAX_HEIGHT = 8;
     27static int const MAX_PIECES = 12;
    2628
    2729/* Duration of the idle loop */
  • trunk/src/font.cpp

    r318 r320  
    133133}
    134134
    135 void Font::Print(int x, int y, char const *str)
     135void Font::Print(int3 pos, char const *str)
    136136{
    137137    if (data->img)
     
    149149        {
    150150            glTexCoord2f(tx, ty + data->ty);
    151             glVertex2f(x, y);
     151            glVertex2f(pos.x, pos.y);
    152152            glTexCoord2f(tx + data->tx, ty + data->ty);
    153             glVertex2f(x + data->width, y);
     153            glVertex2f(pos.x + data->width, pos.y);
    154154            glTexCoord2f(tx + data->tx, ty);
    155             glVertex2f(x + data->width, y + data->height);
     155            glVertex2f(pos.x + data->width, pos.y + data->height);
    156156            glTexCoord2f(tx, ty);
    157             glVertex2f(x, y + data->height);
     157            glVertex2f(pos.x, pos.y + data->height);
    158158        }
    159159
    160         x += data->width;
     160        pos.x += data->width;
    161161    }
    162162    glEnd();
    163163}
    164164
    165 void Font::PrintBold(int x, int y, char const *str)
     165void Font::PrintBold(int3 pos, char const *str)
    166166{
    167167    static struct { int dx, dy; float r, g, b; } tab[] =
     
    184184    {
    185185        glColor3f(tab[i].r, tab[i].g, tab[i].b);
    186         Print(x + tab[i].dx, y + tab[i].dy, str);
     186        Print(pos + int3(tab[i].dx, tab[i].dy, 0), str);
    187187    }
    188188    glPopAttrib();
  • trunk/src/font.h

    r221 r320  
    3434public:
    3535    /* New methods */
    36     void Print(int x, int y, char const *str);
    37     void PrintBold(int x, int y, char const *str);
     36    void Print(int3 pos, char const *str);
     37    void PrintBold(int3 pos, char const *str);
    3838
    3939private:
  • trunk/src/text.cpp

    r319 r320  
    6666    {
    6767        Font *font = Forge::GetFont(data->font);
    68         font->Print(data->pos.x, data->pos.y, data->text);
     68        font->Print(data->pos, data->text);
    6969    }
    7070}
Note: See TracChangeset for help on using the changeset viewer.