diff --git a/src/defs.h b/src/defs.h index eb8f172..e99f398 100644 --- a/src/defs.h +++ b/src/defs.h @@ -81,18 +81,56 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #define MAX_WIDGET_OPTIONS 8 -#define ET_ENEMY 0 -#define ET_KEY 1 -#define ET_MIA 2 -#define ET_BOB 3 -#define ET_DESTRUCTABLE 4 -#define ET_BOSS 5 +enum +{ + ET_EFFECT, + ET_TRAP, + ET_BOB, + ET_ENEMY, + ET_TEEKA, + ET_BOSS, + ET_HEART_CELL, + ET_KEY, + ET_ITEM, + ET_CONSUMABLE, + ET_MIA, + ET_DECORATION, + ET_DOOR, + ET_LIFT, + ET_PUSHBLOCK, + ET_DESTRUCTABLE, + ET_POWER_POINT, + ET_CARD_READER, + ET_PRESSURE_PLATE, + ET_TELEPORTER, + ET_ITEM_PAD, + ET_POOL, + ET_EXIT, + ET_INFO_POINT +}; -#define EF_NONE 0 -#define EF_HEART_CELL (2 << 0) -#define EF_WEIGHTLESS (2 << 1) -#define EF_BOMB_SHIELD (2 << 2) -#define EF_IMMUNE (2 << 3) +#define EF_NONE 0 +#define EF_WEIGHTLESS (2 << 0) +#define EF_BOUNCES (2 << 1) +#define EF_TELEPORTING (2 << 2) +#define EF_NO_ENVIRONMENT (2 << 3) +#define EF_SWIMS (2 << 4) +#define EF_HALT_AT_EDGE (2 << 5) +#define EF_NO_CLIP (2 << 6) +#define EF_EXPLODES (2 << 7) +#define EF_IGNORE_BULLETS (2 << 8) +#define EF_FLICKER (2 << 9) +#define EF_FRICTIONLESS (2 << 10) +#define EF_WATER_BREATHING (2 << 11) +#define EF_IMMUNE (2 << 12) +#define EF_BOMB_SHIELD (2 << 13) +#define EF_GONE (2 << 14) +#define EF_KILL_OFFSCREEN (2 << 15) +#define EF_ALWAYS_PROCESS (2 << 16) +#define EF_NO_TELEPORT (2 << 17) + +#define GRAVITY_POWER 0.5f +#define FRICTION 0.75f enum { @@ -153,6 +191,11 @@ enum PLANE_FOREGROUND }; +enum +{ + ENV_AIR +}; + enum { PT_LINE, diff --git a/src/structs.h b/src/structs.h index 6e70c57..49c2173 100644 --- a/src/structs.h +++ b/src/structs.h @@ -84,6 +84,7 @@ typedef struct { } Delegate; struct Entity { + unsigned long uniqueId; char name[MAX_NAME_LENGTH]; int type; float x; @@ -91,9 +92,12 @@ struct Entity { int w; int h; int health; + int healthMax; int alive; float dx; float dy; + int tx; + int ty; int reload; int isOnGround; int facing; @@ -101,6 +105,11 @@ struct Entity { int weaponType; int shotsToFire; int isSolid; + int environment; + int isStatic; + int isMissionTarget; + int thinkTime; + int plane; int value; long flags; SDL_Rect bounds; @@ -219,6 +228,7 @@ typedef struct { int enemiesKilled; int missionsPlayed; long timePlayed; + unsigned long entityCounter; char worldId[MAX_NAME_LENGTH]; int isResumingMission; int isComplete; diff --git a/src/world/entities.c b/src/world/entities.c index 1202cbe..b5f265a 100644 --- a/src/world/entities.c +++ b/src/world/entities.c @@ -29,9 +29,116 @@ Entity *createEntity(void) world.entityTail->next = e; world.entityTail = e; + e->uniqueId = game.entityCounter++; + 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 = e->healthMax = 1; + + e->facing = FACING_LEFT; + + e->spriteFrame = -1; + e->spriteTime = 0; + + e->dx = e->dy = 0; + + e->flags = 0; + + e->owner = NULL; + + e->thinkTime = 0; + + e->plane = PLANE_BACKGROUND; +} + +SDL_Rect *getEntityBounds(Entity *e) +{ + e->bounds.x = e->x; + e->bounds.y = e->y; + e->bounds.w = e->w; + e->bounds.h = e->h; + + return &e->bounds; +} + +int getCurrentEntitySprite(Entity *e) +{ + return e->sprite[e->facing]; +} + +void animateEntity(Entity *e) +{ + Sprite *spr; + + if (e->spriteTime != -1) + { + e->spriteTime--; + + if (e->spriteTime <= 0) + { + spr = getSpriteByIndex(getCurrentEntitySprite(e)); + e->spriteFrame = wrap(e->spriteFrame + 1, 0, 1); + e->spriteTime = 0; + e->w = spr->w; + e->h = spr->h; + } + } +} + +void setEntitySize(Entity *e) +{ + Sprite *spr; + + spr = getSpriteByIndex(getCurrentEntitySprite(e)); + e->w = spr->w; + e->h = spr->h; +} + +float bounce(Entity *e, float x) +{ + if (!(e->flags & EF_BOUNCES)) + { + return 0; + } + else if (e->flags & EF_FRICTIONLESS) + { + return -x; + } + + x = -x * FRICTION; + + if (x > -1 && x < 1) + { + e->flags &= ~EF_BOUNCES; + 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) { } diff --git a/src/world/entities.h b/src/world/entities.h index 20cd098..8417d02 100644 --- a/src/world/entities.h +++ b/src/world/entities.h @@ -20,4 +20,9 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "../common.h" +extern Sprite *getSpriteByIndex(int x); +extern float wrap(float value, float low, float high); +extern void addTeleportStars(Entity *e); + +extern Game game; extern World world; diff --git a/src/world/objectives.c b/src/world/objectives.c index cbae88c..cc33397 100644 --- a/src/world/objectives.c +++ b/src/world/objectives.c @@ -173,7 +173,7 @@ static int isMissingHeartCell(char *targetName) { if (e->alive == ALIVE_ALIVE) { - if (e->flags & EF_HEART_CELL) + if (e->type == ET_HEART_CELL) { return 0; }