demo13.pas 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. program demo13;
  2. {$I zglCustomConfig.cfg}
  3. uses
  4. zgl_screen,
  5. zgl_window,
  6. zgl_timers,
  7. zgl_keyboard,
  8. zgl_render_2d,
  9. zgl_fx,
  10. zgl_textures,
  11. zgl_textures_png,
  12. zgl_textures_jpg,
  13. zgl_sprite_2d,
  14. zgl_particles_2d,
  15. zgl_primitives_2d,
  16. zgl_font,
  17. zgl_text,
  18. zgl_math_2d,
  19. zgl_utils
  20. ;
  21. var
  22. dirRes : UTF8String {$IFNDEF MACOSX} = '../data/' {$ENDIF};
  23. fntMain : Byte;
  24. texBack : zglPTexture;
  25. debug : Boolean;
  26. particles : zglTPEngine2D;
  27. emitterFire : array[0..2] of zglPEmitter2D;
  28. emitterDiamond: zglPEmitter2D;
  29. emitterRain : zglPEmitter2D;
  30. TimeStart : Byte;
  31. procedure Init;
  32. begin
  33. texBack := tex_LoadFromFile(dirRes + 'back02.png');
  34. fntMain := font_LoadFromFile(dirRes + 'font.zfi');
  35. // EN: Load three types of fire emitters.
  36. // RU: Çàãðóçêà òð¸õ ðàçíûõ âèäîâ ýìèòòåðîâ îãíÿ.
  37. emitterFire[0] := emitter2d_LoadFromFile(dirRes + 'emitter_fire00.zei');
  38. emitterFire[1] := emitter2d_LoadFromFile(dirRes + 'emitter_fire01.zei');
  39. emitterFire[2] := emitter2d_LoadFromFile(dirRes + 'emitter_fire02.zei');
  40. // EN: Set own particels engine.
  41. // RU: Óñòàíîâêà ñîáñòâåííîãî äâèæêà ýìèòòåðîâ.
  42. pengine2d_Set(@particles);
  43. // EN: Add 6 fire emitters to particles engine. Second parameter of function returns pointer to instance of new emitter, which can be processed manually.
  44. // This instance will be nil after the death, so check everything.
  45. // RU: Äîáàâëÿåì â äâèæîê 6 ýìèòòåðîâ îãíÿ. Âòîðîé ïàðàìåòð ôóíêöèè ïîçâîëÿåò ïîëó÷èòü óêàçàòåëü íà êîíêðåòíûé ýêçåìïëÿð ýìèòòåðà, êîòîðûé ìîæíî áóäåò îáðàáàòûâàòü âðó÷íóþ.
  46. // Äàííûé ýêçåìïëÿð ïîñëå ñìåðòè áóäåò ñîäåðæàòü nil, ïîýòîìó èñïîëüçóéòå ïðîâåðêó.
  47. pengine2d_AddEmitter(emitterFire[0], nil, 642, 190);
  48. pengine2d_AddEmitter(emitterFire[0], nil, 40, 368);
  49. pengine2d_AddEmitter(emitterFire[0], nil, 246, 368);
  50. pengine2d_AddEmitter(emitterFire[1], nil, 532, 244);
  51. pengine2d_AddEmitter(emitterFire[1], nil, 318, 422);
  52. pengine2d_AddEmitter(emitterFire[1], nil, 583, 420);
  53. pengine2d_AddEmitter(emitterFire[2], nil, 740, 525);
  54. emitterDiamond := emitter2d_LoadFromFile(dirRes + 'emitter_diamond.zei');
  55. pengine2d_AddEmitter(emitterDiamond, nil);
  56. emitterRain := emitter2d_LoadFromFile(dirRes + 'emitter_rain.zei');
  57. pengine2d_AddEmitter(emitterRain, nil);
  58. setTextScale(15, fntMain);
  59. end;
  60. procedure Draw;
  61. var
  62. i: Integer;
  63. begin
  64. batch2d_Begin();
  65. ssprite2d_Draw(texBack, 0, 0, 800, 600, 0);
  66. // EN: Rendering of all emitters in current particles engine.
  67. // RU: Ðåíäåðèíã âñåõ ýìèòòåðîâ â òåêóùåì äâèæêå ÷àñòèö.
  68. pengine2d_Draw();
  69. if debug Then
  70. for i := 0 to particles.Count.Emitters - 1 do
  71. with particles.List[i].BBox do
  72. pr2d_Rect(MinX, MinY, MaxX - MinX, MaxY - MinY, $FF0000, 255);
  73. text_Draw(fntMain, 0, 0, 'FPS: ' + u_IntToStr(zgl_Get(RENDER_FPS)));
  74. text_Draw(fntMain, 0, 20, 'Particles: ' + u_IntToStr(particles.Count.Particles));
  75. text_Draw(fntMain, 0, 40, 'Debug(F1): ' + u_BoolToStr(debug));
  76. batch2d_End();
  77. end;
  78. procedure Timer;
  79. begin
  80. if key_Press(K_F1) Then debug := not debug;
  81. key_ClearState();
  82. end;
  83. procedure Update(dt: Double);
  84. begin
  85. // EN: Process all emitters in current particles engine.
  86. // RU: Îáðàáîòêà âñåõ ýìèòòåðîâ â òåêóùåì äâèæêå ÷àñòèö.
  87. pengine2d_Proc(dt);
  88. end;
  89. procedure Quit;
  90. begin
  91. // RU: Î÷èùàåì ïàìÿòü îò ñîçäàííûõ ýìèòòåðîâ.
  92. // EN: Free allocated memory for emitters.
  93. pengine2d_Set(@particles);
  94. pengine2d_ClearAll();
  95. end;
  96. Begin
  97. randomize();
  98. TimeStart := timer_Add(@Timer, 16, Start);
  99. zgl_Reg(SYS_LOAD, @Init);
  100. zgl_Reg(SYS_DRAW, @Draw);
  101. zgl_Reg(SYS_UPDATE, @Update);
  102. zgl_Reg(SYS_EXIT, @Quit);
  103. wnd_SetCaption(utf8_Copy('13 - Particles'));
  104. zgl_Init();
  105. End.