blobwarsAttrition/src/entities/items/heart.c

88 lines
1.8 KiB
C
Raw Normal View History

2018-01-26 23:29:08 +01:00
/*
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);
static void init(void);
2018-01-26 23:29:08 +01:00
2018-01-30 09:29:09 +01:00
Entity *initHeart(Entity *e)
2018-01-26 23:29:08 +01:00
{
Item *i;
2018-01-30 09:29:09 +01:00
i = (Item*)createItem();
2018-01-28 10:34:14 +01:00
2018-03-01 23:30:33 +01:00
i->type = ET_HEART;
2018-01-26 23:29:08 +01:00
i->isMissionTarget = 1;
2018-01-26 23:29:08 +01:00
STRNCPY(i->spriteName, "Heart", MAX_NAME_LENGTH);
2018-01-26 23:29:08 +01:00
2018-01-30 00:00:14 +01:00
i->sprite[0] = i->sprite[1] = i->sprite[2] = getSprite("Heart");
2018-01-26 23:29:08 +01:00
i->spriteFrame = 0;
i->spriteTime = -1;
2018-01-26 23:29:08 +01:00
i->action = action;
i->init = init;
i->touch = touch;
2018-01-30 09:29:09 +01:00
return (Entity*)i;
2018-01-26 23:29:08 +01:00
}
static void init(void)
{
2018-05-01 19:15:56 +02:00
if ((game.isComplete && rand() % 3 > 0) || game.plus != PLUS_NONE)
{
self->alive = ALIVE_DEAD;
}
}
2018-01-26 23:29:08 +01:00
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++;
2018-02-13 22:36:42 +01:00
game.stats[STAT_HEARTS_FOUND]++;
2018-01-26 23:29:08 +01:00
world.bob->health = world.bob->healthMax = game.hearts;
2018-04-01 18:41:45 +02:00
setGameplayMessage(MSG_OBJECTIVE, app.strings[ST_HEART]);
2018-01-26 23:29:08 +01:00
2018-02-25 18:29:44 +01:00
playSound(SND_HEART_CELL, self->uniqueId % MAX_SND_CHANNELS);
2018-01-26 23:29:08 +01:00
self->alive = ALIVE_DEAD;
updateHeartCellObjective();
2018-01-26 23:29:08 +01:00
}
}