PlayChange.cpp
上传用户:jalin138
上传日期:2022-02-12
资源大小:5720k
文件大小:3k
源码类别:

游戏引擎

开发平台:

Visual C++

  1. #include "PlayChange.h"
  2. #include "PlayCommand.h"
  3. #include "PlayCheckDel.h"
  4. CPlayChange::CPlayChange(CSprite* _Vector[], 
  5.  ST_GAME_PLAY *_play, 
  6.  EN_PLAY _State)
  7. {
  8. m_pPlay = _play;
  9. int i = 0;
  10. while ( i < m_pPlay->size*m_pPlay->size )
  11. {
  12. m_vSprite[i] = _Vector[i];
  13. i ++;
  14. }
  15. // 判断交换路径
  16. if (m_pPlay->nChoice1 == m_pPlay->nChoice2 + 1)
  17. m_enWay = WAY_LEFT;
  18. else if (m_pPlay->nChoice1 == m_pPlay->nChoice2 - 1)
  19. m_enWay = WAY_RIGHT;
  20. else if (m_pPlay->nChoice1 == m_pPlay->nChoice2 - m_pPlay->size)
  21. m_enWay = WAY_DOWN; 
  22. else
  23. m_enWay = WAY_UP;
  24. en_State = _State;
  25. }
  26. CPlayChange::~CPlayChange(void)
  27. {
  28. m_pPlay = NULL;
  29. memset(m_vSprite,NULL,sizeof(m_vSprite));
  30. }
  31. // 状态逻辑接口
  32. bool CPlayChange::Logic(void)
  33. {
  34. float mt_speed = 24.0f/m_pPlay->size;
  35. static float mt_way = 0;
  36. mt_way += mt_speed;
  37. switch ( m_enWay )
  38. {
  39. case WAY_UP:
  40. m_vSprite[m_pPlay->nChoice1]->m_fy -= mt_speed;
  41. m_vSprite[m_pPlay->nChoice2]->m_fy += mt_speed;
  42. break;
  43. case WAY_DOWN:
  44. m_vSprite[m_pPlay->nChoice1]->m_fy += mt_speed;
  45. m_vSprite[m_pPlay->nChoice2]->m_fy -= mt_speed;
  46. break;
  47. case WAY_LEFT:
  48. m_vSprite[m_pPlay->nChoice1]->m_fx -= mt_speed;
  49. m_vSprite[m_pPlay->nChoice2]->m_fx += mt_speed;
  50. break;
  51. case WAY_RIGHT:
  52. m_vSprite[m_pPlay->nChoice1]->m_fx += mt_speed;
  53. m_vSprite[m_pPlay->nChoice2]->m_fx -= mt_speed;
  54. break;
  55. default:
  56. break;
  57. }
  58. if ( mt_way >= m_pPlay->width )
  59. {
  60. mt_way = 0;
  61. // 复位
  62. int temp = 0;
  63. temp = m_vSprite[m_pPlay->nChoice1]->m_nType;
  64. m_vSprite[m_pPlay->nChoice1]->m_nType = m_vSprite[m_pPlay->nChoice2]->m_nType;
  65. m_vSprite[m_pPlay->nChoice2]->m_nType = temp;
  66. hgeSprite *spr = NULL;
  67. spr = m_vSprite[m_pPlay->nChoice1]->m_pSpr;
  68. m_vSprite[m_pPlay->nChoice1]->m_pSpr = m_vSprite[m_pPlay->nChoice2]->m_pSpr;
  69. m_vSprite[m_pPlay->nChoice2]->m_pSpr = spr;
  70. m_vSprite[m_pPlay->nChoice1]->m_fx = (m_pPlay->nChoice1%m_pPlay->size) * m_pPlay->width 
  71. + 170.0f + m_pPlay->width/2.0f;
  72. m_vSprite[m_pPlay->nChoice1]->m_fy = (m_pPlay->nChoice1/m_pPlay->size) * m_pPlay->width 
  73. + 100.0f + m_pPlay->width/2.0f;
  74. m_vSprite[m_pPlay->nChoice2]->m_fx = (m_pPlay->nChoice2%m_pPlay->size) * m_pPlay->width 
  75. + 170.0f + m_pPlay->width/2.0f;
  76. m_vSprite[m_pPlay->nChoice2]->m_fy = (m_pPlay->nChoice2/m_pPlay->size) * m_pPlay->width 
  77. + 100.0f + m_pPlay->width/2.0f;
  78. return true;
  79. }
  80. return false;
  81. }
  82. // 状态渲染接口
  83. void CPlayChange::Render(void)
  84. {
  85. #ifdef _DEBUG
  86. g_Font->Print( 10,50, "GAME_PLAY : CHANGE");
  87. #endif
  88. }
  89. // 传入场景管理对象,以改变状态
  90. bool CPlayChange::Handle(CSceneManage *_Manage)
  91. {
  92. if (NULL == _Manage )
  93. return false;
  94. if ( en_State == PLAY_COMMEND )
  95. _Manage->ChangeState( new CPlayCheckDel(m_vSprite,m_pPlay) );
  96. if ( en_State == PLAY_CHACK_DEL )
  97. _Manage->ChangeState( new CPlayCommand(m_vSprite,m_pPlay) );
  98. return false;
  99. }