Changeset 354


Ignore:
Timestamp:
Feb 4, 2011, 9:05:58 PM (10 years ago)
Author:
sam
Message:

Remove Piece::Blink and implement it as a timer inside Piece.

Location:
trunk/monsterz
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/monsterz/board.cpp

    r352 r354  
    6868    int2 oldmouse;
    6969    int3 oldbuttons;
    70     float nextblink, whipdelay;
     70    float whipdelay;
    7171
    7272    enum
     
    139139
    140140    data->mashes = NULL;
    141     data->nextblink = 0.0f;
    142141    data->whipdelay = 0.0f;
    143142
     
    160159
    161160    int3 buttons = Input::GetMouseButtons();
    162 
    163     /* If possible, make a random monster blink */
    164     if (data->game == Board::GAME_HUNT && (data->nextblink -= deltams) < 0.0f)
    165     {
    166         data->pairs[rand() % data->dim.i]
    167                    [rand() % data->dim.j].piece->Blink();
    168         data->nextblink = (float)(200 + rand() % 500);
    169     }
    170161
    171162    /* Do not whip too often, the sound may become annoying */
  • trunk/monsterz/monsterz.h

    r322 r354  
    4848static int const MAX_PIECES = 12;
    4949
    50 /* Duration of the idle loop */
     50/* Minimal duration of the idle loop */
    5151static int const DELAY_IDLE = 300;
     52/* Minimal delay before a blink */
     53static int const DELAY_BLINK = 10000;
    5254/* Duration of a blink */
    53 static int const DELAY_BLINK = 200;
     55static int const DURATION_BLINK = 200;
    5456/* Wait time until the next whip sound is allowed */
    5557static int const DELAY_WHIP = 300;
  • trunk/monsterz/piece.cpp

    r337 r354  
    3434    int2 cell, pos, src, dst;
    3535    int id;
    36     float speed, timer, idle;
     36    float speed, timer, blink, idle;
    3737
    3838    enum
     
    6666    data->state = PieceData::IDLE;
    6767    data->timer = RandF(DELAY_IDLE);
     68    data->blink = RandF(DELAY_BLINK);
    6869    data->idle = RandF(DELAY_IDLE, 2 * DELAY_IDLE);
    6970}
     
    140141{
    141142    return data->state == PieceData::DEAD;
    142 }
    143 
    144 int Piece::Blink()
    145 {
    146     switch (data->state)
    147     {
    148     case PieceData::IDLE:
    149         data->state = PieceData::BLINK;
    150         data->timer = DELAY_BLINK;
    151         return 1;
    152     default:
    153         return 0;
    154     }
    155143}
    156144
     
    242230        if (data->timer < 0.0f)
    243231            data->timer = data->idle = RandF(DELAY_IDLE, 2 * DELAY_IDLE);
     232        data->blink -= deltams;
     233        if (data->blink < 0.0f)
     234        {
     235            data->state = PieceData::BLINK;
     236            data->timer = DURATION_BLINK;
     237        }
    244238        break;
    245239    case PieceData::BLINK:
     
    249243            data->state = PieceData::IDLE;
    250244            data->timer = data->idle = RandF(DELAY_IDLE, 2 * DELAY_IDLE);
     245            data->blink = RandF(DELAY_BLINK, 2 * DELAY_BLINK);
    251246        }
    252247        break;
  • trunk/monsterz/piece.h

    r312 r354  
    3939    int IsDead() const;
    4040
    41     int Blink();
    4241    int Pop();
    4342    int Grab(int2 dir);
Note: See TracChangeset for help on using the changeset viewer.