hgeparticle.h
上传用户:jalin138
上传日期:2022-02-12
资源大小:5720k
文件大小:3k
源码类别:

游戏引擎

开发平台:

Visual C++

  1. /*
  2. ** Haaf's Game Engine 1.7
  3. ** Copyright (C) 2003-2007, 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);
  67. hgeParticleSystem(hgeParticleSystemInfo *psi);
  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 SetScale(float scale) { fScale = scale; }
  79. void TrackBoundingBox(bool bTrack) { bUpdateBoundingBox=bTrack; }
  80. int GetParticlesAlive() const { return nParticlesAlive; }
  81. float GetAge() const { return fAge; }
  82. void GetPosition(float *x, float *y) const { *x=vecLocation.x; *y=vecLocation.y; }
  83. void GetTransposition(float *x, float *y) const { *x=fTx; *y=fTy; }
  84. float GetScale() { return fScale; }
  85. hgeRect* GetBoundingBox(hgeRect *rect) const;
  86. private:
  87. hgeParticleSystem();
  88. static HGE *hge;
  89. float fAge;
  90. float fEmissionResidue;
  91. hgeVector vecPrevLocation;
  92. hgeVector vecLocation;
  93. float fTx, fTy;
  94. float fScale;
  95. int nParticlesAlive;
  96. hgeRect rectBoundingBox;
  97. bool bUpdateBoundingBox;
  98. hgeParticle particles[MAX_PARTICLES];
  99. };
  100. class hgeParticleManager
  101. {
  102. public:
  103. hgeParticleManager();
  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. int nPS;
  117. float tX;
  118. float tY;
  119. hgeParticleSystem* psList[MAX_PSYSTEMS];
  120. };
  121. #endif