Use getCurrentSprite for entity sprites.
This commit is contained in:
parent
cab6d3b205
commit
d11443158d
|
@ -20,6 +20,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
|
||||||
#include "bob.h"
|
#include "bob.h"
|
||||||
|
|
||||||
|
static SDL_Rect *getCurrentSprite(void);
|
||||||
static void load(cJSON *root);
|
static void load(cJSON *root);
|
||||||
static void save(cJSON *root);
|
static void save(cJSON *root);
|
||||||
|
|
||||||
|
@ -35,6 +36,7 @@ void initBob(void)
|
||||||
u->sprite[FACING_RIGHT] = getSprite("BobRight");
|
u->sprite[FACING_RIGHT] = getSprite("BobRight");
|
||||||
u->sprite[FACING_DIE] = getSprite("BobSpin");
|
u->sprite[FACING_DIE] = getSprite("BobSpin");
|
||||||
|
|
||||||
|
u->getCurrentSprite = getCurrentSprite;
|
||||||
u->load = load;
|
u->load = load;
|
||||||
u->save = save;
|
u->save = save;
|
||||||
}
|
}
|
||||||
|
@ -49,6 +51,16 @@ int numCarriedItems(void)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static SDL_Rect *getCurrentSprite(void)
|
||||||
|
{
|
||||||
|
if (world.bob->alive == ALIVE_ALIVE && world.bob->stunTimer <= 0)
|
||||||
|
{
|
||||||
|
return &world.bob->sprite[world.bob->facing]->frames[0]->rect;
|
||||||
|
}
|
||||||
|
|
||||||
|
return &world.bob->sprite[FACING_DIE]->frames[0]->rect;
|
||||||
|
}
|
||||||
|
|
||||||
static void load(cJSON *root)
|
static void load(cJSON *root)
|
||||||
{
|
{
|
||||||
world.bob->x = cJSON_GetObjectItem(root, "x")->valueint;
|
world.bob->x = cJSON_GetObjectItem(root, "x")->valueint;
|
||||||
|
|
|
@ -24,7 +24,7 @@ static void activate(int activate);
|
||||||
static void walk(void);
|
static void walk(void);
|
||||||
static void tick(void);
|
static void tick(void);
|
||||||
static void changeEnvironment(void);
|
static void changeEnvironment(void);
|
||||||
static Sprite *getCurrentSprite(void);
|
static SDL_Rect *getCurrentSprite(void);
|
||||||
static void animate(void);
|
static void animate(void);
|
||||||
static void applyDamage(int amount);
|
static void applyDamage(int amount);
|
||||||
static void moveTowardsPlayer(void);
|
static void moveTowardsPlayer(void);
|
||||||
|
@ -171,7 +171,7 @@ static void die1(void)
|
||||||
b->action = die2;
|
b->action = die2;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Sprite *getCurrentSprite(void)
|
static SDL_Rect *getCurrentSprite(void)
|
||||||
{
|
{
|
||||||
Boss *b;
|
Boss *b;
|
||||||
|
|
||||||
|
@ -179,10 +179,10 @@ static Sprite *getCurrentSprite(void)
|
||||||
|
|
||||||
if (b->stunTimer > 0 || b->health <= 0)
|
if (b->stunTimer > 0 || b->health <= 0)
|
||||||
{
|
{
|
||||||
return b->sprite[FACING_DIE];
|
return &b->sprite[FACING_DIE]->frames[0]->rect;
|
||||||
}
|
}
|
||||||
|
|
||||||
return b->sprite[b->facing];
|
return &b->sprite[b->facing]->frames[0]->rect;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void animate(void)
|
static void animate(void)
|
||||||
|
|
|
@ -33,7 +33,7 @@ static void attackMissile(void);
|
||||||
static void preFire(void);
|
static void preFire(void);
|
||||||
static void attack(void);
|
static void attack(void);
|
||||||
static void applyDamage(int amount);
|
static void applyDamage(int amount);
|
||||||
static Sprite *getCurrentSprite(void);
|
static SDL_Rect *getCurrentSprite(void);
|
||||||
|
|
||||||
static int brakingTimer;
|
static int brakingTimer;
|
||||||
static Sprite *aimedSprite;
|
static Sprite *aimedSprite;
|
||||||
|
@ -382,12 +382,12 @@ static void die2()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static Sprite *getCurrentSprite(void)
|
static SDL_Rect *getCurrentSprite(void)
|
||||||
{
|
{
|
||||||
if (self->health <= 0)
|
if (self->health <= 0)
|
||||||
{
|
{
|
||||||
return self->sprite[FACING_DIE];
|
return &self->sprite[FACING_DIE]->frames[0]->rect;
|
||||||
}
|
}
|
||||||
|
|
||||||
return self->sprite[self->facing];
|
return &self->sprite[self->facing]->frames[0]->rect;
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,6 +28,7 @@ static void tick(void);
|
||||||
static void touch(Entity *other);
|
static void touch(Entity *other);
|
||||||
static void load(cJSON *root);
|
static void load(cJSON *root);
|
||||||
static void save(cJSON *root);
|
static void save(cJSON *root);
|
||||||
|
static SDL_Rect *getCurrentSprite(void);
|
||||||
|
|
||||||
void initEntity(Entity *e)
|
void initEntity(Entity *e)
|
||||||
{
|
{
|
||||||
|
@ -55,6 +56,7 @@ void initEntity(Entity *e)
|
||||||
e->applyDamage = applyDamage;
|
e->applyDamage = applyDamage;
|
||||||
e->bounce = bounce;
|
e->bounce = bounce;
|
||||||
e->getBounds = getBounds;
|
e->getBounds = getBounds;
|
||||||
|
e->getCurrentSprite = getCurrentSprite;
|
||||||
|
|
||||||
e->load = load;
|
e->load = load;
|
||||||
e->save = save;
|
e->save = save;
|
||||||
|
@ -134,6 +136,11 @@ static void touch(Entity *other)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static SDL_Rect *getCurrentSprite(void)
|
||||||
|
{
|
||||||
|
return &self->sprite[self->facing]->frames[0]->rect;
|
||||||
|
}
|
||||||
|
|
||||||
static void load(cJSON *root)
|
static void load(cJSON *root)
|
||||||
{
|
{
|
||||||
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_ERROR, "Entity [name=%s, type=%d, x=%d, y=%d] cannot be loaded", self->name, self->type, (int)self->x, (int)self->y);
|
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_ERROR, "Entity [name=%s, type=%d, x=%d, y=%d] cannot be loaded", self->name, self->type, (int)self->x, (int)self->y);
|
||||||
|
|
|
@ -23,6 +23,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
void unitTick(void);
|
void unitTick(void);
|
||||||
static void attack(void);
|
static void attack(void);
|
||||||
static int canFire(Entity *target);
|
static int canFire(Entity *target);
|
||||||
|
static SDL_Rect *getCurrentSprite(void);
|
||||||
static void preFire(void);
|
static void preFire(void);
|
||||||
static void load(cJSON *root);
|
static void load(cJSON *root);
|
||||||
static void save(cJSON *root);
|
static void save(cJSON *root);
|
||||||
|
@ -57,6 +58,7 @@ Unit *createUnit(void)
|
||||||
u->preFire = preFire;
|
u->preFire = preFire;
|
||||||
u->attack = attack;
|
u->attack = attack;
|
||||||
u->canFire = canFire;
|
u->canFire = canFire;
|
||||||
|
u->getCurrentSprite = getCurrentSprite;
|
||||||
u->load = load;
|
u->load = load;
|
||||||
u->save = save;
|
u->save = save;
|
||||||
|
|
||||||
|
@ -224,6 +226,16 @@ static int canFire(Entity *target)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static SDL_Rect *getCurrentSprite(void)
|
||||||
|
{
|
||||||
|
if (self->alive == ALIVE_ALIVE)
|
||||||
|
{
|
||||||
|
return &self->sprite[self->facing]->frames[0]->rect;
|
||||||
|
}
|
||||||
|
|
||||||
|
return &self->sprite[FACING_DIE]->frames[0]->rect;
|
||||||
|
}
|
||||||
|
|
||||||
static void load(cJSON *root)
|
static void load(cJSON *root)
|
||||||
{
|
{
|
||||||
Unit *u;
|
Unit *u;
|
||||||
|
|
|
@ -144,7 +144,7 @@ struct Entity {
|
||||||
void (*activate)(int active);
|
void (*activate)(int active);
|
||||||
void (*applyDamage)(int amount);
|
void (*applyDamage)(int amount);
|
||||||
void (*changeEnvironment)(void);
|
void (*changeEnvironment)(void);
|
||||||
Sprite *(*getCurrentSprite)(void);
|
SDL_Rect *(*getCurrentSprite)(void);
|
||||||
void (*load)(cJSON *root);
|
void (*load)(cJSON *root);
|
||||||
void (*save)(cJSON *root);
|
void (*save)(cJSON *root);
|
||||||
SDL_Rect *(*getBounds)(void);
|
SDL_Rect *(*getBounds)(void);
|
||||||
|
|
|
@ -29,14 +29,13 @@ void initEntities(void)
|
||||||
|
|
||||||
void drawEntities(void)
|
void drawEntities(void)
|
||||||
{
|
{
|
||||||
Entity *e;
|
|
||||||
int x, y;
|
int x, y;
|
||||||
|
|
||||||
for (e = world.entityHead.next ; e != NULL ; e = e->next)
|
for (self = world.entityHead.next ; self != NULL ; self = self->next)
|
||||||
{
|
{
|
||||||
x = (-camera.x + e->x);
|
x = (-camera.x + self->x);
|
||||||
y = (-camera.y + e->y);
|
y = (-camera.y + self->y);
|
||||||
|
|
||||||
blitRect(atlasTexture->texture, x, y, &e->sprite[0]->frames[0]->rect, 0);
|
blitRect(atlasTexture->texture, x, y, self->getCurrentSprite(), 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,5 +23,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
extern Texture *getTexture(const char *filename);
|
extern Texture *getTexture(const char *filename);
|
||||||
extern void blitRect(SDL_Texture *texture, int x, int y, SDL_Rect *srcRect, int center);
|
extern void blitRect(SDL_Texture *texture, int x, int y, SDL_Rect *srcRect, int center);
|
||||||
|
|
||||||
|
extern Entity *self;
|
||||||
extern Camera camera;
|
extern Camera camera;
|
||||||
extern World world;
|
extern World world;
|
||||||
|
|
Loading…
Reference in New Issue