/*.$file${.::ship.c} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/ /* * Model: game.qm * File: ${.::ship.c} * * This code has been generated by QM 4.6.0 . * DO NOT EDIT THIS FILE MANUALLY. All your changes will be lost. * * This program is open source software: you can redistribute it and/or * modify it under the terms of the GNU General Public License as published * by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * for more details. */ /*.$endhead${.::ship.c} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/ #include "qpn.h" #include "game.h" #include "bsp.h" /* Q_DEFINE_THIS_MODULE(ship) */ #define SHIP_WIDTH 5U #define SHIP_HEIGHT 3U /* encapsulated delcaration of the Ship active object ----------------------*/ /*.$declare${AOs::Ship} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/ /*.${AOs::Ship} ............................................................*/ typedef struct Ship { /* protected: */ QActive super; /* private: */ uint8_t x; uint16_t y; uint8_t exp_ctr; uint16_t score; } Ship; /* protected: */ static QState Ship_initial(Ship * const me); static QState Ship_active(Ship * const me); static QState Ship_parked(Ship * const me); static QState Ship_flying(Ship * const me); static QState Ship_exploding(Ship * const me); /*.$enddecl${AOs::Ship} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/ /* global objects ----------------------------------------------------------*/ Ship AO_Ship; /* Active object definition ------------------------------------------------*/ /*.$skip${QP_VERSION} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/ /*. Check for the minimum required QP version */ #if (QP_VERSION < 650U) || (QP_VERSION != ((QP_RELEASE^4294967295U) % 0x3E8U)) #error qpn version 6.5.0 or higher required #endif /*.$endskip${QP_VERSION} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/ /*.$define${AOs::Ship_ctor} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/ /*.${AOs::Ship_ctor} .......................................................*/ void Ship_ctor(void) { Ship *me = &AO_Ship; QActive_ctor(&me->super, Q_STATE_CAST(&Ship_initial)); me->x = GAME_SHIP_X; me->y = (GAME_SHIP_Y << 2); } /*.$enddef${AOs::Ship_ctor} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/ /*.$define${AOs::Ship} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/ /*.${AOs::Ship} ............................................................*/ /*.${AOs::Ship::SM} ........................................................*/ static QState Ship_initial(Ship * const me) { /*.${AOs::Ship::SM::initial} */ return Q_TRAN(&Ship_active); } /*.${AOs::Ship::SM::active} ................................................*/ static QState Ship_active(Ship * const me) { QState status_; switch (Q_SIG(me)) { /*.${AOs::Ship::SM::active::initial} */ case Q_INIT_SIG: { status_ = Q_TRAN(&Ship_parked); break; } default: { status_ = Q_SUPER(&QHsm_top); break; } } return status_; } /*.${AOs::Ship::SM::active::parked} ........................................*/ static QState Ship_parked(Ship * const me) { QState status_; switch (Q_SIG(me)) { /*.${AOs::Ship::SM::active::parked::TAKE_OFF} */ case TAKE_OFF_SIG: { status_ = Q_TRAN(&Ship_flying); break; } default: { status_ = Q_SUPER(&Ship_active); break; } } return status_; } /*.${AOs::Ship::SM::active::flying} ........................................*/ static QState Ship_flying(Ship * const me) { QState status_; switch (Q_SIG(me)) { /*.${AOs::Ship::SM::active::flying} */ case Q_ENTRY_SIG: { me->score = 0; /* reset the score */ QACTIVE_POST(&AO_Tunnel, SCORE_SIG, me->score); /* lauch the ship from the initial position */ me->x = GAME_SHIP_X; me->y = (GAME_SHIP_Y << 2); status_ = Q_HANDLED(); break; } /*.${AOs::Ship::SM::active::flying::TIME_TICK} */ case TIME_TICK_SIG: { /* move the Ship up or down depending on the button state */ if (BSP_isThrottle()) { if (me->y > 0) { me->y -= 1U; } } else { if (me->y < (GAME_TUNNEL_HEIGHT << 2)) { me->y += 1U; } } /* tell the Tunnel to draw the Ship and test for hits */ QACTIVE_POST(&AO_Tunnel, SHIP_IMG_SIG, (SHIP_BMP << 16) | me->x | ((me->y >> 2) << 8)); ++me->score; /* increment the score for surviving another tick */ if ((me->score % 10) == 0) { /* is the score "round"? */ QACTIVE_POST(&AO_Tunnel, SCORE_SIG, me->score); } status_ = Q_HANDLED(); break; } /*.${AOs::Ship::SM::active::flying::PLAYER_TRIGGER} */ case PLAYER_TRIGGER_SIG: { QACTIVE_POST(&AO_Missile, MISSILE_FIRE_SIG, me->x | (((me->y >> 2) - 1 + SHIP_HEIGHT) & 0xFFU) << 8); status_ = Q_HANDLED(); break; } /*.${AOs::Ship::SM::active::flying::DESTROYED_MINE} */ case DESTROYED_MINE_SIG: { me->score += (uint16_t)Q_PAR(me); /* the score will be sent to the Tunnel by the next TIME_TICK */ status_ = Q_HANDLED(); break; } /*.${AOs::Ship::SM::active::flying::HIT_WALL} */ case HIT_WALL_SIG: { status_ = Q_TRAN(&Ship_exploding); break; } /*.${AOs::Ship::SM::active::flying::HIT_MINE} */ case HIT_MINE_SIG: { status_ = Q_TRAN(&Ship_exploding); break; } default: { status_ = Q_SUPER(&Ship_active); break; } } return status_; } /*.${AOs::Ship::SM::active::exploding} .....................................*/ static QState Ship_exploding(Ship * const me) { QState status_; switch (Q_SIG(me)) { /*.${AOs::Ship::SM::active::exploding} */ case Q_ENTRY_SIG: { me->exp_ctr = 0; status_ = Q_HANDLED(); break; } /*.${AOs::Ship::SM::active::exploding::TIME_TICK} */ case TIME_TICK_SIG: { /*.${AOs::Ship::SM::active::exploding::TIME_TICK::[me->exp_ctr<15]} */ if (me->exp_ctr < 15) { ++me->exp_ctr; /* tell the Tunnel to draw the current stage of Explosion */ QACTIVE_POST(&AO_Tunnel, EXPLOSION_SIG, ((EXPLOSION0_BMP + (me->exp_ctr >> 2)) << 16) | me->x | ((((me->y >> 2) - 4U + SHIP_HEIGHT) & 0xFFU) << 8)); status_ = Q_HANDLED(); } /*.${AOs::Ship::SM::active::exploding::TIME_TICK::[else]} */ else { QACTIVE_POST(&AO_Tunnel, GAME_OVER_SIG, me->score); status_ = Q_TRAN(&Ship_parked); } break; } default: { status_ = Q_SUPER(&Ship_active); break; } } return status_; } /*.$enddef${AOs::Ship} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/