hgeparticle.h
上传用户:maxiaolivb
上传日期:2022-06-07
资源大小:915k
文件大小:4k
源码类别:

游戏引擎

开发平台:

Visual C++

  1. /*
  2. ** Haaf's Game Engine 1.5
  3. ** Copyright (C) 2003-2004, Relish Games
  4. ** hge.relishgames.com
  5. **
  6. ** hgeParticleSystem helper class header
  7. */
  8. #ifndef HGEPARTICLE_H
  9. #define HGEPARTICLE_H
  10. #include "hge.h"
  11. #include "hgesprite.h"
  12. #include "hgevector.h"
  13. #include "hgecolor.h"
  14. #include "hgerect.h"
  15. #define MAX_PARTICLES 500
  16. #define MAX_PSYSTEMS 100
  17. struct hgeParticle
  18. {
  19. hgeVector vecLocation;
  20. hgeVector vecVelocity;
  21. float fGravity;
  22. float fRadialAccel;
  23. float fTangentialAccel;
  24. float fSpin;
  25. float fSpinDelta;
  26. float fSize;
  27. float fSizeDelta;
  28. hgeColor colColor; // + alpha
  29. hgeColor colColorDelta;
  30. float fAge;
  31. float fTerminalAge;
  32. };
  33. struct hgeParticleSystemInfo
  34. {
  35. hgeSprite* sprite;    // texture + blend mode
  36. int nEmission; // particles per sec
  37. float fLifetime;
  38. float fParticleLifeMin;
  39. float fParticleLifeMax;
  40. float fDirection;
  41. float fSpread;
  42. bool bRelative;
  43. float fSpeedMin;
  44. float fSpeedMax;
  45. float fGravityMin;
  46. float fGravityMax;
  47. float fRadialAccelMin;
  48. float fRadialAccelMax;
  49. float fTangentialAccelMin;
  50. float fTangentialAccelMax;
  51. float fSizeStart;
  52. float fSizeEnd;
  53. float fSizeVar;
  54. float fSpinStart;
  55. float fSpinEnd;
  56. float fSpinVar;
  57. hgeColor colColorStart; // + alpha
  58. hgeColor colColorEnd;
  59. float fColorVar;
  60. float fAlphaVar;
  61. };
  62. class hgeParticleSystem
  63. {
  64. public:
  65. hgeParticleSystemInfo info;
  66. hgeParticleSystem(const char *filename, hgeSprite *sprite, float fps=0.0f);
  67. hgeParticleSystem(hgeParticleSystemInfo *psi, float fps=0.0f);
  68. hgeParticleSystem(const hgeParticleSystem &ps);
  69. ~hgeParticleSystem() { hge->Release(); }
  70. hgeParticleSystem& operator= (const hgeParticleSystem &ps);
  71. void Render();
  72. void FireAt(float x, float y);
  73. void Fire();
  74. void Stop(bool bKillParticles=false);
  75. void Update(float fDeltaTime);
  76. void MoveTo(float x, float y, bool bMoveParticles=false);
  77. void Transpose(float x, float y) { fTx=x; fTy=y; }
  78. void TrackBoundingBox(bool bTrack) { bUpdateBoundingBox=bTrack; }
  79. int GetParticlesAlive() const { return nParticlesAlive; }
  80. float GetAge() const { return fAge; }
  81. void GetPosition(float *x, float *y) const { *x=vecLocation.x; *y=vecLocation.y; }
  82. void GetTransposition(float *x, float *y) const { *x=fTx; *y=fTy; }
  83. hgeRect* GetBoundingBox(hgeRect *rect) const { memcpy(rect, &rectBoundingBox, sizeof(hgeRect)); return rect; }
  84. private:
  85. hgeParticleSystem();
  86. void _update(float fDeltaTime);
  87. static HGE *hge;
  88. float fUpdSpeed;
  89. float fResidue;
  90. float fAge;
  91. float fEmissionResidue;
  92. hgeVector vecPrevLocation;
  93. hgeVector vecLocation;
  94. float fTx, fTy;
  95. int nParticlesAlive;
  96. hgeRect rectBoundingBox;
  97. bool bUpdateBoundingBox;
  98. hgeParticle particles[MAX_PARTICLES];
  99. };
  100. class hgeParticleManager
  101. {
  102. public:
  103. hgeParticleManager(float fps=0.0f);
  104. ~hgeParticleManager();
  105. void Update(float dt);
  106. void Render();
  107. hgeParticleSystem* SpawnPS(hgeParticleSystemInfo *psi, float x, float y);
  108. bool IsPSAlive(hgeParticleSystem *ps) const;
  109. void Transpose(float x, float y);
  110. void GetTransposition(float *dx, float *dy) const {*dx=tX; *dy=tY;}
  111. void KillPS(hgeParticleSystem *ps);
  112. void KillAll();
  113. private:
  114. hgeParticleManager(const hgeParticleManager &);
  115. hgeParticleManager& operator= (const hgeParticleManager &);
  116. float fFPS;
  117. int nPS;
  118. float tX;
  119. float tY;
  120. hgeParticleSystem* psList[MAX_PSYSTEMS];
  121. };
  122. #endif