2012-08-14 18:07:04 -04:00
|
|
|
/*****************************************************************************
|
|
|
|
* Model: game.qm
|
2012-12-10 16:00:27 -05:00
|
|
|
* File: ./missile.c
|
2012-08-14 18:07:04 -04:00
|
|
|
*
|
2013-09-23 14:34:35 -04:00
|
|
|
* This code has been generated by QM tool (see state-machine.com/qm).
|
|
|
|
* DO NOT EDIT THIS FILE MANUALLY. All your changes will be lost.
|
2012-08-14 18:07:04 -04:00
|
|
|
*
|
2013-09-23 14:34:35 -04:00
|
|
|
* 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.
|
2012-08-14 18:07:04 -04:00
|
|
|
*****************************************************************************/
|
2013-09-23 14:34:35 -04:00
|
|
|
/* @(/3/1) .................................................................*/
|
2012-08-14 18:07:04 -04:00
|
|
|
#include "qp_port.h"
|
|
|
|
#include "bsp.h"
|
|
|
|
#include "game.h"
|
|
|
|
|
|
|
|
/* Q_DEFINE_THIS_FILE */
|
|
|
|
|
|
|
|
/* local objects -----------------------------------------------------------*/
|
|
|
|
/* @(/2/2) .................................................................*/
|
|
|
|
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) {
|
2013-09-23 14:34:35 -04:00
|
|
|
QState status_;
|
2012-08-14 18:07:04 -04:00
|
|
|
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;
|
2013-09-23 14:34:35 -04:00
|
|
|
status_ = Q_TRAN(&Missile_flying);
|
2012-08-14 18:07:04 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
default: {
|
2013-09-23 14:34:35 -04:00
|
|
|
status_ = Q_SUPER(&QHsm_top);
|
2012-08-14 18:07:04 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2013-09-23 14:34:35 -04:00
|
|
|
return status_;
|
2012-08-14 18:07:04 -04:00
|
|
|
}
|
|
|
|
/* @(/2/2/3/2) .............................................................*/
|
|
|
|
static QState Missile_flying(Missile * const me, QEvt const * const e) {
|
2013-09-23 14:34:35 -04:00
|
|
|
QState status_;
|
2012-08-14 18:07:04 -04:00
|
|
|
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);
|
2013-09-23 14:34:35 -04:00
|
|
|
status_ = Q_HANDLED();
|
2012-08-14 18:07:04 -04:00
|
|
|
}
|
|
|
|
/* @(/2/2/3/2/0/1) */
|
|
|
|
else {
|
2013-09-23 14:34:35 -04:00
|
|
|
status_ = Q_TRAN(&Missile_armed);
|
2012-08-14 18:07:04 -04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* @(/2/2/3/2/1) */
|
|
|
|
case HIT_WALL_SIG: {
|
2013-09-23 14:34:35 -04:00
|
|
|
status_ = Q_TRAN(&Missile_exploding);
|
2012-08-14 18:07:04 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* @(/2/2/3/2/2) */
|
|
|
|
case DESTROYED_MINE_SIG: {
|
|
|
|
QACTIVE_POST(AO_Ship, e, me);
|
2013-09-23 14:34:35 -04:00
|
|
|
status_ = Q_TRAN(&Missile_armed);
|
2012-08-14 18:07:04 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
default: {
|
2013-09-23 14:34:35 -04:00
|
|
|
status_ = Q_SUPER(&QHsm_top);
|
2012-08-14 18:07:04 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2013-09-23 14:34:35 -04:00
|
|
|
return status_;
|
2012-08-14 18:07:04 -04:00
|
|
|
}
|
|
|
|
/* @(/2/2/3/3) .............................................................*/
|
|
|
|
static QState Missile_exploding(Missile * const me, QEvt const * const e) {
|
2013-09-23 14:34:35 -04:00
|
|
|
QState status_;
|
2012-08-14 18:07:04 -04:00
|
|
|
switch (e->sig) {
|
|
|
|
/* @(/2/2/3/3) */
|
|
|
|
case Q_ENTRY_SIG: {
|
|
|
|
me->exp_ctr = 0U;
|
2013-09-23 14:34:35 -04:00
|
|
|
status_ = Q_HANDLED();
|
2012-08-14 18:07:04 -04:00
|
|
|
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);
|
2013-09-23 14:34:35 -04:00
|
|
|
status_ = Q_HANDLED();
|
2012-08-14 18:07:04 -04:00
|
|
|
}
|
|
|
|
/* @(/2/2/3/3/0/1) */
|
|
|
|
else {
|
2013-09-23 14:34:35 -04:00
|
|
|
status_ = Q_TRAN(&Missile_armed);
|
2012-08-14 18:07:04 -04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default: {
|
2013-09-23 14:34:35 -04:00
|
|
|
status_ = Q_SUPER(&QHsm_top);
|
2012-08-14 18:07:04 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2013-09-23 14:34:35 -04:00
|
|
|
return status_;
|
2012-08-14 18:07:04 -04:00
|
|
|
}
|
|
|
|
|