blobwarsAttrition/src/entities/entities.c

217 lines
3.6 KiB
C
Raw Normal View History

2018-01-25 08:41:10 +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 "entities.h"
void animateEntity(void);
static void applyDamage(int damage);
static float bounce(float x);
static SDL_Rect *getBounds(void);
Entity *createEntity(int type)
2018-01-25 08:41:10 +01:00
{
Entity *e;
switch (type)
{
case ET_BOB:
e = malloc(sizeof(Bob));
memset(e, 0, sizeof(Bob));
break;
case ET_ENEMY:
case ET_TEEKA:
e = malloc(sizeof(Unit));
memset(e, 0, sizeof(Unit));
break;
case ET_BOSS:
e = malloc(sizeof(Boss));
memset(e, 0, sizeof(Boss));
break;
case ET_HEART_CELL:
case ET_KEY:
case ET_ITEM:
case ET_CONSUMABLE:
e = malloc(sizeof(Item));
memset(e, 0, sizeof(Item));
break;
case ET_MIA:
e = malloc(sizeof(MIA));
memset(e, 0, sizeof(MIA));
break;
case ET_DECORATION:
e = malloc(sizeof(Decoration));
memset(e, 0, sizeof(Decoration));
break;
case ET_DOOR:
case ET_LIFT:
case ET_PUSHBLOCK:
case ET_DESTRUCTABLE:
case ET_POWER_POINT:
case ET_CARD_READER:
case ET_PRESSURE_PLATE:
case ET_TELEPORTER:
case ET_ITEM_PAD:
case ET_POOL:
case ET_TRAP:
case ET_EXIT:
case ET_INFO_POINT:
e = malloc(sizeof(Structure));
memset(e, 0, sizeof(Structure));
break;
}
2018-01-25 08:41:10 +01:00
world.entityTail->next = e;
world.entityTail = e;
e->type = type;
2018-01-29 09:34:39 +01:00
e->uniqueId = world.entityCounter++;
2018-01-25 08:41:10 +01:00
return e;
}
void initEntity(Entity *e)
{
e->sprite[0] = e->sprite[1] = e->sprite[2] = -1;
e->environment = ENV_AIR;
e->alive = ALIVE_ALIVE;
e->isOnGround = 0;
e->isSolid = 0;
e->isStatic = 0;
e->isMissionTarget = 0;
e->health = 1;
2018-01-25 08:41:10 +01:00
e->facing = FACING_LEFT;
e->flags = 0;
e->thinkTime = 0;
e->animate = animateEntity;
e->applyDamage = applyDamage;
e->bounce = bounce;
e->getBounds = getBounds;
2018-01-25 08:41:10 +01:00
}
static SDL_Rect *getBounds(void)
2018-01-25 08:41:10 +01:00
{
self->bounds.x = self->x;
self->bounds.y = self->y;
self->bounds.w = self->w;
self->bounds.h = self->h;
2018-01-25 08:41:10 +01:00
return &self->bounds;
2018-01-25 08:41:10 +01:00
}
int getCurrentEntitySprite(EntityExt *e)
2018-01-25 08:41:10 +01:00
{
if (e->alive == ALIVE_ALIVE)
{
return e->sprite[e->facing];
}
return e->sprite[FACING_DIE];
}
void animateEntity(void)
2018-01-25 08:41:10 +01:00
{
}
void setEntitySize(Entity *e)
{
}
static float bounce(float x)
2018-01-25 08:41:10 +01:00
{
if (!(self->flags & EF_BOUNCES))
2018-01-25 08:41:10 +01:00
{
return 0;
}
else if (self->flags & EF_FRICTIONLESS)
2018-01-25 08:41:10 +01:00
{
return -x;
}
x = -x * FRICTION;
if (x > -1 && x < 1)
{
self->flags &= ~EF_BOUNCES;
2018-01-25 08:41:10 +01:00
x = 0;
}
return x;
}
void teleport(Entity *e, float tx, float ty)
{
e->tx = tx;
e->ty = ty;
e->flags |= EF_TELEPORTING;
addTeleportStars(e);
}
void activateEntities(char *names, int activate)
{
}
2018-01-27 12:55:15 +01:00
void teleportEntity(Entity *e, float tx, float ty)
{
}
static void applyDamage(int damage)
2018-01-25 08:41:10 +01:00
{
}
void dropCarriedItem(void)
{
EntityExt *e;
Item *i;
e = (EntityExt*)self;
if (e->carriedItem != NULL)
2018-01-25 08:41:10 +01:00
{
i = e->carriedItem;
i->x = (e->x + e->w / 2) - i->w / 2;
i->y = e->y;
2018-01-25 08:41:10 +01:00
i->dx = i->dy = 0;
2018-01-25 08:41:10 +01:00
world.entityTail->next = (Entity*)i;
world.entityTail = (Entity*)i;
world.entityTail->next = NULL;
e->carriedItem = NULL;
2018-01-25 08:41:10 +01:00
}
}