From e7d4c028341556eb8f59e5866ee9354aafc2100a Mon Sep 17 00:00:00 2001 From: Steve Date: Fri, 26 Jan 2018 22:29:08 +0000 Subject: [PATCH] Remaining items. --- common.mk | 5 +- src/structs.h | 1 + src/world/entities/blobs/teeka.c | 5 ++ src/world/entities/items/cherry.h | 3 - src/world/entities/items/heart.c | 69 +++++++++++++++++++ src/world/entities/items/heart.h | 32 +++++++++ src/world/entities/items/key.c | 45 +++++++++++++ src/world/entities/items/key.h | 23 +++++++ src/world/entities/items/keycard.c | 83 +++++++++++++++++++++++ src/world/entities/items/keycard.h | 33 +++++++++ src/world/entities/items/weaponPickup.c | 89 +++++++++++++++++++++++++ src/world/entities/items/weaponPickup.h | 36 ++++++++++ 12 files changed, 419 insertions(+), 5 deletions(-) create mode 100644 src/world/entities/items/heart.c create mode 100644 src/world/entities/items/heart.h create mode 100644 src/world/entities/items/key.c create mode 100644 src/world/entities/items/key.h create mode 100644 src/world/entities/items/keycard.c create mode 100644 src/world/entities/items/keycard.h create mode 100644 src/world/entities/items/weaponPickup.c create mode 100644 src/world/entities/items/weaponPickup.h diff --git a/common.mk b/common.mk index 3663f97..bd2660b 100644 --- a/common.mk +++ b/common.mk @@ -27,8 +27,9 @@ OBJS += draw.o OBJS += effects.o entities.o explosions.o eyeDroidCommander.o OBJS += frost.o OBJS += game.o -OBJS += hub.o hud.o +OBJS += heart.o hub.o hud.o OBJS += init.o input.o io.o item.o items.o +OBJS += key.o keycard.o OBJS += lookup.o OBJS += main.o map.o maths.o mia.o OBJS += objectives.o @@ -37,7 +38,7 @@ OBJS += quadtree.o OBJS += sound.o sprites.o OBJS += tankCommander.o tankTrack.o teeka.o text.o textures.o title.o triggers.o OBJS += unit.o util.o -OBJS += weapons.o widgets.o +OBJS += weapons.o weaponPickup.o widgets.o # top-level rule to create the program. all: $(PROG) $(LOCALE_MO) diff --git a/src/structs.h b/src/structs.h index 9058a88..054a5be 100644 --- a/src/structs.h +++ b/src/structs.h @@ -133,6 +133,7 @@ struct Entity { int collected; int canBeCarried; int canBePickedUp; + int provided; long flags; SDL_Rect bounds; int sprite[3]; diff --git a/src/world/entities/blobs/teeka.c b/src/world/entities/blobs/teeka.c index 21034e6..deb53c5 100644 --- a/src/world/entities/blobs/teeka.c +++ b/src/world/entities/blobs/teeka.c @@ -159,3 +159,8 @@ static void attack(void) self->reload = 5; } + +void teekaExitMission(void) +{ + exitMission = 1; +} diff --git a/src/world/entities/items/cherry.h b/src/world/entities/items/cherry.h index f91d6e7..8b0c40a 100644 --- a/src/world/entities/items/cherry.h +++ b/src/world/entities/items/cherry.h @@ -21,14 +21,11 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "../../../common.h" extern void initConsumable(Entity *e); -extern int getSpriteIndex(char *name); extern void setGameplayMessage(int type, char *format, ...); extern void playSound(int snd, int ch); -extern void updateObjective(char *targetName); extern int touchedPlayer(Entity *other); extern void pickupItem(void); extern float limit(float i, float a, float b); extern Entity *self; -extern Game game; extern World world; diff --git a/src/world/entities/items/heart.c b/src/world/entities/items/heart.c new file mode 100644 index 0000000..0767191 --- /dev/null +++ b/src/world/entities/items/heart.c @@ -0,0 +1,69 @@ +/* +Copyright (C) 2018 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 "heart.h" + +static void action(void); +static void touch(Entity *other); + +void initHeart(Entity *e) +{ + initItem(e); + + e->isMissionTarget = 1; + + STRNCPY(e->spriteName, "Heart", MAX_NAME_LENGTH); + + e->sprite[0] = e->sprite[1] = e->sprite[2] = getSpriteIndex("Heart"); + + e->spriteFrame = 0; + e->spriteTime = -1; + + e->action = action; + e->touch = touch; +} + +static void action(void) +{ + if (self->isOnGround) + { + self->dy = -5; + } + + self->thinkTime = FPS * rrnd(1, 3); +} + +static void touch(Entity *other) +{ + if (other != NULL && other->type == ET_BOB && self->alive == ALIVE_ALIVE) + { + game.hearts++; + + world.bob->health = world.bob->healthMax = game.hearts; + + setGameplayMessage(MSG_OBJECTIVE, "Found a heart - Max health increased!"); + + playSound(SND_HEART_CELL, CH_ITEM); + + self->alive = ALIVE_DEAD; + + updateObjective("HEART_CELL"); + } +} diff --git a/src/world/entities/items/heart.h b/src/world/entities/items/heart.h new file mode 100644 index 0000000..1a1e804 --- /dev/null +++ b/src/world/entities/items/heart.h @@ -0,0 +1,32 @@ +/* +Copyright (C) 2018 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" + +extern void playSound(int snd, int ch); +extern void setGameplayMessage(int type, char *format, ...); +extern void initItem(Entity *e); +extern int getSpriteIndex(char *name); +extern void updateObjective(char *targetName); +extern int rrnd(int low, int high); + +extern Entity *self; +extern Game game; +extern World world; diff --git a/src/world/entities/items/key.c b/src/world/entities/items/key.c new file mode 100644 index 0000000..b9bca38 --- /dev/null +++ b/src/world/entities/items/key.c @@ -0,0 +1,45 @@ +/* +Copyright (C) 2018 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 "key.h" + +void initBronzeKey(Entity *e) +{ + initItem(e); + + STRNCPY(e->name, "Bronze Key", MAX_NAME_LENGTH); + STRNCPY(e->spriteName, "BronzeKey", MAX_NAME_LENGTH); +} + +void initSilverKey(Entity *e) +{ + initItem(e); + + STRNCPY(e->name, "Silver Key", MAX_NAME_LENGTH); + STRNCPY(e->spriteName, "SilverKey", MAX_NAME_LENGTH); +} + +void initGoldKey(Entity *e) +{ + initItem(e); + + STRNCPY(e->name, "Gold Key", MAX_NAME_LENGTH); + STRNCPY(e->spriteName, "GoldKey", MAX_NAME_LENGTH); +} diff --git a/src/world/entities/items/key.h b/src/world/entities/items/key.h new file mode 100644 index 0000000..f061783 --- /dev/null +++ b/src/world/entities/items/key.h @@ -0,0 +1,23 @@ +/* +Copyright (C) 2018 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" + +extern void initItem(Entity *e); diff --git a/src/world/entities/items/keycard.c b/src/world/entities/items/keycard.c new file mode 100644 index 0000000..b19c03b --- /dev/null +++ b/src/world/entities/items/keycard.c @@ -0,0 +1,83 @@ +/* +Copyright (C) 2018 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 "keycard.h" + +static void (*itemTouch)(Entity *other); +static void touchWhiteKeycard(Entity *other); + +void initRedKeycard(Entity *e) +{ + initItem(e); + + STRNCPY(e->name, "Red Keycard", MAX_NAME_LENGTH); + STRNCPY(e->spriteName, "RedKeycard", MAX_NAME_LENGTH); +} + +void initBlueKeycard(Entity *e) +{ + initItem(e); + + STRNCPY(e->name, "Blue Keycard", MAX_NAME_LENGTH); + STRNCPY(e->spriteName, "BlueKeycard", MAX_NAME_LENGTH); +} + +void initGreenKeycard(Entity *e) +{ + initItem(e); + + STRNCPY(e->name, "Green Keycard", MAX_NAME_LENGTH); + STRNCPY(e->spriteName, "GreenKeycard", MAX_NAME_LENGTH); +} + +void initYellowKeycard(Entity *e) +{ + initItem(e); + + STRNCPY(e->name, "Yellow Keycard", MAX_NAME_LENGTH); + STRNCPY(e->spriteName, "YellowKeycard", MAX_NAME_LENGTH); +} + +void initWhiteKeycard(Entity *e) +{ + initItem(e); + + STRNCPY(e->name, "White Keycard", MAX_NAME_LENGTH); + STRNCPY(e->spriteName, "WhiteKeycard", MAX_NAME_LENGTH); + + itemTouch = e->touch; + + e->touch = touchWhiteKeycard; +} + +static void touchWhiteKeycard(Entity *other) +{ + itemTouch(other); + + if (other == world.bob) + { + updateObjective("White Keycard"); + + if (self->alive == ALIVE_DEAD) + { + teekaExitMission(); + } + } +} diff --git a/src/world/entities/items/keycard.h b/src/world/entities/items/keycard.h new file mode 100644 index 0000000..ed850a8 --- /dev/null +++ b/src/world/entities/items/keycard.h @@ -0,0 +1,33 @@ +/* +Copyright (C) 2018 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" + +extern void playSound(int snd, int ch); +extern void setGameplayMessage(int type, char *format, ...); +extern void initItem(Entity *e); +extern int getSpriteIndex(char *name); +extern void updateObjective(char *targetName); +extern int rrnd(int low, int high); +extern void teekaExitMission(void); + +extern Entity *self; +extern Game game; +extern World world; diff --git a/src/world/entities/items/weaponPickup.c b/src/world/entities/items/weaponPickup.c new file mode 100644 index 0000000..f8ebeea --- /dev/null +++ b/src/world/entities/items/weaponPickup.c @@ -0,0 +1,89 @@ +/* +Copyright (C) 2018 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 "weaponPickup.h" + +static void (*itemTick)(void); +static void tick(void); +static void touch(Entity *other); + +static char *description[] = { + "Pistol", + "Plasma Rifle", + "Spread Gun", + "Laser Cannon", + "Grenades" +}; + +void initWeaponPickup(Entity *e) +{ + initConsumable(e); + + e->weaponType = WPN_PISTOL; + + e->sprite[0] = e->sprite[1] = e->sprite[2] = getSpriteIndex("Weapon"); + e->spriteFrame = e->weaponType; + e->spriteTime = -1; + + setEntitySize(e); + + if (e->provided) + { + e->health = 9999; + } + + itemTick = e->tick; + + e->tick = tick; + e->touch = touch; +} + +static void tick(void) +{ + itemTick(); + + if (self->provided && self->alive == ALIVE_ALIVE) + { + self->health = 9999; + } +} + +static void touch(Entity *other) +{ + if (touchedPlayer(other)) + { + world.bob->weaponType = self->weaponType; + + switch (self->weaponType) + { + case WPN_GRENADES: + setGameplayMessage(MSG_STANDARD, "Got some Grenades"); + break; + + default: + setGameplayMessage(MSG_STANDARD, "Picked up a %s", description[self->weaponType]); + break; + } + + pickupItem(); + + playSound(SND_WEAPON, CH_ITEM); + } +} diff --git a/src/world/entities/items/weaponPickup.h b/src/world/entities/items/weaponPickup.h new file mode 100644 index 0000000..22efe30 --- /dev/null +++ b/src/world/entities/items/weaponPickup.h @@ -0,0 +1,36 @@ +/* +Copyright (C) 2018 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" + +extern void playSound(int snd, int ch); +extern void setGameplayMessage(int type, char *format, ...); +extern void initConsumable(Entity *e); +extern int getSpriteIndex(char *name); +extern void updateObjective(char *targetName); +extern int rrnd(int low, int high); +extern void pickupItem(void); +extern void teekaExitMission(void); +extern void setEntitySize(Entity *e); +extern int touchedPlayer(Entity *e); + +extern Entity *self; +extern Game game; +extern World world;