Start of items.

This commit is contained in:
Steve 2018-01-26 19:14:18 +00:00
parent 14fee71a27
commit 75f6220aeb
17 changed files with 880 additions and 36 deletions

View File

@ -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

View File

@ -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
};

View File

@ -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)
{
}

View File

@ -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;

View File

@ -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;
}

View File

@ -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"

View File

@ -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);
}
}

View File

@ -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;

View File

@ -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! */
}

View File

@ -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;

View File

@ -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! */
}

View File

@ -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;

21
src/world/world.c Normal file
View File

@ -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"

19
src/world/world.h Normal file
View File

@ -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.
*/

17
tools/potHeader.txt Normal file
View File

@ -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"

197
tools/tidyHeaders.sh Executable file
View File

@ -0,0 +1,197 @@
#!/usr/bin/php
<?php
/*
Copyright (C) 2015-2016 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.
*/
$UPDATE_FILES = false;
function cleanHeader($headerFile)
{
global $UPDATE_FILES;
$func_pattern = "/(([A-Z0-9_]+)\\()/i";
$struct_pattern = "/([A-Z]+);/i";
$define_pattern = "/#define ([A-Z]+)/i";
$bodyFile = $headerFile;
$bodyFile[strlen($bodyFile) - 1] = 'c';
if (file_exists($bodyFile))
{
$header = file($headerFile);
$body = file_get_contents($bodyFile);
$lines = [];
$i = 0;
$hasChanges = false;
foreach ($header as $line)
{
if (preg_match("/extern|define/", $line) && strstr($line, "getTranslatedString") === FALSE)
{
preg_match($func_pattern, $line, $matches);
if (count($matches) == 3)
{
$extern = $matches[2];
if (!preg_match_all("/\b[(]?${extern}[\\(;,)\\n]/", $body))
{
if (!$hasChanges)
{
echo "$headerFile\n";
$hasChanges = true;
}
echo "\t- $line";
unset($header[$i]);
}
if (!in_array($line, $lines))
{
$lines[] = $line;
}
else
{
if (!$hasChanges)
{
echo "$headerFile\n";
$hasChanges = true;
}
echo "\t- $line";
unset($header[$i]);
}
}
preg_match($struct_pattern, $line, $matches);
if (count($matches) == 2)
{
$extern = $matches[1];
$externs[] = $extern;
if (!preg_match_all("/\b${extern}[\\.\\-\\)]/", $body))
{
if (!$hasChanges)
{
echo "$headerFile\n";
$hasChanges = true;
}
echo "\t- $line";
unset($header[$i]);
}
if (!in_array($line, $lines))
{
$lines[] = $line;
}
else
{
if (!$hasChanges)
{
echo "$headerFile\n";
$hasChanges = true;
}
echo "\t- $line";
unset($header[$i]);
}
}
preg_match($define_pattern, $line, $matches);
if (count($matches) == 2)
{
$extern = $matches[1];
$externs[] = $extern;
if (strstr($body, "$extern") === FALSE)
{
if (!$hasChanges)
{
echo "$headerFile\n";
$hasChanges = true;
}
echo "\t- $line";
unset($header[$i]);
}
if (!in_array($line, $lines))
{
$lines[] = $line;
}
else
{
if (!$hasChanges)
{
echo "$headerFile\n";
$hasChanges = true;
}
echo "\t- $line";
unset($header[$i]);
}
}
}
$i++;
}
if ($UPDATE_FILES && $hasChanges)
{
file_put_contents($headerFile, $header);
}
}
}
function recurseDir($dir)
{
if ($dir != "../src/json")
{
$files = array_diff(scandir($dir), array('..', '.'));
foreach ($files as $file)
{
if (is_dir("$dir/$file"))
{
recurseDir("$dir/$file");
}
else if (strstr($file, ".h") !== FALSE)
{
cleanHeader("$dir/$file");
}
}
}
}
if (isset($argv[1]))
{
$UPDATE_FILES = ($argv[1] == "-commit");
}
recurseDir("../src");
if (!$UPDATE_FILES)
{
echo "\nNo files updated. Use -commit to update headers\n";
}
?>

168
tools/updateI18N.sh Executable file
View File

@ -0,0 +1,168 @@
#!/usr/bin/php
<?php
/*
Copyright (C) 2015-2016 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.
*/
$strings = [];
function addString($string)
{
global $strings;
if ($string != "")
{
if (!in_array($string, $strings))
{
$strings[] = $string;
}
}
}
function extractC($filename)
{
$i = 0;
$lines = file($filename);
$reg = "(_\\(\"([^\\\"]*)\")";
foreach ($lines as $line)
{
$i++;
if (preg_match($reg, $line, $matches) > 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);
?>