Beispiel #1
0
//............................................................................
QState Mine1::planted(Mine1 *me, QEvent const *e) {
    uint8_t x;
    uint8_t y;
    uint8_t bmp;

    switch (e->sig) {
        case TIME_TICK_SIG: {
            if (me->m_x >= GAME_SPEED_X) {
                ObjectImageEvt *oie;

                me->m_x -= GAME_SPEED_X;               // move the mine 1 step

                // tell the Tunnel to draw the Mine
                oie = Q_NEW(ObjectImageEvt, MINE_IMG_SIG);
                oie->x   = me->m_x;
                oie->y   = me->m_y;
                oie->bmp = MINE1_BMP;
                AO_Tunnel->postFIFO(oie);
            }
            else {
                return Q_TRAN(&Mine1::unused);
            }
            return Q_HANDLED();
        }
        case SHIP_IMG_SIG: {
            x   = (uint8_t)((ObjectImageEvt const *)e)->x;
            y   = (uint8_t)((ObjectImageEvt const *)e)->y;
            bmp = (uint8_t)((ObjectImageEvt const *)e)->bmp;

            // test for incoming Ship hitting this mine
            if (do_bitmaps_overlap(MINE1_BMP, me->m_x, me->m_y, bmp, x, y)) {
                                       // Hit event with the type of the Mine1
                static MineEvt const mine1_hit(HIT_MINE_SIG, 1);
                AO_Ship->postFIFO(&mine1_hit);

                // go straight to 'disabled' and let the Ship do the exploding
                return Q_TRAN(&Mine1::unused);
            }
            return Q_HANDLED();
        }
        case MISSILE_IMG_SIG: {
            x   = (uint8_t)((ObjectImageEvt const *)e)->x;
            y   = (uint8_t)((ObjectImageEvt const *)e)->y;
            bmp = (uint8_t)((ObjectImageEvt const *)e)->bmp;

            // test for incoming Missile hitting this mine
            if (do_bitmaps_overlap(MINE1_BMP, me->m_x, me->m_y, bmp, x, y)) {
                            // Score event with the score for destroying Mine1
                static ScoreEvt const mine1_destroyed(DESTROYED_MINE_SIG, 25);
                AO_Missile->postFIFO(&mine1_destroyed);
                return Q_TRAN(&Mine1::exploding);
            }
            return Q_HANDLED();
        }
    }
    return Q_SUPER(&Mine1::used);
}
Beispiel #2
0
/* @(/2/4/3/2/1) ...........................................................*/
static QState Mine2_planted(Mine2 * const me, QEvt const * const e) {
    QState status_;
    switch (e->sig) {
        /* @(/2/4/3/2/1/0) */
        case TIME_TICK_SIG: {
            /* @(/2/4/3/2/1/0/0) */
            if (me->x >= GAME_SPEED_X) {
                ObjectImageEvt *oie;
                 me->x -= GAME_SPEED_X; /* move the mine 1 step */
                /* tell the Tunnel to draw the Mine */
                oie = Q_NEW(ObjectImageEvt, MINE_IMG_SIG);
                oie->x   = me->x;
                oie->y   = me->y;
                oie->bmp = MINE2_BMP;
                QACTIVE_POST(AO_Tunnel, (QEvt *)oie, me);
                status_ = QM_HANDLED();
            }
            /* @(/2/4/3/2/1/0/1) */
            else {
                static QActionHandler const act_[] = {
                    Q_ACTION_CAST(&Mine2_used_x),
                    Q_ACTION_CAST(0)
                };
                status_ = QM_TRAN(&Mine2_unused_s, &act_[0]);
            }
            break;
        }
        /* @(/2/4/3/2/1/1) */
        case SHIP_IMG_SIG: {
            uint8_t x   = Q_EVT_CAST(ObjectImageEvt)->x;
            uint8_t y   = Q_EVT_CAST(ObjectImageEvt)->y;
            uint8_t bmp = Q_EVT_CAST(ObjectImageEvt)->bmp;
            /* @(/2/4/3/2/1/1/0) */
            if (do_bitmaps_overlap(MINE2_BMP, me->x, me->y, bmp, x, y)) {
                static QActionHandler const act_[] = {
                    Q_ACTION_CAST(&Mine2_used_x),
                    Q_ACTION_CAST(0)
                };
                static MineEvt const mine1_hit = {
                    { HIT_MINE_SIG, 0U, 0U }, /* the QEvt base instance */
                    2U  /* type of the mine (2 for Mine type-2) */
                };
                 QACTIVE_POST(AO_Ship, (QEvt *)&mine1_hit, me);
                 /* go straight to 'disabled' and let the Ship do
                 * the exploding */
                status_ = QM_TRAN(&Mine2_unused_s, &act_[0]);
            }
            else {
                status_ = QM_UNHANDLED();
            }
            break;
        }
        /* @(/2/4/3/2/1/2) */
        case MISSILE_IMG_SIG: {
            uint8_t x   = Q_EVT_CAST(ObjectImageEvt)->x;
            uint8_t y   = Q_EVT_CAST(ObjectImageEvt)->y;
            uint8_t bmp = Q_EVT_CAST(ObjectImageEvt)->bmp;
            /* @(/2/4/3/2/1/2/0) */
            if (do_bitmaps_overlap(MINE2_MISSILE_BMP, me->x, me->y, bmp, x, y)) {
                static QActionHandler const act_[] = {
                    Q_ACTION_CAST(&Mine2_exploding_e),
                    Q_ACTION_CAST(0)
                };
                /* NOTE: Mine type-2 is nastier than Mine type-1.
                * The type-2 mine can hit the Ship with any of its
                * "tentacles". However, it can be destroyed by the
                * Missile only by hitting its center, defined as
                * a smaller bitmap MINE2_MISSILE_BMP.
                */
                static ScoreEvt const mine2_destroyed = {
                    { DESTROYED_MINE_SIG, 0U, 0U },  /* the QEvt base instance */
                    45U  /* score for destroying Mine type-2 */
                };
                QACTIVE_POST(AO_Missile, (QEvt *)&mine2_destroyed, me);
                status_ = QM_TRAN(&Mine2_exploding_s, &act_[0]);
            }
            else {
                status_ = QM_UNHANDLED();
            }
            break;
        }
        default: {
            status_ = QM_SUPER();
            break;
        }
    }
    return status_;
}
Beispiel #3
0
/*..........................................................................*/
QState Mine2_planted(Mine2 *me, QEvt const *e) {
    uint8_t x;
    uint8_t y;
    uint8_t bmp;

    switch (e->sig) {
        case TIME_TICK_SIG: {
            if (me->x >= GAME_SPEED_X) {
                ObjectImageEvt *oie;

                me->x -= GAME_SPEED_X;              /* move the mine 1 step */

                /* tell the Tunnel to draw the Mine */
                oie = Q_NEW(ObjectImageEvt, MINE_IMG_SIG);
                oie->x   = me->x;
                oie->y   = me->y;
                oie->bmp = MINE2_BMP;
                QACTIVE_POST(AO_Tunnel, (QEvt *)oie, me);
            }
            else {
                return Q_TRAN(&Mine2_unused);
            }
            return Q_HANDLED();
        }
        case SHIP_IMG_SIG: {
            x   = (uint8_t)((ObjectImageEvt const *)e)->x;
            y   = (uint8_t)((ObjectImageEvt const *)e)->y;
            bmp = (uint8_t)((ObjectImageEvt const *)e)->bmp;

            /* test for incoming Ship hitting this mine */
            if (do_bitmaps_overlap(MINE2_BMP, me->x, me->y, bmp, x, y)) {
                static MineEvt const mine2_hit = {
                    { HIT_MINE_SIG, 0, 0 },     /* the QEvt base instance */
                    2               /* type of the mine (2 for type-2 mine) */
                };
                QACTIVE_POST(AO_Ship, (QEvt *)&mine2_hit, me);

                /* go straight to 'disabled' and let the Ship do
                * the exploding
                */
                return Q_TRAN(&Mine2_unused);
            }
            return Q_HANDLED();
        }
        case MISSILE_IMG_SIG: {
            x   = (uint8_t)((ObjectImageEvt const *)e)->x;
            y   = (uint8_t)((ObjectImageEvt const *)e)->y;
            bmp = (uint8_t)((ObjectImageEvt const *)e)->bmp;

            /* test for incoming Missile hitting this mine */
            /* NOTE: Mine type-2 is nastier than Mine type-1.
            * The type-2 mine can hit the Ship with any of its
            * "tentacles". However, it can be destroyed by the
            * Missile only by hitting its center, defined as
            * a smaller bitmap MINE2_MISSILE_BMP.
            */
            if (do_bitmaps_overlap(MINE2_MISSILE_BMP,
                                   me->x, me->y, bmp, x, y))
            {
               static ScoreEvt const mine2_destroyed = {
                    { DESTROYED_MINE_SIG, 0, 0 },/*the QEvt base instance */
                    45                  /* score for destroying Mine type-2 */
                };
                QACTIVE_POST(AO_Missile, (QEvt *)&mine2_destroyed, me);
                return Q_TRAN(&Mine2_exploding);
            }
            return Q_HANDLED();
        }
    }
    return Q_SUPER(&Mine2_used);
}
Beispiel #4
0
/* ${AOs::Mine2::SM::used::planted} */
static QState Mine2_planted(Mine2 * const me, QEvt const * const e) {
    QState status_;
    switch (e->sig) {
        /* ${AOs::Mine2::SM::used::planted::TIME_TICK} */
        case TIME_TICK_SIG: {
            /* ${AOs::Mine2::SM::used::planted::TIME_TICK::[me->x>=GAME_S~]} */
            if (me->x >= GAME_SPEED_X) {
                ObjectImageEvt *oie;
                 me->x -= GAME_SPEED_X; /* move the mine 1 step */
                /* tell the Tunnel to draw the Mine */
                oie = Q_NEW(ObjectImageEvt, MINE_IMG_SIG);
                oie->x   = me->x;
                oie->y   = me->y;
                oie->bmp = MINE2_BMP;
                QACTIVE_POST(AO_Tunnel, (QEvt *)oie, me);
                status_ = QM_HANDLED();
            }
            /* ${AOs::Mine2::SM::used::planted::TIME_TICK::[else]} */
            else {
                static struct {
                    QMState const *target;
                    QActionHandler act[2];
                } const tatbl_ = { /* transition-action table */
                    &Mine2_unused_s, /* target state */
                    {
                        Q_ACTION_CAST(&Mine2_used_x), /* exit */
                        Q_ACTION_CAST(0) /* zero terminator */
                    }
                };
                status_ = QM_TRAN(&tatbl_);
            }
            break;
        }
        /* ${AOs::Mine2::SM::used::planted::SHIP_IMG} */
        case SHIP_IMG_SIG: {
            uint8_t x   = Q_EVT_CAST(ObjectImageEvt)->x;
            uint8_t y   = Q_EVT_CAST(ObjectImageEvt)->y;
            uint8_t bmp = Q_EVT_CAST(ObjectImageEvt)->bmp;
            /* ${AOs::Mine2::SM::used::planted::SHIP_IMG::[collisionwith~]} */
            if (do_bitmaps_overlap(MINE2_BMP, me->x, me->y, bmp, x, y)) {
                static struct {
                    QMState const *target;
                    QActionHandler act[2];
                } const tatbl_ = { /* transition-action table */
                    &Mine2_unused_s, /* target state */
                    {
                        Q_ACTION_CAST(&Mine2_used_x), /* exit */
                        Q_ACTION_CAST(0) /* zero terminator */
                    }
                };
                static MineEvt const mine1_hit = {
                    { HIT_MINE_SIG, 0U, 0U }, /* the QEvt base instance */
                    2U  /* type of the mine (2 for Mine type-2) */
                };
                 QACTIVE_POST(AO_Ship, (QEvt *)&mine1_hit, me);
                 /* go straight to 'disabled' and let the Ship do
                 * the exploding */
                status_ = QM_TRAN(&tatbl_);
            }
            else {
                status_ = QM_UNHANDLED();
            }
            break;
        }
        /* ${AOs::Mine2::SM::used::planted::MISSILE_IMG} */
        case MISSILE_IMG_SIG: {
            uint8_t x   = Q_EVT_CAST(ObjectImageEvt)->x;
            uint8_t y   = Q_EVT_CAST(ObjectImageEvt)->y;
            uint8_t bmp = Q_EVT_CAST(ObjectImageEvt)->bmp;
            /* ${AOs::Mine2::SM::used::planted::MISSILE_IMG::[collisionwith~]} */
            if (do_bitmaps_overlap(MINE2_MISSILE_BMP, me->x, me->y, bmp, x, y)) {
                static struct {
                    QMState const *target;
                    QActionHandler act[2];
                } const tatbl_ = { /* transition-action table */
                    &Mine2_exploding_s, /* target state */
                    {
                        Q_ACTION_CAST(&Mine2_exploding_e), /* entry */
                        Q_ACTION_CAST(0) /* zero terminator */
                    }
                };
                /* NOTE: Mine type-2 is nastier than Mine type-1.
                * The type-2 mine can hit the Ship with any of its
                * "tentacles". However, it can be destroyed by the
                * Missile only by hitting its center, defined as
                * a smaller bitmap MINE2_MISSILE_BMP.
                */
                static ScoreEvt const mine2_destroyed = {
                    { DESTROYED_MINE_SIG, 0U, 0U },  /* the QEvt base instance */
                    45U  /* score for destroying Mine type-2 */
                };
                QACTIVE_POST(AO_Missile, (QEvt *)&mine2_destroyed, me);
                status_ = QM_TRAN(&tatbl_);
            }
            else {
                status_ = QM_UNHANDLED();
            }
            break;
        }
        default: {
            status_ = QM_SUPER();
            break;
        }
    }
    return status_;
}
Beispiel #5
0
/*..........................................................................*/
QState Mine1_planted(Mine1 *me, QEvt const *e) {
    uint8_t x;
    uint8_t y;
    uint8_t bmp;

    switch (e->sig) {
        case TIME_TICK_SIG: {
            if (me->x >= GAME_SPEED_X) {
                ObjectImageEvt *oie;

                me->x -= GAME_SPEED_X;              /* move the mine 1 step */

                /* tell the Tunnel to draw the Mine */
                oie = Q_NEW(ObjectImageEvt, MINE_IMG_SIG);
                oie->x   = me->x;
                oie->y   = me->y;
                oie->bmp = MINE1_BMP;
                QACTIVE_POST(AO_Tunnel, (QEvt *)oie, me);
            }
            else {
                return Q_TRAN(&Mine1_unused);
            }
            return Q_HANDLED();
        }
        case SHIP_IMG_SIG: {
            x   = (uint8_t)((ObjectImageEvt const *)e)->x;
            y   = (uint8_t)((ObjectImageEvt const *)e)->y;
            bmp = (uint8_t)((ObjectImageEvt const *)e)->bmp;

            /* test for incoming Ship hitting this mine */
            if (do_bitmaps_overlap(MINE1_BMP, me->x, me->y, bmp, x, y)) {
                static MineEvt const mine1_hit = {
                    { HIT_MINE_SIG, 0, 0 },     /* the QEvt base instance */
                    1               /* type of the mine (1 for Mine type-1) */
                };
                QACTIVE_POST(AO_Ship, (QEvt *)&mine1_hit, me);

                /* go straight to 'disabled' and let the Ship do
                * the exploding
                */
                return Q_TRAN(&Mine1_unused);
            }
            return Q_HANDLED();
        }
        case MISSILE_IMG_SIG: {
            x   = (uint8_t)((ObjectImageEvt const *)e)->x;
            y   = (uint8_t)((ObjectImageEvt const *)e)->y;
            bmp = (uint8_t)((ObjectImageEvt const *)e)->bmp;

            /* test for incoming Missile hitting this mine */
            if (do_bitmaps_overlap(MINE1_BMP, me->x, me->y, bmp, x, y)) {
               static ScoreEvt const mine1_destroyed = {
                    { DESTROYED_MINE_SIG, 0, 0 },/*the QEvt base instance */
                    25                  /* score for destroying Mine type-1 */
                };
                QACTIVE_POST(AO_Missile, (QEvt *)&mine1_destroyed, me);
                return Q_TRAN(&Mine1_exploding);
            }
            return Q_HANDLED();
        }
    }
    return Q_SUPER(&Mine1_used);
}