PongApp.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. /*
  2. * Copyright (c) 2011 Nokia Corporation.
  3. */
  4. #ifndef __PONG_GAMEAPP__
  5. #define __PONG_GAMEAPP__
  6. #include "FontWriter.h"
  7. #include "ParticleEngine.h"
  8. #include "GameApp.h"
  9. #include "PongGame.h"
  10. #include "PongBackground.h"
  11. #include "PongHighScores.h"
  12. #include "PongCredits.h"
  13. #include "GameMenu.h"
  14. #include "AudioInterfaces.h"
  15. #include "AudioBuffer.h"
  16. #include "MusicPlayer.h"
  17. #include "../spritebatchqt/src_general/SpriteBatch.h"
  18. #ifdef IAP
  19. #include "../epong_iap_impl/miniiapinterface.h"
  20. #include "../epong_iap_impl/miniiapclientapi.h"
  21. #include "../epong_iap_impl/epong_iap_constants.h"
  22. #endif
  23. #define MENU_ITEM_HEIGHT 0.15f
  24. #define MAX_PARTICLES 2000 // maximum amount of simultaneous particles alive.
  25. #define AUDIO_EFFECT_CHANNELS 4 // How many audio channels are used.
  26. class PongApp : public GF::GameApp
  27. #ifdef IAP
  28. , public MiniIAPInterface
  29. #endif
  30. {
  31. public:
  32. PongApp( GF::GameEngine *engine );
  33. ~PongApp();
  34. void update( float frameTime );
  35. void render();
  36. bool prepare();
  37. void release();
  38. void resize( int w, int h );
  39. virtual void readAudioStream( AUDIO_SAMPLE_TYPE *target, int sampleCount );
  40. void mouseEvent( GF::MOUSE_EVENT_TYPE type, int x, int y, int button );
  41. void keyEvent( GF::KEY_EVENT_TYPE type, int code );
  42. void sensorEvent(GF::SENSOR_EVENT_TYPE type, int x, int y, int z);
  43. float getTop() { return (float)currentHeight/(float)currentWidth; }
  44. ParticleEngine *getParticleEngine() { return pengine; }
  45. GF::GameEngine *getEngine() { return engine; }
  46. ParticleType *getBallFlyParticleType() { return ballFlyParticleType; }
  47. ParticleType *getBallHitParticleType() { return ballHitParticleType; }
  48. FontWriter *getFontWriter() { return fontWriter; }
  49. PongGame *getGame() { return currentGame; }
  50. void notifyEvent( GF::NOTIFY_EVENT_TYPE type, int flags );
  51. // textures
  52. int getPlayerPadTexture() { return playerPadTexture; }
  53. int getComputerPadTexture() { return computerPadTexture; }
  54. int getBallTexture() { return ballTexture; }
  55. SpriteBatch *getSpriteBatch() { return spriteBatch; }
  56. // Audio buffers
  57. GF::AudioBuffer *sampleBallPong;
  58. GF::AudioBuffer *sampleMenuTick;
  59. GF::AudioBuffer *sampleGameOver;
  60. GF::AudioBuffer *sampleLevelCompleted;
  61. #ifdef EPONG_DEBUG
  62. GF::AudioBuffer *sampleLatencyTest;
  63. #endif
  64. // Selects a free channels and starts playing buffer with it
  65. void playSoundEffect( GF::AudioBuffer *buffer, float volume, float leftright = 0.0f);
  66. #ifdef IAP
  67. virtual void purchaseCompleted(const char *productId, const char *status);
  68. virtual void purchaseFlowFinished(const char *productId);
  69. #endif
  70. protected:
  71. SpriteBatch *spriteBatch;
  72. float sensorGravity[3];
  73. // Raw/encoded music loaded into the memory for playback.
  74. void *musicBinaryResource;
  75. int musicBinaryResourceLength;
  76. GameMenu* createMainMenu();
  77. GameMenu* createPauseMenu();
  78. GameMenu* createExitQuery();
  79. #ifdef IAP
  80. GameMenu* createWaitingIAPMenu();
  81. #endif
  82. static void menuItemRender( void *data, GameMenu *menu, MenuItem *ni );
  83. bool allowMainMenuCreation;
  84. int volumeIndicator; // 0 - mute, 4=
  85. PongHighScores *highScores;
  86. PongCredits *credits;
  87. PongBackground *background1;
  88. // Font
  89. FontWriter *fontWriter;
  90. GameMenu *currentMenu;
  91. // Particles
  92. ParticleEngine *pengine;
  93. ParticleType *ballFlyParticleType;
  94. ParticleType *ballHitParticleType;
  95. float pointerX[2];
  96. float pointerY[2];
  97. bool buttonDown[2];
  98. int currentWidth;
  99. int currentHeight;
  100. void restartGame(bool singlePlayer);
  101. PongGame *currentGame;
  102. int fontTexture;
  103. // Textures
  104. int computerPadTexture;
  105. int playerPadTexture;
  106. int ballTexture;
  107. int ballShineTexture;
  108. int volumeTexture; //all control buttons,
  109. int topBarTexture;
  110. #ifdef MY_OS_MEEGO
  111. int meegoSwipeTexture;
  112. #endif
  113. // Our projectionmatrix set at resize
  114. float matrixProjection[16];
  115. // Audio effect playing
  116. GF::AudioMixer *amixer;
  117. // Mixer channels for audio-effects
  118. GF::AudioBufferPlayInstance **aeffectChannels;
  119. #ifdef IAP
  120. int m_multiplayerPurchased; // 0 == not started, 1 == phase 1 in started (preparing IAP client), 2 == started purchasing, 3 == purchase OK, 4 == purchase failed.
  121. #endif
  122. GF::AudioBuffer *loadWavFromResource( const char *name );
  123. };
  124. #endif