diff --git a/src/structs.h b/src/structs.h index 640c364..034192c 100644 --- a/src/structs.h +++ b/src/structs.h @@ -408,10 +408,10 @@ struct Particle { float dx; float dy; int size; - float r; - float g; - float b; - Sprite *spriteIndex; + int r; + int g; + int b; + Sprite *sprite; float spriteTime; int spriteFrame; int destroyAfterAnim; diff --git a/src/world/hud.c b/src/world/hud.c index 221d49e..f298737 100644 --- a/src/world/hud.c +++ b/src/world/hud.c @@ -88,10 +88,10 @@ static void drawHealth(void) { 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"); - drawOutlineRect(620, 5, 350, 15, 255, 0, 255, 255); powerPercent = world.bob->power / world.bob->powerMax; drawRect(620, 5, 350 * powerPercent, 15, 255, 0, 255, 255); diff --git a/src/world/particles.c b/src/world/particles.c index 5fd94fd..f2d2097 100644 --- a/src/world/particles.c +++ b/src/world/particles.c @@ -28,6 +28,7 @@ static Sprite *explosionSprite[2]; static Sprite *flameSprite; static Sprite *smokeSprite; static Sprite *teleportStarSprite; +static Texture *atlasTexture; void initParticles(void) { @@ -42,6 +43,8 @@ void initParticles(void) smokeSprite = getSprite("Smoke"); teleportStarSprite = getSprite("TeleportStar"); + + atlasTexture = getTexture("gfx/atlas/atlas.png"); } 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) { Particle *p; @@ -94,30 +125,24 @@ void addBlood(float x, float y) p->size = 1; p->dy = 1; p->health = rrnd(5, 30); - p->spriteIndex = bloodSprite[(int) (rand() % 3)]; + p->sprite = bloodSprite[(int) (rand() % 3)]; } void addSparkParticles(float x, float y) { Particle *p; int i; - float c; for (i = 0; i < 3; i++) { p = createParticle(); p->x = x; p->y = y; - p->dx = rand() % 300 - rand() % 300; - p->dx /= 100; - p->dy = rand() % 300 - rand() % 300; - p->dy /= 100; + p->dx = (randF() - randF()) * 3; + p->dy = (randF() - randF()) * 3; p->health = rrnd(5, 30); - c = 50 + (rand() % 50); - c /= 100; - - p->r = p->g = p->b = c; + p->r = p->g = p->b = rrnd(128, 255); } } @@ -131,7 +156,7 @@ void addSmokeParticles(float x, float y) p->y = y; p->size = 1; p->health = rrnd(5, 30); - p->spriteIndex = smokeSprite; + p->sprite = smokeSprite; p->spriteTime = 5; p->spriteFrame = 0; p->destroyAfterAnim = 1; @@ -147,7 +172,7 @@ void addFlameParticles(float x, float y) p->y = y; p->size = 1; p->health = rrnd(5, 30); - p->spriteIndex = flameSprite; + p->sprite = flameSprite; p->spriteTime = 5; p->spriteFrame = 0; p->destroyAfterAnim = 1; @@ -171,7 +196,7 @@ void addExplosionParticles(float x, float y, float radius, int amount) p->health = rrnd(FPS / 4, FPS); p->spriteTime = 5; 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->dy = ((randF() - randF()) * 4); p->health = rrnd(FPS / 4, FPS); - p->r = p->g = p->b = 1.0f; - p->spriteIndex = teleportStarSprite; + p->r = p->g = p->b = 255; + p->sprite = teleportStarSprite; p->spriteFrame = (rand() % 12); p->plane = PLANE_FOREGROUND; } @@ -215,8 +240,8 @@ void addMIATeleportStars(float x, float y) p->y = y; p->dy = -(1 + (rand()) % 4); p->health = FPS * 3; - p->r = p->g = p->b = 1.0f; - p->spriteIndex = teleportStarSprite; + p->r = p->g = p->b = 255; + p->sprite = teleportStarSprite; p->spriteFrame = (rand() % 12); p->plane = PLANE_FOREGROUND; } @@ -232,14 +257,29 @@ void addTeleporterEffect(float x, float y) p->dx = 0; p->dy = -(randF() * 2); p->health = rrnd(FPS / 4, FPS); - p->r = p->g = p->b = 1.0f; - p->spriteIndex = teleportStarSprite; + p->r = p->g = p->b = 255; + p->sprite = teleportStarSprite; p->spriteFrame = (rand() % 12); } 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) @@ -251,5 +291,7 @@ static Particle *createParticle(void) world.particleTail->next = p; world.particleTail = p; + p->spriteTime = -1; + return p; } diff --git a/src/world/particles.h b/src/world/particles.h index dd6d41e..6a89720 100644 --- a/src/world/particles.h +++ b/src/world/particles.h @@ -24,6 +24,10 @@ extern Sprite *getSprite(char *name); extern int rrnd(int low, int high); extern double randF(void); 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 World world; diff --git a/src/world/world.c b/src/world/world.c index 7a9cc85..a6298a9 100644 --- a/src/world/world.c +++ b/src/world/world.c @@ -45,6 +45,8 @@ void initWorld(void) initObjectives(); + initParticles(); + initHud(); initWeapons(); @@ -128,21 +130,36 @@ static void draw(void) drawEntities(PLANE_BACKGROUND); + drawParticles(PLANE_BACKGROUND); + drawMap(); drawEntities(PLANE_FOREGROUND); + drawParticles(PLANE_FOREGROUND); + drawHud(); } } void startMission(void) { + Entity *self; + SDL_Rect *r; + + self = (Entity*)world.bob; + world.state = WS_IN_PROGRESS; world.betweenTimer = FPS / 2; + + r = &self->sprite[self->facing]->frames[self->spriteFrame]->rect; + self->w = r->w; + self->h = r->h; + resetAtCheckpoint(); - world.entityToTrack = (Entity*)world.bob; - world.bob->flags &= ~EF_GONE; + + world.entityToTrack = self; + self->flags &= ~EF_GONE; } static void doWorldStart(void) diff --git a/src/world/world.h b/src/world/world.h index c7eed8b..13904ac 100644 --- a/src/world/world.h +++ b/src/world/world.h @@ -55,6 +55,8 @@ extern void drawHud(void); extern void initHud(void); extern void initWeapons(void); extern void initQuadtree(Quadtree *root); +extern void initParticles(void); +extern void drawParticles(int plane); extern App app; extern Dev dev;