From 743786efb82a3cf9148ff3ae9b8d3af4c63e1715 Mon Sep 17 00:00:00 2001 From: Steve Date: Sun, 13 Dec 2015 14:50:54 +0000 Subject: [PATCH] Added debris. --- common.mk | 2 +- gfx/debris/debris1.png | Bin 0 -> 822 bytes gfx/debris/debris2.png | Bin 0 -> 1172 bytes gfx/debris/debris3.png | Bin 0 -> 1157 bytes gfx/debris/debris4.png | Bin 0 -> 886 bytes gfx/debris/debris5.png | Bin 0 -> 889 bytes gfx/debris/debris6.png | Bin 0 -> 803 bytes src/battle/battle.c | 16 +++++ src/battle/battle.h | 3 + src/battle/debris.c | 141 +++++++++++++++++++++++++++++++++++++++++ src/battle/debris.h | 34 ++++++++++ src/battle/effects.c | 25 ++++++++ src/battle/fighters.c | 3 + src/battle/fighters.h | 1 + src/structs.h | 14 ++++ 15 files changed, 238 insertions(+), 1 deletion(-) create mode 100644 gfx/debris/debris1.png create mode 100644 gfx/debris/debris2.png create mode 100644 gfx/debris/debris3.png create mode 100644 gfx/debris/debris4.png create mode 100644 gfx/debris/debris5.png create mode 100644 gfx/debris/debris6.png create mode 100644 src/battle/debris.c create mode 100644 src/battle/debris.h diff --git a/common.mk b/common.mk index 9be17b4..a39f80f 100644 --- a/common.mk +++ b/common.mk @@ -11,7 +11,7 @@ DEPS += defs.h structs.h OBJS += ai.o OBJS += battle.o bullets.o OBJS += capitalShips.o challenges.o cJSON.o -OBJS += draw.o +OBJS += debris.o draw.o OBJS += effects.o entities.o extractionPoint.o OBJS += fighters.o OBJS += galacticMap.o game.o grid.o diff --git a/gfx/debris/debris1.png b/gfx/debris/debris1.png new file mode 100644 index 0000000000000000000000000000000000000000..3f24190bd4a0cf2091af2cc5c3963c8a03bf4654 GIT binary patch literal 822 zcmV-61Ihe}P)e zSad^gZEa<4bO1wgWnpw>WFU8GbZ8()Nlj2!fese{00N##L_t(I%f*wsZyZ$^#ea8a z?z}d$Z?CPj5=2kgWUAsdN}5TrnnYdVUQ=_pemMQKC+2s+C2phzo(=ul9I5X6#+ z?Tuw^cD;}B?#|54+`TkV;esL(r#(mKoKO0W;D5k3U##nuPb<9N{0#AvVEL;D;vdee zc%F`v1XF7S@LmvbzF2T{dPit|JeVs*qBTlu z5~V2C>jWDc9G{$EyDlHyyh)){VirZjX^NZABc;T)EPTgd62~a5Y1lS9YioRP?HaXe zmHO%`bFDF?#IY<2QnGdVG8-$)RNh@B%|i0iDr3Xq*W+Vir7)}IGQD1ph1OL6HrGHH zhAb~F(QG#HTo+ zX066#Fu)ap!Ei{Nc$7bRhs>Xlg(Hm72+J^VTo<#`?TTCL>$>~;HD~iVwq=ns4E}iW zf^XL}Fu1X~$)(v0zfi!BBK$@Jb>#{}U^pJLNKxr2)&3ptR*hl*g!s=PHt>DBEd;=wR!dK#h~x8fUX913N^u^BEVRb8 zZ7j=TdwZMx{e2dI%;m6w&s#0tb{v9gmFZ-{s8qtfdX?|mZ4_V{240rY^gQ0G)fhw( z&tASH3qu|~c_J=)c=0Ay^X=ZAUcG&rS)suG;UQn%zyB}aA09r`za1R#OQ%E0b$Rso z@rBvun<(_-(Gg2epW-(f3`V01H6P!*_n(gc3piyL_VW#~0ssI207*qoM6N<$g7Exx AT>t<8 literal 0 HcmV?d00001 diff --git a/gfx/debris/debris2.png b/gfx/debris/debris2.png new file mode 100644 index 0000000000000000000000000000000000000000..2a66d7e3003be377d346449ffd9c78c6eeebe99a GIT binary patch literal 1172 zcmV;F1Z(?=P)e zSad^gZEa<4bO1wgWnpw>WFU8GbZ8()Nlj2!fese{00aC1I}k#x2n{JAw)>1>cGgz%-V^O!o=302*iYh#K6c13{VLgppZC3 zbt5;WO%pe%lbn0D&pv;gUxq>jDhR?eJ=0H*^#482BlsUR7K^E%(;*`Si3#|;;0t+F z$aFleT;HeJ>mf7^yQcx59|e+&$5l8QrQB%n`lU-u2!XruE#Un-C}mly+G=44!Q$Do zXtvEOgM*BYjUgR}8P9{QFVTl>TU8qkUYeU@KAWZ4Zc`5eyn3DW)m5sVhXf*0((d(` z7#m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%mVKmY&$ M07*qoM6N<$g2U5}3;+NC literal 0 HcmV?d00001 diff --git a/gfx/debris/debris5.png b/gfx/debris/debris5.png new file mode 100644 index 0000000000000000000000000000000000000000..39ba84f0d362ce7f405f896747853957953c08b9 GIT binary patch literal 889 zcmV-<1BU#GP)e zSad^gZEa<4bO1wgWnpw>WFU8GbZ8()Nlj2!fese{00QAjL_t(I%XO4ZYgfUbU(YfEa`8x`?&JX^Jt1xF~P{Ck)HPt>fT&9ts#^ zsMl)vs>}ufcW&M+p(II2(iBt)tflJv_{K0eI%41V%VJLAm_n7jD42{!cv(ib-Dbh} z+3oks5?B#cRg4G=p2v&`rYJbhGQ^ltsp>db5oWBV69f$6m_e421AAFkmY`}aE#GG~ zikR~}wueJhgaV)_F!f4Bv6hPOW31(ql@(T6Et>T@*+nO0wbRkS^Jve_vD#>GXLXgc zB;nopIlKKnPc}BhoQ=mEpPte?I%1Tj)T&hu-@YZNREX;JX@jk`YDK7t(D8k~eei(B z+8V#Dud~(bm5CQcfdUf|{u_^3fBKZ}XvFyZeCj7vEvA4H49j0ctBBw^4s$`kitF-qv&r&Yc=fl_jw0>0+xkPds{sE4pd1>oM?f4F P00000NkvXXu0mjfT7aDD literal 0 HcmV?d00001 diff --git a/gfx/debris/debris6.png b/gfx/debris/debris6.png new file mode 100644 index 0000000000000000000000000000000000000000..4de2362315897217b1d6355ca2698a832463a4d8 GIT binary patch literal 803 zcmV+;1Kj+HP)e zSad^gZEa<4bO1wgWnpw>WFU8GbZ8()Nlj2!fese{00N6iL_t(I%bk?XZWC7&$A9ucTJ5Ga8MsfIb(l-MlGtm5R)Go?MM%IggjtQWOOa@Z#xHNs@%4!$Xwo0^ptt zdr880GQnEQD9gClXvkl^9!7*_z0RZi_nEI&>Ari%X_~UQv_u@oXMk^7E%|M44=aMJ z6my=(==79Ho)b9^-`>5;gNF|p^m-f}95Bu@(r%Ypt%mbtZB2gO-DPMDq1IfFW4>Bg zpxx~j$#6)eT4iHngU!uNL}V&&3h@1x3o}_w8=Q%}L0^s}p zS${OE@Ig2hA>-4xqW|qU0w{WEj%zucNy(K!b0VTX3n2FlZe62LL{?w=bNQ&us&Ffu hXZbY531%)0_#29~4t7A)E&~7n002ovPDHLkV1f@uY4iX9 literal 0 HcmV?d00001 diff --git a/src/battle/battle.c b/src/battle/battle.c index b86c352..71c02cc 100644 --- a/src/battle/battle.c +++ b/src/battle/battle.c @@ -42,6 +42,7 @@ void initBattle(void) { memset(&battle, 0, sizeof(Battle)); battle.bulletTail = &battle.bulletHead; + battle.debrisTail = &battle.debrisHead; battle.entityTail = &battle.entityHead; battle.effectTail = &battle.effectHead; battle.objectiveTail = &battle.objectiveHead; @@ -68,6 +69,8 @@ void initBattle(void) initMissionInfo(); + initDebris(); + resetWaypoints(); show = SHOW_BATTLE; @@ -136,6 +139,8 @@ static void doBattle(void) doEffects(); + doDebris(); + doPlayer(); doMessageBox(); @@ -177,6 +182,8 @@ static void draw(void) drawBullets(); + drawDebris(); + drawEffects(); drawHud(); @@ -339,6 +346,7 @@ void destroyBattle(void) { Entity *ent; Bullet *b; + Debris *d; Effect *e; Objective *o; @@ -358,6 +366,14 @@ void destroyBattle(void) } battle.bulletTail = &battle.bulletHead; + while (battle.debrisHead.next) + { + d = battle.debrisHead.next; + battle.debrisHead.next = d->next; + free(d); + } + battle.debrisTail = &battle.debrisHead; + while (battle.effectHead.next) { e = battle.effectHead.next; diff --git a/src/battle/battle.h b/src/battle/battle.h index 16b3a78..398fb7b 100644 --- a/src/battle/battle.h +++ b/src/battle/battle.h @@ -75,6 +75,9 @@ extern void doMessageBox(void); extern void drawMessageBox(void); extern void resetMessageBox(void); extern void initBullets(void); +extern void initDebris(void); +extern void doDebris(void); +extern void drawDebris(void); extern App app; extern Battle battle; diff --git a/src/battle/debris.c b/src/battle/debris.c new file mode 100644 index 0000000..e1ae101 --- /dev/null +++ b/src/battle/debris.c @@ -0,0 +1,141 @@ +/* +Copyright (C) 2015 Parallel Realities + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + +See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +*/ + +#include "debris.h" + +static void changeCourse(Debris *d); + +static Debris *debrisToDraw[MAX_DEBRIS_TO_DRAW]; +static SDL_Texture *debrisTexture[MAX_DEBRIS_TEXTURES]; + +void initDebris(void) +{ + memset(debrisToDraw, 0, sizeof(Debris*) * MAX_DEBRIS_TO_DRAW); + + debrisTexture[0] = getTexture("gfx/debris/debris1.png"); + debrisTexture[1] = getTexture("gfx/debris/debris2.png"); + debrisTexture[2] = getTexture("gfx/debris/debris3.png"); + debrisTexture[3] = getTexture("gfx/debris/debris4.png"); + debrisTexture[4] = getTexture("gfx/debris/debris5.png"); + debrisTexture[5] = getTexture("gfx/debris/debris6.png"); +} + +void addDebris(int x, int y, int amount) +{ + int i; + Debris *d; + + for (i = 0 ; i < amount ; i++) + { + d = malloc(sizeof(Debris)); + memset(d, 0, sizeof(Debris)); + battle.debrisTail->next = d; + battle.debrisTail = d; + + d->x = x; + d->y = y; + d->dx = rand() % 500 - rand() % 500; + d->dx *= 0.01; + d->dy = rand() % 500 - rand() % 500; + d->dy *= 0.01; + d->health = FPS + (FPS * (rand() % 3)); + + d->texture = debrisTexture[rand() % MAX_DEBRIS_TEXTURES]; + } +} + +void doDebris(void) +{ + int i; + Debris *d, *prev; + + memset(debrisToDraw, 0, sizeof(Debris*) * MAX_DEBRIS_TO_DRAW); + + prev = &battle.debrisHead; + + i = 0; + + for (d = battle.debrisHead.next ; d != NULL ; d = d->next) + { + d->x += d->dx; + d->y += d->dy; + + if (--d->thinkTime <= 0) + { + changeCourse(d); + } + + d->angle = mod(d->angle + 1, 360); + + addDebrisFire(d->x, d->y); + + if (--d->health <= 0) + { + if (d == battle.debrisTail) + { + battle.debrisTail = prev; + } + + prev->next = d->next; + free(d); + d = prev; + } + else + { + if (collision(d->x - 16 - battle.camera.x, d->y - 16 - battle.camera.y, 32, 32, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)) + { + debrisToDraw[i++] = d; + if (i >= MAX_DEBRIS_TO_DRAW) + { + printf("Too much debris to draw\n"); + exit(1); + } + } + } + + prev = d; + } +} + +static void changeCourse(Debris *d) +{ + float dir; + + dir = rand() % 25 - rand() % 25; + dir *= 0.01; + d->dx += dir; + + dir = rand() % 25 - rand() % 25; + dir *= 0.01; + d->dy += dir; + + d->thinkTime = 1 + (rand() % 5); +} + +void drawDebris(void) +{ + int i; + Debris *d; + + for (i = 0, d = debrisToDraw[i] ; d != NULL ; d = debrisToDraw[++i]) + { + blitRotated(d->texture, d->x - battle.camera.x, d->y - battle.camera.y, d->angle); + } +} diff --git a/src/battle/debris.h b/src/battle/debris.h new file mode 100644 index 0000000..203f936 --- /dev/null +++ b/src/battle/debris.h @@ -0,0 +1,34 @@ +/* +Copyright (C) 2015 Parallel Realities + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + +See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +*/ + +#include "../common.h" + +#include "../json/cJSON.h" + +#define MAX_DEBRIS_TO_DRAW 512 +#define MAX_DEBRIS_TEXTURES 6 + +extern float mod(float n, float x); +extern void blitRotated(SDL_Texture *texture, int x, int y, int angle); +extern int collision(int x1, int y1, int w1, int h1, int x2, int y2, int w2, int h2); +extern SDL_Texture *getTexture(char *filename); +extern void addDebrisFire(int x, int y); + +extern Battle battle; diff --git a/src/battle/effects.c b/src/battle/effects.c index 224e25f..99b6e74 100644 --- a/src/battle/effects.c +++ b/src/battle/effects.c @@ -140,6 +140,31 @@ void addSmallFighterExplosion(void) e->y -= e->size / 2; } +void addDebrisFire(int x, int y) +{ + Effect *e; + + e = malloc(sizeof(Effect)); + memset(e, 0, sizeof(Effect)); + battle.effectTail->next = e; + battle.effectTail = e; + + e->type = EFFECT_TEXTURE; + + e->x = x + (rand() % 8 - rand() % 8); + e->y = y + (rand() % 8 - rand() % 8); + e->texture = explosionTexture; + e->health = 0; + e->size = 8 + rand() % 9; + + setRandomFlameHue(e); + + e->a = rand() % 256; + + e->x -= e->size / 2; + e->y -= e->size / 2; +} + void addSmallExplosion(void) { int i; diff --git a/src/battle/fighters.c b/src/battle/fighters.c index e33818c..24d69ca 100644 --- a/src/battle/fighters.c +++ b/src/battle/fighters.c @@ -469,6 +469,7 @@ static void immediateDie(void) self->alive = ALIVE_DEAD; addSmallExplosion(); playBattleSound(SND_EXPLOSION_1 + rand() % 4, self->x, self->y); + addDebris(self->x, self->y, 8); } static void spinDie(void) @@ -491,6 +492,7 @@ static void spinDie(void) self->alive = ALIVE_DEAD; addSmallExplosion(); playBattleSound(SND_EXPLOSION_1 + rand() % 4, self->x, self->y); + addDebris(self->x, self->y, 8); } } @@ -512,6 +514,7 @@ static void straightDie(void) self->alive = ALIVE_DEAD; addSmallExplosion(); playBattleSound(SND_EXPLOSION_1 + rand() % 4, self->x, self->y); + addDebris(self->x, self->y, 8); } } diff --git a/src/battle/fighters.h b/src/battle/fighters.h index 30608d8..1e5ae89 100644 --- a/src/battle/fighters.h +++ b/src/battle/fighters.h @@ -44,6 +44,7 @@ extern void addShieldSplinterEffect(Entity *ent); extern void completeMission(void); extern void runScriptFunction(char *format, ...); extern char *getFileLocation(char *filename); +extern void addDebris(int x, int y, int amount); extern App app; extern Battle battle; diff --git a/src/structs.h b/src/structs.h index a757746..a990b13 100644 --- a/src/structs.h +++ b/src/structs.h @@ -23,6 +23,7 @@ typedef struct Lookup Lookup; typedef struct Weapon Weapon; typedef struct Entity Entity; typedef struct Bullet Bullet; +typedef struct Debris Debris; typedef struct Effect Effect; typedef struct Objective Objective; typedef struct StarSystem StarSystem; @@ -140,6 +141,18 @@ struct Bullet { Bullet *next; }; +struct Debris { + float x; + float y; + float dx; + float dy; + int health; + int thinkTime; + float angle; + SDL_Texture *texture; + Debris *next; +}; + typedef struct { float x; float y; @@ -247,6 +260,7 @@ typedef struct { PointF planet; Entity entityHead, *entityTail; Bullet bulletHead, *bulletTail; + Debris debrisHead, *debrisTail; Effect effectHead, *effectTail; Objective objectiveHead, *objectiveTail; struct cJSON *missionJSON;