Changeset 264


Ignore:
Timestamp:
Jan 23, 2011, 2:21:26 PM (9 years ago)
Author:
sam
Message:

Start implementing mash lifetime.

Location:
trunk/monsterz
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/monsterz/board.cpp

    r263 r264  
    107107    }
    108108
    109     /* Should we start dragging something? */
     109    /* Get rid of finished mashes */
     110    for (Mash **it = &data->mashes; *it; )
     111    {
     112        if ((*it)->IsFinished())
     113        {
     114            Ticker::Unref(*it);
     115            *it = (*it)->nextmash;
     116        }
     117        else
     118            it = &(*it)->nextmash;
     119    }
     120
    110121    switch (data->state)
    111122    {
    112123    case BoardData::IDLE:
     124        /* Should we start dragging something? */
    113125        if (buttons[0] && !data->buttons[0])
    114126        {
     
    133145        break;
    134146    case BoardData::GRAB:
     147        /* Should we stop dragging? */
    135148        if (mouse.x >= 0 && mouse.y >= 0)
    136149        {
     
    220233    do
    221234    {
    222 //        Mash *mash = new Mash(data->game);
    223 //        Ticker::Ref(mash);
     235        Mash *mash = new Mash(data->game);
     236        Ticker::Ref(mash);
    224237
    225238        for (int j = 8; j--;) for (int i = 0; i < 8; i++)
     
    229242
    230243            /* The mash becomes the new owner of the disappearing piece */
    231 //            mash->AddPiece(data->pieces[i][j], Int2(i, j));
    232             Ticker::Unref(data->pieces[i][j]);
     244            mash->AddPiece(data->pieces[i][j]);
    233245
    234246            Int2 newpos = data->pieces[i][7]->GetPos() + Int2(0, 48);
     
    247259            list[i][7] = 0;
    248260        }
     261
     262        mash->nextmash = data->mashes;
     263        data->mashes = mash;
    249264    }
    250265    while(ListMashes(list));
  • trunk/monsterz/mash.cpp

    r262 r264  
    1414
    1515#include <cstdio>
     16#include <cstdlib>
    1617#include <cmath>
    1718
     
    3233    Piece *pieces[8 * 8];
    3334    Int2 cells[8 * 8];
    34     int npieces;
     35    int npieces, finished;
    3536};
    3637
     
    4647    Ticker::Ref(game);
    4748    data->npieces = 0;
     49    data->finished = 0;
    4850}
    4951
     
    5557}
    5658
     59int Mash::IsFinished() const
     60{
     61    return data->finished;
     62}
     63
    5764void Mash::TickGame(float deltams)
    5865{
    5966    Entity::TickGame(deltams);
     67
     68    if (data->finished)
     69        return;
     70
     71    int inplace = 1;
     72    for (int n = 0; n < data->npieces && inplace; n++)
     73    {
     74        Int2 dest = data->pieces[n]->GetCell() * 48;
     75        Int2 cur = data->pieces[n]->GetPos();
     76
     77        if (abs(cur.x - dest.x) > 24)
     78            inplace = 0;
     79    }
     80
     81    if (inplace)
     82    {
     83        for (int n = 0; n < data->npieces; n++)
     84            Ticker::Unref(data->pieces[n]);
     85        data->finished = 1;
     86    }
    6087}
    6188
  • trunk/monsterz/mash.h

    r262 r264  
    2525
    2626    void AddPiece(Piece *piece);
     27    int IsFinished() const;
    2728
    2829protected:
Note: See TracChangeset for help on using the changeset viewer.