demo13.cpp 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. #define ZGL_IMPORT
  2. #include <memory.h>
  3. #include <math.h>
  4. #include "zglHeader.h"
  5. zglPFont fntMain;
  6. zglPTexture texBack;
  7. bool debug;
  8. zglTPEngine2D particles;
  9. zglPEmitter2D emitterFire[3];
  10. zglPEmitter2D emitterDiamond;
  11. zglPEmitter2D emitterRain;
  12. char resource[256];
  13. char* GetResource( char* FileName )
  14. {
  15. sprintf_s( resource, "../data/%s", FileName );
  16. return resource;
  17. }
  18. void Init()
  19. {
  20. texBack = tex_LoadFromFile( GetResource( "back02.png" ) );
  21. fntMain = font_LoadFromFile( GetResource( "font.zfi" ) );
  22. // EN: Load three types of fire emitters.
  23. // RU: Загрузка трёх разных видов эмиттеров огня.
  24. emitterFire[ 0 ] = emitter2d_LoadFromFile( GetResource( "emitter_fire00.zei" ) );
  25. emitterFire[ 1 ] = emitter2d_LoadFromFile( GetResource( "emitter_fire01.zei" ) );
  26. emitterFire[ 2 ] = emitter2d_LoadFromFile( GetResource( "emitter_fire02.zei" ) );
  27. // EN: Set own particels engine.
  28. // RU: Установка собственного движка эмиттеров.
  29. pengine2d_Set( &particles );
  30. // EN: Add 6 fire emitters to particles engine. Second parameter of function returns pointer to instance of new emitter, which can be processed manually.
  31. // This instance will be NULL after the death, so check everything.
  32. // RU: Добавляем в движок 6 эмиттеров огня. Второй параметр функции позволяет получить указатель на конкретный экземпляр эмиттера, который можно будет обрабатывать вручную.
  33. // Данный экземпляр после смерти будет содержать NULL, поэтому используйте проверку.
  34. pengine2d_AddEmitter( emitterFire[ 0 ], NULL, 642, 190 );
  35. pengine2d_AddEmitter( emitterFire[ 0 ], NULL, 40, 368 );
  36. pengine2d_AddEmitter( emitterFire[ 0 ], NULL, 246, 368 );
  37. pengine2d_AddEmitter( emitterFire[ 1 ], NULL, 532, 244 );
  38. pengine2d_AddEmitter( emitterFire[ 1 ], NULL, 318, 422 );
  39. pengine2d_AddEmitter( emitterFire[ 1 ], NULL, 583, 420 );
  40. pengine2d_AddEmitter( emitterFire[ 2 ], NULL, 740, 525 );
  41. emitterDiamond = emitter2d_LoadFromFile( GetResource( "emitter_diamond.zei" ) );
  42. pengine2d_AddEmitter( emitterDiamond, NULL );
  43. emitterRain = emitter2d_LoadFromFile( GetResource( "emitter_rain.zei" ) );
  44. pengine2d_AddEmitter( emitterRain, NULL );
  45. }
  46. void Draw()
  47. {
  48. batch2d_Begin();
  49. ssprite2d_Draw( texBack, 0, 0, 800, 600, 0 );
  50. // EN: Rendering of all emitters in current particles engine.
  51. // RU: Рендеринг всех эмиттеров в текущем движке частиц.
  52. pengine2d_Draw();
  53. if ( debug )
  54. for ( int i = 0; i < particles.Count.Emitters; i++ )
  55. pr2d_Rect( particles.List[ i ]->BBox.MinX, particles.List[ i ]->BBox.MinY,
  56. particles.List[ i ]->BBox.MaxX - particles.List[ i ]->BBox.MinX,
  57. particles.List[ i ]->BBox.MaxY - particles.List[ i ]->BBox.MinY, 0xFF0000, 255 );
  58. char text[64];
  59. sprintf_s( text, "FPS: %i", zgl_Get( RENDER_FPS ) );
  60. text_Draw( fntMain, 0, 0, text );
  61. sprintf_s( text, "Particles: %i", particles.Count.Particles );
  62. text_Draw( fntMain, 0, 20, text );
  63. sprintf_s( text, "Debug(F1): %s", debug ? "TRUE" : "FALSE" );
  64. text_Draw( fntMain, 0, 40, text );
  65. batch2d_End();
  66. }
  67. void Timer()
  68. {
  69. if ( key_Press( K_ESCAPE ) ) zgl_Exit();
  70. if ( key_Press( K_F1 ) ) debug = !debug;
  71. key_ClearState();
  72. }
  73. void Update( double dt )
  74. {
  75. // EN: Process all emitters in current particles engine.
  76. // RU: Обработка всех эмиттеров в текущем движке частиц.
  77. pengine2d_Proc( dt );
  78. }
  79. void Quit()
  80. {
  81. // RU: Очищаем память от созданных эмиттеров.
  82. // EN: Free allocated memory for emitters.
  83. pengine2d_Set( &particles );
  84. pengine2d_ClearAll();
  85. }
  86. int CALLBACK WinMain (
  87. __in HINSTANCE hInstance,
  88. __in_opt HINSTANCE hPrevInstance,
  89. __in_opt LPSTR lpCmdLine,
  90. __in int nShowCmd
  91. )
  92. {
  93. if ( !zglLoad( libZenGL ) ) return 0;
  94. timer_Add( (void*)&Timer, 16 );
  95. zgl_Reg( SYS_LOAD, (void*)&Init );
  96. zgl_Reg( SYS_DRAW, (void*)&Draw );
  97. zgl_Reg( SYS_UPDATE, (void*)&Update );
  98. zgl_Reg( SYS_EXIT, (void*)&Quit );
  99. wnd_SetCaption( "13 - Particles" );
  100. wnd_ShowCursor( TRUE );
  101. scr_SetOptions( 800, 600, REFRESH_MAXIMUM, FALSE, FALSE );
  102. zgl_Init();
  103. zglFree();
  104. return 0;
  105. }