Use offset specified in tiled for y-sorting objects
It's now no longer using the bounding box on objects anywhere, but we're going to want that soon anyway for culling off-screen entities so I decided to leave it in.
This commit is contained in:
parent
5eff48b449
commit
d1fb902e8a
34
game/main.c
34
game/main.c
@ -121,6 +121,7 @@ typedef struct {
|
||||
SDL_Rect src;
|
||||
SDL_Texture *tex;
|
||||
dbox_t bbox;
|
||||
int ysortoffset;
|
||||
} objtype_t;
|
||||
|
||||
typedef struct {
|
||||
@ -128,6 +129,7 @@ typedef struct {
|
||||
unsigned type;
|
||||
ivec_t pos;
|
||||
dbox_t bbox;
|
||||
int ysortoffset;
|
||||
} objentity_t;
|
||||
|
||||
typedef struct {
|
||||
@ -280,7 +282,7 @@ static unsigned load_objtype(
|
||||
state->objtypes[id].src.w = prop_int(node, "width");
|
||||
state->objtypes[id].src.h = prop_int(node, "height");
|
||||
|
||||
// Load bounding box from sprites document
|
||||
// Load bounding box and y-sort offset from sprites document
|
||||
const int sid = prop_int(node, "gid") - sidoff;
|
||||
xmlNodePtr snode = sprites->xmlChildrenNode;
|
||||
while (snode
|
||||
@ -299,10 +301,27 @@ static unsigned load_objtype(
|
||||
&& xmlStrcmp(snode->name, (const xmlChar *)"object") != 0)
|
||||
snode = snode->next;
|
||||
assert(snode);
|
||||
state->objtypes[id].bbox.off.x = (double)prop_int(snode, "x");
|
||||
state->objtypes[id].bbox.off.y = (double)prop_int(snode, "y");
|
||||
state->objtypes[id].bbox.ext.x = (double)prop_int(snode, "width");
|
||||
state->objtypes[id].bbox.ext.y = (double)prop_int(snode, "height");
|
||||
bool gotbb = false, gotysort = false;
|
||||
while (snode) {
|
||||
if (xmlStrcmp(snode->name, (const xmlChar *)"object") == 0) {
|
||||
if (xmlHasProp(snode, (const xmlChar *)"width")) {
|
||||
state->objtypes[id].bbox.off.x
|
||||
= (double)prop_int(snode, "x");
|
||||
state->objtypes[id].bbox.off.y
|
||||
= (double)prop_int(snode, "y");
|
||||
state->objtypes[id].bbox.ext.x
|
||||
= (double)prop_int(snode, "width");
|
||||
state->objtypes[id].bbox.ext.y
|
||||
= (double)prop_int(snode, "height");
|
||||
gotbb = true;
|
||||
} else {
|
||||
state->objtypes[id].ysortoffset = prop_int(snode, "y");
|
||||
gotysort = true;
|
||||
}
|
||||
}
|
||||
snode = snode->next;
|
||||
}
|
||||
assert(gotbb && gotysort);
|
||||
|
||||
// Load custom properties
|
||||
node = node->xmlChildrenNode;
|
||||
@ -382,8 +401,9 @@ load_objects(gamestate_t *state, xmlNodePtr node, SDL_Renderer *renderer)
|
||||
o->pos.x = prop_int(node, "x");
|
||||
o->pos.y = prop_int(node, "y") - type->src.h;
|
||||
|
||||
// Load bounding box from object type
|
||||
// Load bounding box and ysortoffset from object type
|
||||
o->bbox = type->bbox;
|
||||
o->ysortoffset = type->ysortoffset;
|
||||
} while ((node = node->next) != NULL);
|
||||
|
||||
xmlFreeDoc(spritesdoc);
|
||||
@ -630,7 +650,7 @@ static inline double dynentity_bottom(const dynentity_t *e)
|
||||
|
||||
static inline double objentity_bottom(const objentity_t *e)
|
||||
{
|
||||
return (double)e->pos.y + e->bbox.off.y + e->bbox.ext.y;
|
||||
return (double)(e->pos.y + e->ysortoffset);
|
||||
}
|
||||
|
||||
static inline double entity_bottom(entity_t *e)
|
||||
|
Loading…
x
Reference in New Issue
Block a user