PlayCommand.cpp
上传用户:jalin138
上传日期:2022-02-12
资源大小:5720k
文件大小:3k
- #include "PlayCommand.h"
- #include "PlayChange.h"
- CPlayCommand::CPlayCommand(CSprite* _Vector[],
- ST_GAME_PLAY *_play)
- {
- m_bChoice = false;
- m_pChoice = g_Res->GetSprite( "Choice" );
- m_pPlay = _play;
- int i = 0;
- while ( i < m_pPlay->size*m_pPlay->size )
- {
- m_vSprite[i] = _Vector[i];
- i ++;
- }
- m_pPlay->nChoice1 = 0;
- m_pPlay->nChoice2 = 0;
- }
- CPlayCommand::~CPlayCommand(void)
- {
- m_pChoice = NULL;
- m_pPlay = NULL;
- memset(m_vSprite,NULL,sizeof(m_vSprite));
- }
- // 状态逻辑接口
- bool CPlayCommand::Logic(void)
- {
- float g_fBegX = 170.0f;
- float g_fBegY = 100.0f;
- float mouseX = 0, mouseY = 0;
- if ( g_Hge->Input_KeyDown(HGEK_LBUTTON) )
- {
- g_Hge->Input_GetMousePos(&mouseX, &mouseY);
- for (int i = 0;i < m_pPlay->size*m_pPlay->size; i ++)
- {
- int mt_c = i%m_pPlay->size, mt_l = i/m_pPlay->size;
- if ( mouseX > g_fBegX + m_pPlay->width*mt_c
- && mouseX < g_fBegX + m_pPlay->width*(mt_c+1)
- && mouseY > g_fBegY + m_pPlay->width*mt_l
- && mouseY < g_fBegY + m_pPlay->width*(mt_l+1) )
- {
- return CheckChoice( i );
- }
- }
- }
- if ( m_bChoice )
- {
- Move();
- }
- return false;
- }
- //检测选择
- bool CPlayCommand::CheckChoice(int _n)
- {
- if ( m_bChoice)
- {
- if ( m_pPlay->nChoice1 - 1 == _n
- || m_pPlay->nChoice1 + 1 == _n
- || m_pPlay->nChoice1 - m_pPlay->size == _n
- || m_pPlay->nChoice1 + m_pPlay->size == _n )
- {
- m_pPlay->nChoice2 = _n;
- m_bChoice = false;
- return true;
- }
- // 复位
- 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_pPlay->nChoice1 = _n;
- m_bChoice = true;
- return false;
- }
- m_pPlay->nChoice1 = _n;
- m_bChoice = true;
- return false;
- }
- // 选择动态
- void CPlayCommand::Move(void)
- {
- static int i = 0;
- static float mt_y = 0.0f;
- mt_y += 4.0f/m_pPlay->size;
- if ( mt_y > m_pPlay->size / 1.6f )
- {
- mt_y = 0.0f;
- i == 0 ? i = 1 : i = 0;
- }
- if ( i == 0 )
- m_vSprite[m_pPlay->nChoice1]->m_fy += 4.0f/m_pPlay->size;
- else
- m_vSprite[m_pPlay->nChoice1]->m_fy -= 4.0f/m_pPlay->size;
- }
- // 状态渲染接口
- void CPlayCommand::Render(void)
- {
- #ifdef _DEBUG
- g_Font->Print( 10,30, "Play Command" );
- #endif
- if ( m_bChoice )
- {
- float m_fsize = m_pPlay->width/73.0f;
- float mf_x = (m_pPlay->nChoice1%m_pPlay->size)*m_pPlay->width
- + m_pPlay->width / 2.0f + 170.0f;
- float mf_y = (m_pPlay->nChoice1/m_pPlay->size)*m_pPlay->width
- + m_pPlay->width / 2.0f + 100.0f;
- m_pChoice->RenderEx(mf_x,mf_y,0.0f,m_fsize,m_fsize );
- }
- }
- // 传入场景管理对象,以改变状态
- bool CPlayCommand::Handle(CSceneManage *_Manage)
- {
- if ( NULL == _Manage )
- return false;
- _Manage->ChangeState( new CPlayChange(m_vSprite,m_pPlay,PLAY_COMMEND) );
- return false;
- }