Changeset 230


Ignore:
Timestamp:
Jan 19, 2011, 1:33:50 PM (10 years ago)
Author:
sam
Message:

Monsters can now blink.

Location:
trunk/monsterz
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/monsterz/board.cpp

    r227 r230  
    1515#include <cstdio>
    1616#include <cmath>
     17#include <cstdlib>
    1718
    1819#include "core.h"
     
    5051        for (int i = 0; i < 8; i++)
    5152        {
    52             int id = (35 + i + (i ^ j + 13) * (2 * j + 711)) % 9;
     53            int id = (35 + i + (i ^ (j + 13)) * (2 * j + 711)) % 9;
    5354            data->pieces[j][i] = new Piece(game, i, j, 25 + 5 * id);
    5455            Ticker::Ref(data->pieces[j][i]);
     
    5859void Board::TickGame(float deltams)
    5960{
     61    if (rand() % 20 == 0)
     62        data->pieces[rand() % 8][rand() % 8]->Blink();
    6063    Entity::TickGame(deltams);
    6164}
  • trunk/monsterz/piece.cpp

    r227 r230  
    3232    int tiler;
    3333    int i, j, id;
     34    float timer;
     35
     36    enum
     37    {
     38        IDLE,
     39        BLINK,
     40    }
     41    state;
    3442};
    3543
     
    4755    data->j = j;
    4856    data->id = id;
     57    data->state = PieceData::IDLE;
     58}
     59
     60void Piece::Blink()
     61{
     62    if (data->state == PieceData::IDLE)
     63    {
     64        data->state = PieceData::BLINK;
     65        data->timer = 400.0f;
     66    }
    4967}
    5068
    5169void Piece::TickGame(float deltams)
    5270{
     71    switch (data->state)
     72    {
     73    case PieceData::IDLE:
     74        break;
     75    case PieceData::BLINK:
     76        data->timer -= deltams;
     77        if (data->timer < 0.0f)
     78            data->state = PieceData::IDLE;
     79        break;
     80    }
    5381    Entity::TickGame(deltams);
    5482}
     
    6189    int i = data->i;
    6290    int j = data->j;
     91    if (data->state == PieceData::BLINK)
     92        id++;
    6393    data->game->GetScene()->AddTile((data->tiler << 16) | id,
    6494                                    i * 48 + 24, j * 48 + 177, 2, 0);
  • trunk/monsterz/piece.h

    r227 r230  
    2323    virtual ~Piece();
    2424
     25    void Blink();
     26
    2527protected:
    2628    virtual void TickGame(float deltams);
Note: See TracChangeset for help on using the changeset viewer.