📄 hgeparticle.h
字号:
/*
** Haaf's Game Engine 1.4
** Copyright (C) 2003-2004, Relish Games
** hge.relishgames.com
**
** hgeParticleSystem helper class header
*/
#ifndef HGEPARTICLE_H
#define HGEPARTICLE_H
#include "hgehelpers.h"
#include "hgesprite.h"
#include "hgevector.h"
#include "hgecolor.h"
#include "hgerect.h"
#include <string.h>
#define MAX_PARTICLES 500
#define MAX_PSYSTEMS 100
struct hgeParticle
{
hgeVector vecLocation;
hgeVector vecVelocity;
float fGravity;
float fRadialAccel;
float fTangentialAccel;
float fSpin;
float fSpinDelta;
float fSize;
float fSizeDelta;
hgeColor colColor; // + alpha
hgeColor colColorDelta;
float fAge;
float fTerminalAge;
};
struct hgeParticleSystemInfo
{
hgeSprite* sprite; // texture + blend mode
int nEmission; // particles per sec
float fLifetime;
float fParticleLifeMin;
float fParticleLifeMax;
float fDirection;
float fSpread;
bool bRelative;
float fSpeedMin;
float fSpeedMax;
float fGravityMin;
float fGravityMax;
float fRadialAccelMin;
float fRadialAccelMax;
float fTangentialAccelMin;
float fTangentialAccelMax;
float fSizeStart;
float fSizeEnd;
float fSizeVar;
float fSpinStart;
float fSpinEnd;
float fSpinVar;
hgeColor colColorStart; // + alpha
hgeColor colColorEnd;
float fColorVar;
float fAlphaVar;
};
class hgeParticleSystem
{
public:
hgeParticleSystemInfo info;
hgeParticleSystem(char *filename, hgeSprite *sprite, float fps=0.0f);
hgeParticleSystem(hgeParticleSystemInfo *psi, float fps=0.0f);
void Render();
void FireAt(float x, float y);
void Fire();
void Stop();
void Update(float fDeltaTime);
void MoveTo(float x, float y);
void Transpose(float x, float y);
void GetBoundingBox(hgeRect *rect) const { memcpy(rect, &rectBoundingBox, sizeof(hgeRect)); }
int GetParticlesAlive() const { return nParticlesAlive; }
float GetAge() const { return fAge; }
void GetPosition(float *x, float *y) { *x=vecLocation.x; *y=vecLocation.y; }
private:
hgeParticleSystem();
void _update(float fDeltaTime);
float fUpdSpeed;
float fResidue;
float fAge;
float fEmissionResidue;
hgeVector vecPrevLocation;
hgeVector vecLocation;
int nParticlesAlive;
hgeRect rectBoundingBox;
hgeParticle particles[MAX_PARTICLES];
};
class hgeParticleManager
{
public:
hgeParticleManager(float fps=0.0f);
~hgeParticleManager();
void Update(float dt);
void Render();
hgeParticleSystem* SpawnPS(hgeParticleSystemInfo *psi, float x, float y);
bool IsPSAlive(hgeParticleSystem *ps);
void KillPS(hgeParticleSystem *ps);
void KillAll();
private:
float fFPS;
int nPS;
hgeParticleSystem* psList[MAX_PSYSTEMS];
};
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -