TileInterfaces.cpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #include "TileInterfaces.h"
  2. #include "ParticleEngine.h"
  3. ITileGame::ITileGame( ITileRenderer *renderer, int x, int y, int width, int height ) {
  4. m_renderer = renderer;
  5. m_pengine = new CParticleEngine( renderer );
  6. m_logoState = 0;
  7. m_hudState = 0;
  8. m_state = eTILEGAMESTATE_NOTSET;
  9. setGameArea( x,y,width,height );
  10. };
  11. ITileGame::~ITileGame() {
  12. if (m_pengine) {
  13. delete m_pengine;
  14. };
  15. // destroy something?
  16. };
  17. void ITileGame::click( int fixedx, int fixedy, eMOUSEEVENT etype ) {
  18. // TODO, transfer basic functionality here.
  19. gameClick( fixedx, fixedy, etype );
  20. };
  21. void ITileGame::setGameState( eTILEGAMESTATE state ) {
  22. switch ( state ) {
  23. case eTILEGAMESTATE_MENU:
  24. m_renderer->effectNotify( eEFFECT_MENU, 0, 0);
  25. break;
  26. case eTILEGAMESTATE_GAMEOVER:
  27. m_renderer->effectNotify( eEFFECT_GAMEOVER, 0, 0);
  28. break;
  29. }
  30. m_state = state;
  31. gameStateChanged(); // notify
  32. };
  33. int ITileGame::run( int fixedFrameTime16Bit ) {
  34. //fixedFrameTime16Bit /= 8;
  35. int hudStateTarget = 0;
  36. int logoStateTarget = 0;
  37. switch ( m_state ) {
  38. case eTILEGAMESTATE_NOTSET:
  39. if (load() == 1) {
  40. setGameState( eTILEGAMESTATE_PAUSED );
  41. } else setGameState( eTILEGAMESTATE_MENU );
  42. break;
  43. case eTILEGAMESTATE_MENU:
  44. logoStateTarget = 65535;
  45. break;
  46. case eTILEGAMESTATE_RUNGAME:
  47. {
  48. hudStateTarget = 65535;
  49. };
  50. break;
  51. };
  52. m_logoState += (((logoStateTarget-m_logoState) * fixedFrameTime16Bit) >> 13);
  53. m_hudState += (((hudStateTarget-m_hudState) * fixedFrameTime16Bit) >> 14);
  54. int grun = gameRun( fixedFrameTime16Bit );
  55. m_pengine->run( fixedFrameTime16Bit);
  56. return 1;
  57. };
  58. int ITileGame::draw() {
  59. m_renderer->renderBackground(0); // game will render bg
  60. int rval = gameDraw();
  61. //m_pengine->draw();
  62. m_renderer->renderForeground(0);
  63. return rval;
  64. };
  65. // helpers