diff --git a/data/battle/items.json b/data/battle/items.json index bf44259..6917620 100644 --- a/data/battle/items.json +++ b/data/battle/items.json @@ -1,6 +1,6 @@ [ { - "name" : "Smile", + "name" : "smile", "textureName" : "gfx/items/smile.png" } ] diff --git a/sound/56246__q-k__latch-04.ogg b/sound/56246__q-k__latch-04.ogg new file mode 100644 index 0000000..75864ba Binary files /dev/null and b/sound/56246__q-k__latch-04.ogg differ diff --git a/src/battle/items.c b/src/battle/items.c index 8e26e3b..2d91d14 100644 --- a/src/battle/items.c +++ b/src/battle/items.c @@ -43,10 +43,14 @@ void loadItemDefs(void) e = malloc(sizeof(Entity)); memset(e, 0, sizeof(Entity)); + e->type = ET_ITEM; + e->active = 1; STRNCPY(e->name, cJSON_GetObjectItem(node, "name")->valuestring, MAX_NAME_LENGTH); STRNCPY(e->defName, cJSON_GetObjectItem(node, "name")->valuestring, MAX_NAME_LENGTH); e->texture = getTexture(cJSON_GetObjectItem(node, "textureName")->valuestring); + e->health = e->maxHealth = FPS; + SDL_QueryTexture(e->texture, NULL, NULL, &e->w, &e->h); defTail->next = e; @@ -66,6 +70,10 @@ Entity *spawnItem(char *name) memcpy(item, def, sizeof(Entity)); + item->dx = rand() % 100 - rand() % 100; + item->dx *= 0.01; + item->dy = rand() % 100 - rand() % 100; + item->dy *= 0.01; item->action = action; return item; @@ -98,8 +106,13 @@ static void action(void) { if ((e->flags & EF_COLLECTS_ITEMS) && collision(self->x - (self->w / 2), self->y - (self->h / 2), self->w, self->h, e->x - (e->w / 2), e->y - (e->h / 2), e->w, e->h)) { - e->alive = ALIVE_DEAD; - printf("Picked up an Item\n"); + self->alive = ALIVE_DEAD; + playSound(SND_GET_ITEM); + addHudMessage(colors.white, "Picked up %s", self->name); + + updateObjective(self->name, TT_ITEM); + + checkTrigger(self->name, TRIGGER_ITEM); } } } diff --git a/src/battle/items.h b/src/battle/items.h index 83532b1..a900ada 100644 --- a/src/battle/items.h +++ b/src/battle/items.h @@ -31,5 +31,10 @@ extern long flagsToLong(char *flags); extern Entity *spawnEntity(void); extern Entity **getAllEntsWithin(int x, int y, int w, int h, Entity *ignore); extern int collision(int x1, int y1, int w1, int h1, int x2, int y2, int w2, int h2); +extern void playSound(int id); +extern void addHudMessage(SDL_Color c, char *format, ...); +extern void updateObjective(char *name, int type); +extern void checkTrigger(char *name, int type); extern Entity *self; +extern Colors colors; diff --git a/src/defs.h b/src/defs.h index 8db6119..27d55f9 100644 --- a/src/defs.h +++ b/src/defs.h @@ -83,9 +83,9 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. enum { ET_FIGHTER, + ET_ITEM, ET_WAYPOINT, - ET_EXTRACTION_POINT, - ET_ITEM + ET_EXTRACTION_POINT }; enum @@ -154,6 +154,7 @@ enum SND_EXPLOSION_2, SND_EXPLOSION_3, SND_EXPLOSION_4, + SND_GET_ITEM, SND_MISSILE, SND_BOOST, SND_GUI_CLICK, @@ -176,7 +177,8 @@ enum TT_DESTROY, TT_DISABLE, TT_WAYPOINT, - TT_ESCAPED + TT_ESCAPED, + TT_ITEM }; enum @@ -184,7 +186,8 @@ enum TRIGGER_TIME, TRIGGER_KILLS, TRIGGER_WAYPOINT, - TRIGGER_ESCAPES + TRIGGER_ESCAPES, + TRIGGER_ITEM }; enum diff --git a/src/galaxy/mission.c b/src/galaxy/mission.c index b1dae65..f8ed906 100644 --- a/src/galaxy/mission.c +++ b/src/galaxy/mission.c @@ -27,6 +27,8 @@ static void loadFighters(cJSON *node); static void loadFighterGroups(cJSON *node); static void loadEntities(cJSON *node); static void loadEntityGroups(cJSON *node); +static void loadItems(cJSON *node); +static void loadItemGroups(cJSON *node); static unsigned long hashcode(const char *str); static char **toFighterTypeArray(char *types, int *numTypes); static void loadEpicData(cJSON *node); @@ -65,6 +67,10 @@ void loadMission(char *filename) loadEntityGroups(cJSON_GetObjectItem(root, "entityGroups")); + loadItems(cJSON_GetObjectItem(root, "items")); + + loadItemGroups(cJSON_GetObjectItem(root, "itemGroups")); + STRNCPY(music, cJSON_GetObjectItem(root, "music")->valuestring, MAX_NAME_LENGTH); if (cJSON_GetObjectItem(root, "epic")) @@ -422,7 +428,87 @@ static void loadEntityGroups(cJSON *node) STRNCPY(e->groupName, groupName, MAX_NAME_LENGTH); } - e->id = battle.entId++; + e->x = x; + e->y = y; + + e->x += (rand() % scatter) - (rand() % scatter); + e->y += (rand() % scatter) - (rand() % scatter); + + SDL_QueryTexture(e->texture, NULL, NULL, &e->w, &e->h); + } + + node = node->next; + } + } +} + +static void loadItems(cJSON *node) +{ +} + +static void loadItemGroups(cJSON *node) +{ + Entity *e; + char *name, *groupName, *type; + int i, scatter, number; + long flags; + float x, y; + + flags = -1; + scatter = 1; + + if (node) + { + node = node->child; + + while (node) + { + type = cJSON_GetObjectItem(node, "type")->valuestring; + number = cJSON_GetObjectItem(node, "number")->valueint; + x = cJSON_GetObjectItem(node, "x")->valuedouble * GRID_CELL_WIDTH; + y = cJSON_GetObjectItem(node, "y")->valuedouble * GRID_CELL_HEIGHT; + name = NULL; + groupName = NULL; + + if (cJSON_GetObjectItem(node, "name")) + { + name = cJSON_GetObjectItem(node, "name")->valuestring; + } + + if (cJSON_GetObjectItem(node, "groupName")) + { + groupName = cJSON_GetObjectItem(node, "groupName")->valuestring; + } + + if (cJSON_GetObjectItem(node, "scatter")) + { + scatter = cJSON_GetObjectItem(node, "scatter")->valueint; + } + + if (cJSON_GetObjectItem(node, "flags")) + { + flags = flagsToLong(cJSON_GetObjectItem(node, "flags")->valuestring); + } + + for (i = 0 ; i < number ; i++) + { + e = spawnItem(type); + + if (name) + { + STRNCPY(e->name, name, MAX_NAME_LENGTH); + } + + if (groupName) + { + STRNCPY(e->groupName, groupName, MAX_NAME_LENGTH); + } + + if (flags != -1) + { + e->flags = flags; + } + e->x = x; e->y = y; diff --git a/src/galaxy/mission.h b/src/galaxy/mission.h index 8b733ba..4807dd7 100644 --- a/src/galaxy/mission.h +++ b/src/galaxy/mission.h @@ -39,6 +39,7 @@ extern Entity *spawnWaypoint(void); extern void activateNextWaypoint(void); extern void selectWidget(const char *name, const char *group); extern Entity *spawnExtractionPoint(void); +extern Entity *spawnItem(char *type); extern void failIncompleteObjectives(void); extern void fleeAllEnemies(void); diff --git a/src/system/lookup.c b/src/system/lookup.c index daa2ac2..985f780 100644 --- a/src/system/lookup.c +++ b/src/system/lookup.c @@ -47,6 +47,7 @@ void initLookups(void) addLookup("TT_DISABLE", TT_DISABLE); addLookup("TT_WAYPOINT", TT_WAYPOINT); addLookup("TT_ESCAPED", TT_ESCAPED); + addLookup("TT_ITEM", TT_ITEM); addLookup("WT_BUTTON", WT_BUTTON); addLookup("WT_SELECT", WT_SELECT); diff --git a/src/system/sound.c b/src/system/sound.c index 1810001..ebe10a9 100644 --- a/src/system/sound.c +++ b/src/system/sound.c @@ -98,6 +98,7 @@ static void loadSounds(void) sounds[SND_MISSILE] = Mix_LoadWAV("sound/65787__iwilldstroyu__laserrocket.ogg"); sounds[SND_BOOST] = Mix_LoadWAV("sound/18380__inferno__hvrl.ogg"); /*sounds[SND_ECM] = Mix_LoadWAV("sound/18380__inferno__hvrl.ogg");*/ + sounds[SND_GET_ITEM] = Mix_LoadWAV("sound/56246__q-k__latch-04.ogg"); sounds[SND_EXPLOSION_1] = Mix_LoadWAV("sound/162265__qubodup__explosive.ogg"); sounds[SND_EXPLOSION_2] = Mix_LoadWAV("sound/207322__animationisaac__short-explosion.ogg"); sounds[SND_EXPLOSION_3] = Mix_LoadWAV("sound/254071__tb0y298__firework-explosion.ogg");