/***************************************************************************** * Model: game.qm * File: ././missile.c * * This file has been generated automatically by QP Modeler (QM). * DO NOT EDIT THIS FILE MANUALLY. * * Please visit www.state-machine.com/qm for more information. *****************************************************************************/ #include "qp_port.h" #include "bsp.h" #include "game.h" /* Q_DEFINE_THIS_FILE */ /* local objects -----------------------------------------------------------*/ /* @(/2/2) .................................................................*/ /** * Missile Active Object */ typedef struct MissileTag { /* protected: */ QActive super; /* private: */ uint8_t x; uint8_t y; uint8_t exp_ctr; } Missile; /* protected: */ static QState Missile_initial(Missile * const me, QEvt const * const e); static QState Missile_armed(Missile * const me, QEvt const * const e); static QState Missile_flying(Missile * const me, QEvt const * const e); static QState Missile_exploding(Missile * const me, QEvt const * const e); static Missile l_missile; /* the sole instance of the Missile active object */ /* Public-scope objects ----------------------------------------------------*/ QActive * const AO_Missile = (QActive *)&l_missile; /* opaque pointer */ /* Active object definition ------------------------------------------------*/ /* @(/2/11) ................................................................*/ void Missile_ctor(void) { Missile *me = &l_missile; QActive_ctor(&me->super, (QStateHandler)&Missile_initial); } /* @(/2/2) .................................................................*/ /* @(/2/2/3) ...............................................................*/ /* @(/2/2/3/0) */ static QState Missile_initial(Missile * const me, QEvt const * const e) { (void)e; QActive_subscribe((QActive *)me, TIME_TICK_SIG); QS_OBJ_DICTIONARY(&l_missile); /* object dictionary for Missile object */ QS_FUN_DICTIONARY(&Missile_initial); /* dictionaries for Missile HSM */ QS_FUN_DICTIONARY(&Missile_armed); QS_FUN_DICTIONARY(&Missile_flying); QS_FUN_DICTIONARY(&Missile_exploding); QS_SIG_DICTIONARY(MISSILE_FIRE_SIG, &l_missile); /* local signals */ QS_SIG_DICTIONARY(HIT_WALL_SIG, &l_missile); QS_SIG_DICTIONARY(DESTROYED_MINE_SIG, &l_missile); return Q_TRAN(&Missile_armed); } /* @(/2/2/3/1) .............................................................*/ static QState Missile_armed(Missile * const me, QEvt const * const e) { QState status; switch (e->sig) { /* @(/2/2/3/1/0) */ case MISSILE_FIRE_SIG: { me->x = Q_EVT_CAST(ObjectPosEvt)->x; me->y = Q_EVT_CAST(ObjectPosEvt)->y; status = Q_TRAN(&Missile_flying); break; } default: { status = Q_SUPER(&QHsm_top); break; } } return status; } /* @(/2/2/3/2) .............................................................*/ static QState Missile_flying(Missile * const me, QEvt const * const e) { QState status; switch (e->sig) { /* @(/2/2/3/2/0) */ case TIME_TICK_SIG: { /* @(/2/2/3/2/0/0) */ if (me->x + GAME_MISSILE_SPEED_X < GAME_SCREEN_WIDTH) { ObjectImageEvt *oie; me->x += GAME_MISSILE_SPEED_X; /*tell the Tunnel to draw the Missile and test for wall hits*/ oie = Q_NEW(ObjectImageEvt, MISSILE_IMG_SIG); oie->x = me->x; oie->y = me->y; oie->bmp = MISSILE_BMP; QACTIVE_POST(AO_Tunnel, (QEvt *)oie, me); status = Q_HANDLED(); } /* @(/2/2/3/2/0/1) */ else { status = Q_TRAN(&Missile_armed); } break; } /* @(/2/2/3/2/1) */ case HIT_WALL_SIG: { status = Q_TRAN(&Missile_exploding); break; } /* @(/2/2/3/2/2) */ case DESTROYED_MINE_SIG: { QACTIVE_POST(AO_Ship, e, me); status = Q_TRAN(&Missile_armed); break; } default: { status = Q_SUPER(&QHsm_top); break; } } return status; } /* @(/2/2/3/3) .............................................................*/ static QState Missile_exploding(Missile * const me, QEvt const * const e) { QState status; switch (e->sig) { /* @(/2/2/3/3) */ case Q_ENTRY_SIG: { me->exp_ctr = 0U; status = Q_HANDLED(); break; } /* @(/2/2/3/3/0) */ case TIME_TICK_SIG: { /* @(/2/2/3/3/0/0) */ if ((me->x >= GAME_SPEED_X) && (me->exp_ctr < 15U)) { ObjectImageEvt *oie; ++me->exp_ctr; /* advance the explosion counter */ me->x -= GAME_SPEED_X; /* move the explosion by one step */ /* tell the Tunnel to render the current stage of Explosion */ oie = Q_NEW(ObjectImageEvt, EXPLOSION_SIG); oie->x = me->x + 3U; /* x-pos of explosion */ oie->y = (int8_t)((int)me->y - 4U); /* y-pos */ oie->bmp = EXPLOSION0_BMP + (me->exp_ctr >> 2); QACTIVE_POST(AO_Tunnel, (QEvt *)oie, me); status = Q_HANDLED(); } /* @(/2/2/3/3/0/1) */ else { status = Q_TRAN(&Missile_armed); } break; } default: { status = Q_SUPER(&QHsm_top); break; } } return status; }