- #include "PlayChange.h"
- #include "PlayCommand.h"
- #include "PlayCheckDel.h"
- CPlayChange::CPlayChange(CSprite* _Vector[],
- ST_GAME_PLAY *_play,
- EN_PLAY _State)
- {
- m_pPlay = _play;
- int i = 0;
- while ( i < m_pPlay->size*m_pPlay->size )
- {
- m_vSprite[i] = _Vector[i];
- i ++;
- }
- // 判断交换路径
- if (m_pPlay->nChoice1 == m_pPlay->nChoice2 + 1)
- m_enWay = WAY_LEFT;
- else if (m_pPlay->nChoice1 == m_pPlay->nChoice2 - 1)
- m_enWay = WAY_RIGHT;
- else if (m_pPlay->nChoice1 == m_pPlay->nChoice2 - m_pPlay->size)
- m_enWay = WAY_DOWN;
- else
- m_enWay = WAY_UP;
- en_State = _State;
- }
- CPlayChange::~CPlayChange(void)
- {
- m_pPlay = NULL;
- memset(m_vSprite,NULL,sizeof(m_vSprite));
- }
- // 状态逻辑接口
- bool CPlayChange::Logic(void)
- {
- float mt_speed = 24.0f/m_pPlay->size;
- static float mt_way = 0;
- mt_way += mt_speed;
- switch ( m_enWay )
- {
- case WAY_UP:
- m_vSprite[m_pPlay->nChoice1]->m_fy -= mt_speed;
- m_vSprite[m_pPlay->nChoice2]->m_fy += mt_speed;
- break;
- case WAY_DOWN:
- m_vSprite[m_pPlay->nChoice1]->m_fy += mt_speed;
- m_vSprite[m_pPlay->nChoice2]->m_fy -= mt_speed;
- break;
- case WAY_LEFT:
- m_vSprite[m_pPlay->nChoice1]->m_fx -= mt_speed;
- m_vSprite[m_pPlay->nChoice2]->m_fx += mt_speed;
- break;
- case WAY_RIGHT:
- m_vSprite[m_pPlay->nChoice1]->m_fx += mt_speed;
- m_vSprite[m_pPlay->nChoice2]->m_fx -= mt_speed;
- break;
- default:
- break;
- }
- if ( mt_way >= m_pPlay->width )
- {
- mt_way = 0;
- // 复位
- int temp = 0;
- temp = m_vSprite[m_pPlay->nChoice1]->m_nType;
- m_vSprite[m_pPlay->nChoice1]->m_nType = m_vSprite[m_pPlay->nChoice2]->m_nType;
- m_vSprite[m_pPlay->nChoice2]->m_nType = temp;
- hgeSprite *spr = NULL;
- spr = m_vSprite[m_pPlay->nChoice1]->m_pSpr;
- m_vSprite[m_pPlay->nChoice1]->m_pSpr = m_vSprite[m_pPlay->nChoice2]->m_pSpr;
- m_vSprite[m_pPlay->nChoice2]->m_pSpr = spr;
- m_vSprite[m_pPlay->nChoice1]->m_fx = (m_pPlay->nChoice1%m_pPlay->size) * m_pPlay->width
- + 170.0f + m_pPlay->width/2.0f;
- m_vSprite[m_pPlay->nChoice1]->m_fy = (m_pPlay->nChoice1/m_pPlay->size) * m_pPlay->width
- + 100.0f + m_pPlay->width/2.0f;
- m_vSprite[m_pPlay->nChoice2]->m_fx = (m_pPlay->nChoice2%m_pPlay->size) * m_pPlay->width
- + 170.0f + m_pPlay->width/2.0f;
- m_vSprite[m_pPlay->nChoice2]->m_fy = (m_pPlay->nChoice2/m_pPlay->size) * m_pPlay->width
- + 100.0f + m_pPlay->width/2.0f;
- return true;
- }
- return false;
- }
- // 状态渲染接口
- void CPlayChange::Render(void)
- {
- #ifdef _DEBUG
- g_Font->Print( 10,50, "GAME_PLAY : CHANGE");
- #endif
- }
- // 传入场景管理对象,以改变状态
- bool CPlayChange::Handle(CSceneManage *_Manage)
- {
- if (NULL == _Manage )
- return false;
- if ( en_State == PLAY_COMMEND )
- _Manage->ChangeState( new CPlayCheckDel(m_vSprite,m_pPlay) );
- if ( en_State == PLAY_CHACK_DEL )
- _Manage->ChangeState( new CPlayCommand(m_vSprite,m_pPlay) );
- return false;
- }