Pick up and store items.

This commit is contained in:
Steve 2018-02-04 08:11:42 +00:00
parent 5588abc063
commit 5bfea20534
9 changed files with 90 additions and 54 deletions

View File

@ -59,8 +59,6 @@ Entity *initBob(void)
b->type = ET_BOB;
b->itemTail = &b->itemHead;
walkSprite[FACING_LEFT] = getSprite("BobLeft");
walkSprite[FACING_RIGHT] = getSprite("BobRight");
walkSprite[FACING_DIE] = getSprite("BobSpin");
@ -626,20 +624,6 @@ void die(void)
}
}
void addBobItem(Item *i)
{
}
int numCarriedItems(void)
{
return 0;
}
void dropCarriedItems(void)
{
}
static SDL_Rect *getCurrentSprite(void)
{
if (world.bob->alive == ALIVE_ALIVE && world.bob->stunTimer <= 0)

View File

@ -23,7 +23,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
static void init(void);
static void reset(void);
static void tick(void);
static void nothing(void);
static void touch(Entity *other);
static void preTeleport(void);
static void teleport(void);
@ -54,7 +53,6 @@ Entity *initMIA(void)
m->spriteTime = rand() % 180;
m->init = init;
m->action = nothing;
m->reset = reset;
m->tick = tick;
m->touch = touch;
@ -93,7 +91,7 @@ static void tick(void)
m->shudderTimer = 2;
}
if (m->action != nothing)
if (!m->isMissionTarget)
{
m->starTimer--;
if (m->starTimer <= 0)
@ -110,7 +108,7 @@ static void touch(Entity *other)
m = (MIA*)self;
if (m->action == nothing && other == (Entity*)world.bob)
if (m->isMissionTarget && other == (Entity*)world.bob)
{
m->action = preTeleport;
m->teleportTimer = FPS * 3;
@ -152,11 +150,6 @@ static void teleport(void)
}
}
static void nothing(void)
{
}
static void load(cJSON *root)
{
MIA *m;

View File

@ -134,8 +134,7 @@ static void bobPickupItem(void)
{
if (i->thinkTime == 0)
{
i->alive = ALIVE_DEAD;
addKey(i->name);
addItem(i);
game.keysFound++;
updateObjective("KEY");
@ -150,18 +149,14 @@ static void bobPickupItem(void)
}
else if (i->canBeCarried)
{
if (numCarriedItems() < MAX_ITEMS)
if (addItem(i))
{
i->flags |= EF_GONE;
if (!i->collected)
{
updateObjective(i->name);
i->collected = 1;
}
addBobItem(i);
setGameplayMessage(MSG_STANDARD, _("Picked up a %s"), i->name);
playSound(SND_ITEM, CH_ITEM);

View File

@ -26,9 +26,8 @@ extern void setGameplayMessage(int type, char *format, ...);
extern void addTeleportStars(Entity *e);
extern void initEntity(Entity *e);
extern Sprite *getSprite(char *name);
extern void addBobItem(Item *i);
extern int addItem(Item *i);
extern int numCarriedItems(void);
extern void addKey(char *name);
extern void updateObjective(char *targetName);
extern Entity *self;

View File

@ -218,33 +218,33 @@ static void openWithKey(void)
s = (Structure*)self;
if (hasItem(s->requiredItem))
if (hasItem(s->requiredItem) || dev.cheatKeys)
{
if (s->thinkTime <= 0)
{
setGameplayMessage(MSG_GAMEPLAY, _("%s required"), s->requiredItem);
removeItem(s->requiredItem);
playSound(SND_DENIED, CH_MECHANICAL);
setGameplayMessage(MSG_GAMEPLAY, _("%s removed"), s->requiredItem);
STRNCPY(s->requiredItem, "", MAX_NAME_LENGTH);
s->isLocked = 0;
if (s->state != DOOR_OPEN)
{
playSound(SND_DOOR_START, CH_MECHANICAL);
}
s->thinkTime = 2;
s->state = DOOR_OPEN;
return;
}
removeItem(s->requiredItem);
setGameplayMessage(MSG_GAMEPLAY, _("%s removed"), s->requiredItem);
STRNCPY(s->requiredItem, "", MAX_NAME_LENGTH);
s->isLocked = 0;
if (s->state != DOOR_OPEN)
if (s->thinkTime <= 0)
{
playSound(SND_DOOR_START, CH_MECHANICAL);
setGameplayMessage(MSG_GAMEPLAY, _("%s required"), s->requiredItem);
playSound(SND_DENIED, CH_MECHANICAL);
}
s->state = DOOR_OPEN;
s->thinkTime = 2;
}
static int isOpening(void)

View File

@ -64,23 +64,84 @@ void addDefeatedTarget(char *name)
}
}
void addKey(char *name)
int addItem(Entity *item)
{
int i;
for (i = 0 ; i < MAX_ITEMS ; i++)
{
if (world.bob->items[i] == NULL)
{
world.bob->items[i] = item;
item->flags |= EF_GONE;
return 1;
}
}
return 0;
}
int hasItem(char *name)
{
int i;
Item *item;
for (i = 0 ; i < MAX_ITEMS ; i++)
{
item = (Item*)world.bob->items[i];
if (item != NULL && strcmp(item->name, name) == 0)
{
return 1;
}
}
return 0;
}
Entity *getItem(char *name)
{
int i;
Item *item;
for (i = 0 ; i < MAX_ITEMS ; i++)
{
item = (Item*)world.bob->items[i];
if (item != NULL && strcmp(item->name, name) == 0)
{
return world.bob->items[i];
}
}
return NULL;
}
void removeItem(char *name)
{
int i;
Item *item;
for (i = 0 ; i < MAX_ITEMS ; i++)
{
item = (Item*)world.bob->items[i];
if (item != NULL && strcmp(item->name, name) == 0)
{
item->flags &= ~EF_GONE;
item->alive = ALIVE_DEAD;
}
}
}
void dropCarriedItems(void)
{
int i;
for (i = 0 ; i < MAX_ITEMS ; i++)
{
}
}
static void loadMetaInfo(void)

View File

@ -24,3 +24,4 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
extern char *readFile(const char *filename);
extern Game game;
extern World world;

View File

@ -214,7 +214,7 @@ struct Bob {
int power, powerMax;
int jpEffectTimer;
PointF checkpoints[MAX_CHECKPOINTS];
Item itemHead, *itemTail;
Entity *items[MAX_ITEMS];
};
struct Structure {

View File

@ -67,6 +67,9 @@ void initWorld(void)
app.delegate.draw = draw;
startMission();
world.bob->x = 166 * MAP_TILE_SIZE;
world.bob->y = 98 * MAP_TILE_SIZE;
}
static void logic(void)