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

Start implementing mash lifetime.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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
Note: See TracChangeset for help on using the changeset viewer.