Added w and h variables for to entity and bullet, for use with grid and colliison detection.

This commit is contained in:
Steve 2015-11-02 07:57:33 +00:00
parent 7a6a6b26c0
commit f667137521
3 changed files with 9 additions and 9 deletions

View File

@ -48,6 +48,8 @@ void initBulletDefs(void)
def->texture = getTexture(cJSON_GetObjectItem(node, "textureName")->valuestring);
def->sound = lookup(cJSON_GetObjectItem(node, "sound")->valuestring);
def->flags = flagsToLong(cJSON_GetObjectItem(node, "flags")->valuestring);
SDL_QueryTexture(def->texture, NULL, NULL, &def->w, &def->h);
}
cJSON_Delete(root);
@ -92,17 +94,12 @@ void doBullets(void)
static void checkCollisions(Bullet *b)
{
Entity *f;
int bw, bh, ew, eh;
SDL_QueryTexture(b->texture, NULL, NULL, &bw, &bh);
for (f = battle.entityHead.next ; f != NULL ; f = f->next)
{
if (f->active && f->type == ET_FIGHTER)
{
SDL_QueryTexture(f->texture, NULL, NULL, &ew, &eh);
if (b->owner != f && f->health > 0 && collision(b->x - bw / 2, b->y - bh / 2, bw, bh, f->x - ew / 2, f->y - eh / 2, ew, eh))
if (b->owner != f && f->health > 0 && collision(b->x - b->w / 2, b->y - b->h / 2, b->w, b->h, f->x - f->w / 2, f->y - f->h / 2, f->w, f->h))
{
if (b->owner->side == f->side)
{

View File

@ -65,7 +65,7 @@ static void loadFighterDef(char *filename)
cJSON *root, *node;
char *text;
Entity *f;
int i, w, h;
int i;
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, "Loading %s", filename);
@ -89,6 +89,8 @@ static void loadFighterDef(char *filename)
f->shieldRechargeRate = cJSON_GetObjectItem(root, "shieldRechargeRate")->valueint;
f->texture = getTexture(cJSON_GetObjectItem(root, "textureName")->valuestring);
SDL_QueryTexture(f->texture, NULL, NULL, &f->w, &f->h);
if (cJSON_GetObjectItem(root, "guns"))
{
i = 0;
@ -124,8 +126,7 @@ static void loadFighterDef(char *filename)
f->missiles.ammo = f->missiles.maxAmmo = cJSON_GetObjectItem(node, "ammo")->valueint;
}
SDL_QueryTexture(f->texture, NULL, NULL, &w, &h);
f->separationRadius = MAX(w, h);
f->separationRadius = MAX(f->w, f->h);
f->separationRadius *= 2;
/* all craft default to 100 system power */

View File

@ -119,6 +119,8 @@ struct Bullet {
int type;
float x;
float y;
int w;
int h;
float dx;
float dy;
int sound;