Added particle effects.

This commit is contained in:
Steve 2018-02-04 16:14:14 +00:00
parent 113cc59ea6
commit 800f26055f
6 changed files with 92 additions and 28 deletions

View File

@ -408,10 +408,10 @@ struct Particle {
float dx; float dx;
float dy; float dy;
int size; int size;
float r; int r;
float g; int g;
float b; int b;
Sprite *spriteIndex; Sprite *sprite;
float spriteTime; float spriteTime;
int spriteFrame; int spriteFrame;
int destroyAfterAnim; int destroyAfterAnim;

View File

@ -88,10 +88,10 @@ static void drawHealth(void)
{ {
if (i < world.bob->health) if (i < world.bob->health)
{ {
drawRect(65 + (i * 18), 5, 14, 20, 0, 255, 0, 255); drawRect(65 + (i * 18), 5, 14, 20, 0, 168, 0, 255);
} }
drawOutlineRect(65 + (i * 18), 5, 14, 20, 255, 255, 255, 255); drawOutlineRect(65 + (i * 18), 5, 14, 20, 0, 255, 0, 255);
} }
} }
@ -101,7 +101,6 @@ static void drawPower(void)
drawText(560, 5, 16, TA_LEFT, colors.white, "Power"); drawText(560, 5, 16, TA_LEFT, colors.white, "Power");
drawOutlineRect(620, 5, 350, 15, 255, 0, 255, 255);
powerPercent = world.bob->power / world.bob->powerMax; powerPercent = world.bob->power / world.bob->powerMax;
drawRect(620, 5, 350 * powerPercent, 15, 255, 0, 255, 255); drawRect(620, 5, 350 * powerPercent, 15, 255, 0, 255, 255);

View File

@ -28,6 +28,7 @@ static Sprite *explosionSprite[2];
static Sprite *flameSprite; static Sprite *flameSprite;
static Sprite *smokeSprite; static Sprite *smokeSprite;
static Sprite *teleportStarSprite; static Sprite *teleportStarSprite;
static Texture *atlasTexture;
void initParticles(void) void initParticles(void)
{ {
@ -42,6 +43,8 @@ void initParticles(void)
smokeSprite = getSprite("Smoke"); smokeSprite = getSprite("Smoke");
teleportStarSprite = getSprite("TeleportStar"); teleportStarSprite = getSprite("TeleportStar");
atlasTexture = getTexture("gfx/atlas/atlas.png");
} }
void doParticles(void) void doParticles(void)
@ -83,6 +86,34 @@ void doParticles(void)
} }
} }
void drawParticles(int plane)
{
Particle *p;
int x, y;
for (p = world.particleHead.next ; p != NULL ; p = p->next)
{
if (p->onScreen && p->plane == plane)
{
x = -camera.x + p->x;
y = -camera.y + p->y;
switch (p->type)
{
case PT_TEXTURED:
blitRect(atlasTexture->texture, x, y, &p->sprite->frames[p->spriteFrame]->rect, 1);
break;
case PT_POINT:
drawRect(x, y, 2, 2, p->r, p->g, p->b, 255);
break;
case PT_LINE:
drawLine(x, y, (int) (x + p->dx), (int) (y + p->dy), p->r, p->g, p->b, 255);
break;
}
}
}
}
void addBlood(float x, float y) void addBlood(float x, float y)
{ {
Particle *p; Particle *p;
@ -94,30 +125,24 @@ void addBlood(float x, float y)
p->size = 1; p->size = 1;
p->dy = 1; p->dy = 1;
p->health = rrnd(5, 30); p->health = rrnd(5, 30);
p->spriteIndex = bloodSprite[(int) (rand() % 3)]; p->sprite = bloodSprite[(int) (rand() % 3)];
} }
void addSparkParticles(float x, float y) void addSparkParticles(float x, float y)
{ {
Particle *p; Particle *p;
int i; int i;
float c;
for (i = 0; i < 3; i++) for (i = 0; i < 3; i++)
{ {
p = createParticle(); p = createParticle();
p->x = x; p->x = x;
p->y = y; p->y = y;
p->dx = rand() % 300 - rand() % 300; p->dx = (randF() - randF()) * 3;
p->dx /= 100; p->dy = (randF() - randF()) * 3;
p->dy = rand() % 300 - rand() % 300;
p->dy /= 100;
p->health = rrnd(5, 30); p->health = rrnd(5, 30);
c = 50 + (rand() % 50); p->r = p->g = p->b = rrnd(128, 255);
c /= 100;
p->r = p->g = p->b = c;
} }
} }
@ -131,7 +156,7 @@ void addSmokeParticles(float x, float y)
p->y = y; p->y = y;
p->size = 1; p->size = 1;
p->health = rrnd(5, 30); p->health = rrnd(5, 30);
p->spriteIndex = smokeSprite; p->sprite = smokeSprite;
p->spriteTime = 5; p->spriteTime = 5;
p->spriteFrame = 0; p->spriteFrame = 0;
p->destroyAfterAnim = 1; p->destroyAfterAnim = 1;
@ -147,7 +172,7 @@ void addFlameParticles(float x, float y)
p->y = y; p->y = y;
p->size = 1; p->size = 1;
p->health = rrnd(5, 30); p->health = rrnd(5, 30);
p->spriteIndex = flameSprite; p->sprite = flameSprite;
p->spriteTime = 5; p->spriteTime = 5;
p->spriteFrame = 0; p->spriteFrame = 0;
p->destroyAfterAnim = 1; p->destroyAfterAnim = 1;
@ -171,7 +196,7 @@ void addExplosionParticles(float x, float y, float radius, int amount)
p->health = rrnd(FPS / 4, FPS); p->health = rrnd(FPS / 4, FPS);
p->spriteTime = 5; p->spriteTime = 5;
p->spriteFrame = 0; p->spriteFrame = 0;
p->spriteIndex = explosionSprite[i % 2]; p->sprite = explosionSprite[i % 2];
} }
} }
@ -186,8 +211,8 @@ void addTeleportStar(float x, float y)
p->dx = ((randF() - randF()) * 4); p->dx = ((randF() - randF()) * 4);
p->dy = ((randF() - randF()) * 4); p->dy = ((randF() - randF()) * 4);
p->health = rrnd(FPS / 4, FPS); p->health = rrnd(FPS / 4, FPS);
p->r = p->g = p->b = 1.0f; p->r = p->g = p->b = 255;
p->spriteIndex = teleportStarSprite; p->sprite = teleportStarSprite;
p->spriteFrame = (rand() % 12); p->spriteFrame = (rand() % 12);
p->plane = PLANE_FOREGROUND; p->plane = PLANE_FOREGROUND;
} }
@ -215,8 +240,8 @@ void addMIATeleportStars(float x, float y)
p->y = y; p->y = y;
p->dy = -(1 + (rand()) % 4); p->dy = -(1 + (rand()) % 4);
p->health = FPS * 3; p->health = FPS * 3;
p->r = p->g = p->b = 1.0f; p->r = p->g = p->b = 255;
p->spriteIndex = teleportStarSprite; p->sprite = teleportStarSprite;
p->spriteFrame = (rand() % 12); p->spriteFrame = (rand() % 12);
p->plane = PLANE_FOREGROUND; p->plane = PLANE_FOREGROUND;
} }
@ -232,14 +257,29 @@ void addTeleporterEffect(float x, float y)
p->dx = 0; p->dx = 0;
p->dy = -(randF() * 2); p->dy = -(randF() * 2);
p->health = rrnd(FPS / 4, FPS); p->health = rrnd(FPS / 4, FPS);
p->r = p->g = p->b = 1.0f; p->r = p->g = p->b = 255;
p->spriteIndex = teleportStarSprite; p->sprite = teleportStarSprite;
p->spriteFrame = (rand() % 12); p->spriteFrame = (rand() % 12);
} }
static void animate(Particle *p) static void animate(Particle *p)
{ {
Sprite *s;
s = p->sprite;
if (p->spriteTime != -1)
{
if (--p->spriteTime <= 0)
{
if (++p->spriteFrame >= s->numFrames)
{
p->spriteFrame = 0;
}
p->spriteTime = p->sprite->times[p->spriteFrame];
}
}
} }
static Particle *createParticle(void) static Particle *createParticle(void)
@ -251,5 +291,7 @@ static Particle *createParticle(void)
world.particleTail->next = p; world.particleTail->next = p;
world.particleTail = p; world.particleTail = p;
p->spriteTime = -1;
return p; return p;
} }

View File

@ -24,6 +24,10 @@ extern Sprite *getSprite(char *name);
extern int rrnd(int low, int high); extern int rrnd(int low, int high);
extern double randF(void); extern double randF(void);
extern int getDistance(int x1, int y1, int x2, int y2); extern int getDistance(int x1, int y1, int x2, int y2);
extern void drawRect(int x, int y, int w, int h, int r, int g, int b, int a);
extern void drawLine(int x1, int y1, int x2, int y2, int r, int g, int b, int a);
extern void blitRect(SDL_Texture *texture, int x, int y, SDL_Rect *srcRect, int center);
extern Texture *getTexture(const char *filename);
extern Camera camera; extern Camera camera;
extern World world; extern World world;

View File

@ -45,6 +45,8 @@ void initWorld(void)
initObjectives(); initObjectives();
initParticles();
initHud(); initHud();
initWeapons(); initWeapons();
@ -128,21 +130,36 @@ static void draw(void)
drawEntities(PLANE_BACKGROUND); drawEntities(PLANE_BACKGROUND);
drawParticles(PLANE_BACKGROUND);
drawMap(); drawMap();
drawEntities(PLANE_FOREGROUND); drawEntities(PLANE_FOREGROUND);
drawParticles(PLANE_FOREGROUND);
drawHud(); drawHud();
} }
} }
void startMission(void) void startMission(void)
{ {
Entity *self;
SDL_Rect *r;
self = (Entity*)world.bob;
world.state = WS_IN_PROGRESS; world.state = WS_IN_PROGRESS;
world.betweenTimer = FPS / 2; world.betweenTimer = FPS / 2;
r = &self->sprite[self->facing]->frames[self->spriteFrame]->rect;
self->w = r->w;
self->h = r->h;
resetAtCheckpoint(); resetAtCheckpoint();
world.entityToTrack = (Entity*)world.bob;
world.bob->flags &= ~EF_GONE; world.entityToTrack = self;
self->flags &= ~EF_GONE;
} }
static void doWorldStart(void) static void doWorldStart(void)

View File

@ -55,6 +55,8 @@ extern void drawHud(void);
extern void initHud(void); extern void initHud(void);
extern void initWeapons(void); extern void initWeapons(void);
extern void initQuadtree(Quadtree *root); extern void initQuadtree(Quadtree *root);
extern void initParticles(void);
extern void drawParticles(int plane);
extern App app; extern App app;
extern Dev dev; extern Dev dev;