blobwarsAttrition/src/entities/items/consumable.c

93 lines
1.7 KiB
C
Raw Normal View History

2018-01-26 20:14:18 +01:00
/*
2019-06-02 17:13:34 +02:00
Copyright (C) 2018-2019 Parallel Realities
2018-01-26 20:14:18 +01:00
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);
2018-02-06 08:29:39 +01:00
Item *initConsumable(void)
2018-01-26 20:14:18 +01:00
{
2018-02-06 08:29:39 +01:00
Item *i;
2019-06-02 17:13:34 +02:00
2018-02-06 08:29:39 +01:00
i = malloc(sizeof(Item));
memset(i, 0, sizeof(Item));
2019-06-02 17:13:34 +02:00
2018-02-06 08:29:39 +01:00
initEntity((Entity*)i);
2019-06-02 17:13:34 +02:00
2018-02-06 08:29:39 +01:00
i->type = ET_CONSUMABLE;
2019-06-02 17:13:34 +02:00
i->flags |= EF_IGNORE_BULLETS | EF_CRUSHABLE;
2018-01-26 20:14:18 +01:00
2018-02-06 08:29:39 +01:00
i->health = FPS * 10;
2018-01-26 20:14:18 +01:00
2018-02-06 08:29:39 +01:00
i->tick = tick;
i->die = die;
2019-06-02 17:13:34 +02:00
2018-02-06 08:29:39 +01:00
return i;
2018-01-26 20:14:18 +01:00
}
static void tick(void)
{
Item *i;
2019-06-02 17:13:34 +02:00
i = (Item*)self;
2019-06-02 17:13:34 +02:00
if (i->isOnGround)
2018-01-26 20:14:18 +01:00
{
i->dx *= 0.05;
2018-01-26 20:14:18 +01:00
}
i->health--;
2018-01-26 20:14:18 +01:00
if ((int) i->health == FPS * 2)
2018-01-26 20:14:18 +01:00
{
i->flags |= EF_FLICKER;
2018-01-26 20:14:18 +01:00
}
else if (i->health <= 0)
2018-01-26 20:14:18 +01:00
{
i->alive = ALIVE_DEAD;
2018-01-26 20:14:18 +01:00
}
}
int touchedPlayer(Entity *other)
{
return (other != NULL && other->type == ET_BOB && self->alive == ALIVE_ALIVE);
}
void pickupItem(void)
{
Item *i;
2019-06-02 17:13:34 +02:00
i = (Item*)self;
2019-06-02 17:13:34 +02:00
i->alive = (i->environment == ENV_AIR) ? ALIVE_DYING : ALIVE_DEAD;
i->health = FPS / 2;
i->thinkTime = 0;
i->dy = -2;
i->dx = 0;
i->flags |= EF_FLICKER | EF_WEIGHTLESS;
2018-01-26 20:14:18 +01:00
}
static void die(void)
{
/* we will handle this ourselves! */
}