From 75f6220aeb31a17e2acba81f5de1c13193f33693 Mon Sep 17 00:00:00 2001 From: Steve Date: Fri, 26 Jan 2018 19:14:18 +0000 Subject: [PATCH] Start of items. --- common.mk | 9 +- src/defs.h | 3 + src/game/game.c | 34 +---- src/structs.h | 7 + src/world/entities/blobs/bob.c | 31 ++++ src/world/entities/blobs/bob.h | 21 +++ src/world/entities/items/battery.c | 43 ++++++ src/world/entities/items/battery.h | 30 ++++ src/world/entities/items/consumable.c | 73 ++++++++++ src/world/entities/items/consumable.h | 23 +++ src/world/entities/items/item.c | 182 ++++++++++++++++++++++++ src/world/entities/items/item.h | 38 +++++ src/world/world.c | 21 +++ src/world/world.h | 19 +++ tools/potHeader.txt | 17 +++ tools/tidyHeaders.sh | 197 ++++++++++++++++++++++++++ tools/updateI18N.sh | 168 ++++++++++++++++++++++ 17 files changed, 880 insertions(+), 36 deletions(-) create mode 100644 src/world/entities/blobs/bob.c create mode 100644 src/world/entities/blobs/bob.h create mode 100644 src/world/entities/items/battery.c create mode 100644 src/world/entities/items/battery.h create mode 100644 src/world/entities/items/consumable.c create mode 100644 src/world/entities/items/consumable.h create mode 100644 src/world/entities/items/item.c create mode 100644 src/world/entities/items/item.h create mode 100644 src/world/world.c create mode 100644 src/world/world.h create mode 100644 tools/potHeader.txt create mode 100755 tools/tidyHeaders.sh create mode 100755 tools/updateI18N.sh diff --git a/common.mk b/common.mk index 4ea2135..e10ceab 100644 --- a/common.mk +++ b/common.mk @@ -11,8 +11,9 @@ SEARCHPATH += src/util SEARCHPATH += src/widgets SEARCHPATH += src/world SEARCHPATH += src/world/entities -SEARCHPATH += src/world/entities/blobs +SEARCHPATH += src/world/entities/blobs SEARCHPATH += src/world/entities/boss +SEARCHPATH += src/world/entities/items vpath %.c $(SEARCHPATH) vpath %.h $(SEARCHPATH) @@ -20,14 +21,14 @@ vpath %.h $(SEARCHPATH) DEPS += defs.h structs.h OBJS += atlas.o -OBJS += blaze.o boss.o blobBoss.o -OBJS += camera.o combat.o +OBJS += battery.o blaze.o bob.o boss.o blobBoss.o +OBJS += camera.o combat.o consumable.o OBJS += draw.o OBJS += effects.o entities.o explosions.o eyeDroidCommander.o OBJS += frost.o OBJS += game.o OBJS += hub.o hud.o -OBJS += init.o input.o io.o items.o +OBJS += init.o input.o io.o item.o items.o OBJS += lookup.o OBJS += main.o map.o maths.o mia.o OBJS += objectives.o diff --git a/src/defs.h b/src/defs.h index a08805c..13920e1 100644 --- a/src/defs.h +++ b/src/defs.h @@ -79,6 +79,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #define JUMP_POWER -12 #define MAX_OXYGEN (FPS * 10) #define MAX_KEY_TYPES 12 +#define MAX_ITEMS 14 #define MAX_CHECKPOINTS 15 @@ -159,6 +160,7 @@ enum enum { ALIVE_ALIVE, + ALIVE_DYING, ALIVE_DEAD }; @@ -271,6 +273,7 @@ enum CH_EXPLODE, CH_WEAPON, CH_DEATH, + CH_ITEM, CH_MAX }; diff --git a/src/game/game.c b/src/game/game.c index 0e474c3..42652db 100644 --- a/src/game/game.c +++ b/src/game/game.c @@ -66,41 +66,11 @@ void addDefeatedTarget(char *name) } } -/* -public void updateTimePlayedString() +void addKey(char *name) { - final int hours = (int) TimeUnit.MILLISECONDS.toHours(timePlayed); - final int minutes = (int) TimeUnit.MILLISECONDS.toMinutes(timePlayed) % 60; - - timePlayedString = String.format("%dh %02dm", hours, minutes); + } -public int getShotPercentage(int i) -{ - return BMath.getPercentage(statShotsHit[i], statShotsFired[i]); -} - -public void addKey(String key) -{ - AtomicInteger i = keys.get(key); - if (i == null) - { - i = new AtomicInteger(); - keys.put(key, i); - } - i.incrementAndGet(); -} - -public void removeKey(String key) -{ - AtomicInteger i = keys.get(key); - if (i != null && i.decrementAndGet() == 0) - { - keys.remove(key); - } -} -*/ - void destroyGame(void) { } diff --git a/src/structs.h b/src/structs.h index 241d3eb..9058a88 100644 --- a/src/structs.h +++ b/src/structs.h @@ -91,6 +91,7 @@ typedef struct { struct Entity { unsigned long uniqueId; char name[MAX_NAME_LENGTH]; + char spriteName[MAX_NAME_LENGTH]; int type; float x; float y; @@ -127,6 +128,11 @@ struct Entity { int teleportTimer; int stunTimer; int weakAgainst; + int power; + int powerMax; + int collected; + int canBeCarried; + int canBePickedUp; long flags; SDL_Rect bounds; int sprite[3]; @@ -323,6 +329,7 @@ struct Particle { }; typedef struct { + char id[MAX_NAME_LENGTH]; Entity *bob, *boss; Map map; Entity entityHead, *entityTail; diff --git a/src/world/entities/blobs/bob.c b/src/world/entities/blobs/bob.c new file mode 100644 index 0000000..e56ae30 --- /dev/null +++ b/src/world/entities/blobs/bob.c @@ -0,0 +1,31 @@ +/* +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 "bob.h" + +void addBobItem(Entity *e) +{ + +} + +int numCarriedItems(void) +{ + return 0; +} diff --git a/src/world/entities/blobs/bob.h b/src/world/entities/blobs/bob.h new file mode 100644 index 0000000..d3ecca0 --- /dev/null +++ b/src/world/entities/blobs/bob.h @@ -0,0 +1,21 @@ +/* +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" diff --git a/src/world/entities/items/battery.c b/src/world/entities/items/battery.c new file mode 100644 index 0000000..4bbdd60 --- /dev/null +++ b/src/world/entities/items/battery.c @@ -0,0 +1,43 @@ +/* +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 "battery.h" + +void initBattery(Entity *e) +{ + initConsumable(e); + + e->spriteFrame = 0; + e->spriteTime = -1; +} + +void touch(Entity *other) +{ + if (touchedPlayer(other)) + { + world.bob->power = MIN(world.bob->power + self->power, world.bob->powerMax); + + setGameplayMessage(MSG_STANDARD, "Picked up a %s", self->name); + + pickupItem(); + + playSound(SND_ITEM, CH_ITEM); + } +} diff --git a/src/world/entities/items/battery.h b/src/world/entities/items/battery.h new file mode 100644 index 0000000..11739e4 --- /dev/null +++ b/src/world/entities/items/battery.h @@ -0,0 +1,30 @@ +/* +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 pickupItem(void); +extern void setGameplayMessage(int type, char *format, ...); +extern void initConsumable(Entity *e); +extern int touchedPlayer(Entity *e); + +extern Entity *self; +extern World world; diff --git a/src/world/entities/items/consumable.c b/src/world/entities/items/consumable.c new file mode 100644 index 0000000..6fda820 --- /dev/null +++ b/src/world/entities/items/consumable.c @@ -0,0 +1,73 @@ +/* +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 "consumable.h" + +static void tick(void); +static void die(void); + +void initConsumable(Entity *e) +{ + e->flags |= EF_IGNORE_BULLETS; + + e->health = FPS * 10; + + e->tick = tick; + e->die = die; +} + +static void tick(void) +{ + if (self->isOnGround) + { + self->dx *= 0.05; + } + + self->health--; + + if ((int) self->health == FPS * 2) + { + self->flags |= EF_FLICKER; + } + else if (self->health <= 0) + { + self->alive = ALIVE_DEAD; + } +} + +int touchedPlayer(Entity *other) +{ + return (other != NULL && other->type == ET_BOB && self->alive == ALIVE_ALIVE); +} + +void pickupItem(void) +{ + self->alive = (self->environment == ENV_AIR) ? ALIVE_DYING : ALIVE_DEAD; + self->health = FPS / 2; + self->thinkTime = 0; + self->dy = -2; + self->dx = 0; + self->flags |= EF_FLICKER | EF_WEIGHTLESS; +} + +static void die(void) +{ + /* we will handle this ourselves! */ +} diff --git a/src/world/entities/items/consumable.h b/src/world/entities/items/consumable.h new file mode 100644 index 0000000..b3d6e4f --- /dev/null +++ b/src/world/entities/items/consumable.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 Entity *self; diff --git a/src/world/entities/items/item.c b/src/world/entities/items/item.c new file mode 100644 index 0000000..a34b288 --- /dev/null +++ b/src/world/entities/items/item.c @@ -0,0 +1,182 @@ +/* +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 "item.h" + +static void reset(void); +static void tick(void); +static void touch(Entity *other); +static void changeEnvironment(void); +static void die(void); +static void destructablePickupItem(Entity *e); +static void enemyPickupItem(Entity *e); +static void bobPickupItem(void); + +void initItem(Entity *e) +{ + initEntity(e); + + STRNCPY(e->spriteName, "Weapon", MAX_NAME_LENGTH); + + e->flags |= EF_IGNORE_BULLETS; + + e->isMissionTarget = 1; + e->canBePickedUp = 1; + e->canBeCarried = 0; + e->collected = 0; + + e->sprite[FACING_LEFT] = e->sprite[FACING_RIGHT] = e->sprite[FACING_DIE] = getSpriteIndex(e->spriteName); + + e->tick = tick; + e->touch = touch; + e->changeEnvironment = changeEnvironment; + e->reset = reset; + e->die = die; +} + +static void reset(void) +{ + self->startX = (int) self->x; + self->startY = (int) self->y; +} + +static void tick(void) +{ + if (self->isOnGround) + { + self->dx *= 0.95; + } + + /* hack, to ensure the size doesn't exceed the maxmium of something carrying it */ + self->w = self->w > 32 ? 32 : self->w; +} + +static void touch(Entity *other) +{ + if (self->alive == ALIVE_ALIVE && other != NULL && self->canBePickedUp) + { + if (other->type == ET_BOB && !world.bob->stunTimer) + { + bobPickupItem(); + } + else if (other->type == ET_ENEMY) + { + enemyPickupItem(other); + } + else if (other->type == ET_DESTRUCTABLE) + { + destructablePickupItem(other); + } + } +} + +static void bobPickupItem(void) +{ + if (!self->isMissionTarget) + { + if (self->thinkTime == 0) + { + self->alive = ALIVE_DEAD; + addKey(self->name); + game.keysFound++; + updateObjective("KEY"); + + setGameplayMessage(MSG_STANDARD, "Picked up a %s", self->name); + + playSound(SND_KEY, CH_ITEM); + } + else + { + setGameplayMessage(MSG_GAMEPLAY, "Can't carry any more keys"); + } + } + else if (self->canBeCarried) + { + if (numCarriedItems() < MAX_ITEMS) + { + self->flags |= EF_GONE; + + if (!self->collected) + { + updateObjective(self->name); + self->collected = 1; + } + + addBobItem(self); + + setGameplayMessage(MSG_STANDARD, "Picked up a %s", self->name); + + playSound(SND_ITEM, CH_ITEM); + } + else + { + setGameplayMessage(MSG_GAMEPLAY, "Can't carry any more items"); + } + } + else + { + self->alive = ALIVE_DEAD; + updateObjective(self->name); + + if (strcmp(world.id, "teeka") != 0) + { + setGameplayMessage(MSG_STANDARD, "Picked up a %s", self->name); + } + + playSound(SND_ITEM, CH_ITEM); + } +} + +static void enemyPickupItem(Entity *e) +{ + if (e->canCarryItem && e->carriedItem == NULL && e->alive == ALIVE_ALIVE) + { + e->carriedItem = self; + + self->flags |= EF_GONE; + } +} + +static void destructablePickupItem(Entity *e) +{ + if (e->carriedItem == NULL && e->alive == ALIVE_ALIVE) + { + e->carriedItem = self; + + self->flags |= EF_GONE; + } +} + +static void changeEnvironment(void) +{ + if (self->environment == ENV_SLIME || self->environment == ENV_LAVA) + { + addTeleportStars(self); + self->x = self->startX; + self->y = self->startY; + addTeleportStars(self); + playSound(SND_APPEAR, CH_ANY); + } +} + +static void die(void) +{ + /* we will handle this ourselves! */ +} diff --git a/src/world/entities/items/item.h b/src/world/entities/items/item.h new file mode 100644 index 0000000..214a1aa --- /dev/null +++ b/src/world/entities/items/item.h @@ -0,0 +1,38 @@ +/* +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 pickupItem(void); +extern void setGameplayMessage(int type, char *format, ...); +extern void initConsumable(Entity *e); +extern int touchedPlayer(Entity *e); +extern void addTeleportStars(Entity *e); +extern void initEntity(Entity *e); +extern int getSpriteIndex(char *name); +extern void addBobItem(Entity *e); +extern int numCarriedItems(void); +extern void addKey(char *name); +extern void updateObjective(char *targetName); + +extern Entity *self; +extern Game game; +extern World world; diff --git a/src/world/world.c b/src/world/world.c new file mode 100644 index 0000000..6aabc0e --- /dev/null +++ b/src/world/world.c @@ -0,0 +1,21 @@ +/* +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 "world.h" diff --git a/src/world/world.h b/src/world/world.h new file mode 100644 index 0000000..d07721d --- /dev/null +++ b/src/world/world.h @@ -0,0 +1,19 @@ +/* +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. + +*/ diff --git a/tools/potHeader.txt b/tools/potHeader.txt new file mode 100644 index 0000000..56f4bf4 --- /dev/null +++ b/tools/potHeader.txt @@ -0,0 +1,17 @@ +# PO file for Blob Wars : Attrition +# Copyright 2018, Stephen J Sweeney +# This file is distributed under the GNU GPL 3.0 +# Email: stephenjsweeney@battleforthesolarsystem.com +# https://github.com/stephenjsweeney/blobwarsAttrition + +msgid "" +msgstr "" +"Project-Id-Version: Blob Wars : Attrition\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: {POT_CREATION_DATE}\n" +"PO-Revision-Date: ???\n" +"Last-Translator: ???\n" +"Language-Team: ???\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" diff --git a/tools/tidyHeaders.sh b/tools/tidyHeaders.sh new file mode 100755 index 0000000..9d2dc53 --- /dev/null +++ b/tools/tidyHeaders.sh @@ -0,0 +1,197 @@ +#!/usr/bin/php + + diff --git a/tools/updateI18N.sh b/tools/updateI18N.sh new file mode 100755 index 0000000..7998475 --- /dev/null +++ b/tools/updateI18N.sh @@ -0,0 +1,168 @@ +#!/usr/bin/php + + 0) + { + addString($matches[1]); + } + } +} + +function extractJSON($filename) +{ + $data = file_get_contents($filename); + $json = json_decode($data); + + if (strpos($filename, "widget") !== false) + { + foreach ($json as $widget) + { + if (array_key_exists("text", $widget)) + { + addString($widget->{"text"}, $filename); + } + } + } + else if (strpos($filename, "trophies") !== false) + { + foreach ($json as $trophy) + { + addString($trophy->{"title"}); + addString($trophy->{"description"}); + } + } + else if (strpos($filename, "missions") !== false) + { + addString($json->{"description"}); + + if (array_key_exists("objectives", $json)) + { + foreach ($json->{"objectives"} as $objective) + { + addString($json->{"description"}, $filename); + } + } + + if (array_key_exists("script", $json)) + { + foreach ($json->{"script"} as $scripts) + { + foreach ($scripts->{"lines"} as $line) + { + if (strpos($line, "MSG_BOX") === 0 || strpos($line, "IMPORTANT_MSG_BOX") === 0) + { + $i = strpos($line, ";") + 1; + + $line = substr($line, $i); + + addString($line, $filename); + } + } + } + } + } + else if (strpos($filename, "challenges") !== false) + { + addString($json->{"description"}); + } +} + +function recurseDir($dir) +{ + $files = array_diff(scandir($dir), array('..', '.')); + + foreach ($files as $file) + { + if (is_dir("$dir/$file")) + { + recurseDir("$dir/$file"); + } + else if (strstr($file, ".c") !== FALSE) + { + extractC("$dir/$file"); + } + else if (strstr($file, ".json") !== FALSE) + { + extractJSON("$dir/$file"); + } + } +} + +recurseDir("../src"); + +recurseDir("../data/widgets"); + +recurseDir("../data/missions"); + +recurseDir("../data/challenges"); + +recurseDir("../data/trophies"); + +$potHeader = file_get_contents("../tools/potHeader.txt"); + +$handle = fopen("../locale/tbftss.pot", "w"); + +$dateTime = date("Y-m-d H:i:sO"); + +$potHeader = str_replace("{POT_CREATION_DATE}", $dateTime, $potHeader); + +fwrite($handle, "$potHeader\n"); + +foreach ($strings as $string) +{ + fwrite($handle, "msgid \"$string\"\n"); + fwrite($handle, "msgstr \"\"\n"); + fwrite($handle, "\n"); +} + +fclose($handle); + +?>