hgepmanager.cpp
上传用户:jnfxsk
上传日期:2022-06-16
资源大小:3675k
文件大小:2k
源码类别:

游戏引擎

开发平台:

Visual C++

  1. /*
  2. ** Haaf's Game Engine 1.7
  3. ** Copyright (C) 2003-2007, Relish Games
  4. ** hge.relishgames.com
  5. **
  6. ** hgeParticleManager helper class implementation
  7. */
  8. #include "....includehgeparticle.h"
  9. hgeParticleManager::hgeParticleManager()
  10. {
  11. nPS=0;
  12. tX=tY=0.0f;
  13. }
  14. hgeParticleManager::~hgeParticleManager()
  15. {
  16. int i;
  17. for(i=0;i<nPS;i++) delete psList[i];
  18. }
  19. void hgeParticleManager::Update(float dt)
  20. {
  21. int i;
  22. for(i=0;i<nPS;i++)
  23. {
  24. psList[i]->Update(dt);
  25. if(psList[i]->GetAge()==-2.0f && psList[i]->GetParticlesAlive()==0)
  26. {
  27. delete psList[i];
  28. psList[i]=psList[nPS-1];
  29. nPS--;
  30. i--;
  31. }
  32. }
  33. }
  34. void hgeParticleManager::Render()
  35. {
  36. int i;
  37. for(i=0;i<nPS;i++) psList[i]->Render();
  38. }
  39. hgeParticleSystem* hgeParticleManager::SpawnPS(hgeParticleSystemInfo *psi, float x, float y)
  40. {
  41. if(nPS==MAX_PSYSTEMS) return 0;
  42. psList[nPS]=new hgeParticleSystem(psi);
  43. psList[nPS]->FireAt(x,y);
  44. psList[nPS]->Transpose(tX,tY);
  45. nPS++;
  46. return psList[nPS-1];
  47. }
  48. bool hgeParticleManager::IsPSAlive(hgeParticleSystem *ps) const
  49. {
  50. int i;
  51. for(i=0;i<nPS;i++) if(psList[i]==ps) return true;
  52. return false;
  53. }
  54. void hgeParticleManager::Transpose(float x, float y)
  55. {
  56. int i;
  57. for(i=0;i<nPS;i++) psList[i]->Transpose(x,y);
  58. tX=x; tY=y;
  59. }
  60. void hgeParticleManager::KillPS(hgeParticleSystem *ps)
  61. {
  62. int i;
  63. for(i=0;i<nPS;i++)
  64. {
  65. if(psList[i]==ps)
  66. {
  67. delete psList[i];
  68. psList[i]=psList[nPS-1];
  69. nPS--;
  70. return;
  71. }
  72. }
  73. }
  74. void hgeParticleManager::KillAll()
  75. {
  76. int i;
  77. for(i=0;i<nPS;i++) delete psList[i];
  78. nPS=0;
  79. }