Added w and h variables for to entity and bullet, for use with grid and colliison detection.
This commit is contained in:
parent
7a6a6b26c0
commit
f667137521
|
@ -48,6 +48,8 @@ void initBulletDefs(void)
|
||||||
def->texture = getTexture(cJSON_GetObjectItem(node, "textureName")->valuestring);
|
def->texture = getTexture(cJSON_GetObjectItem(node, "textureName")->valuestring);
|
||||||
def->sound = lookup(cJSON_GetObjectItem(node, "sound")->valuestring);
|
def->sound = lookup(cJSON_GetObjectItem(node, "sound")->valuestring);
|
||||||
def->flags = flagsToLong(cJSON_GetObjectItem(node, "flags")->valuestring);
|
def->flags = flagsToLong(cJSON_GetObjectItem(node, "flags")->valuestring);
|
||||||
|
|
||||||
|
SDL_QueryTexture(def->texture, NULL, NULL, &def->w, &def->h);
|
||||||
}
|
}
|
||||||
|
|
||||||
cJSON_Delete(root);
|
cJSON_Delete(root);
|
||||||
|
@ -92,17 +94,12 @@ void doBullets(void)
|
||||||
static void checkCollisions(Bullet *b)
|
static void checkCollisions(Bullet *b)
|
||||||
{
|
{
|
||||||
Entity *f;
|
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)
|
for (f = battle.entityHead.next ; f != NULL ; f = f->next)
|
||||||
{
|
{
|
||||||
if (f->active && f->type == ET_FIGHTER)
|
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 - 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 != 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->side == f->side)
|
if (b->owner->side == f->side)
|
||||||
{
|
{
|
||||||
|
|
|
@ -65,7 +65,7 @@ static void loadFighterDef(char *filename)
|
||||||
cJSON *root, *node;
|
cJSON *root, *node;
|
||||||
char *text;
|
char *text;
|
||||||
Entity *f;
|
Entity *f;
|
||||||
int i, w, h;
|
int i;
|
||||||
|
|
||||||
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, "Loading %s", filename);
|
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->shieldRechargeRate = cJSON_GetObjectItem(root, "shieldRechargeRate")->valueint;
|
||||||
f->texture = getTexture(cJSON_GetObjectItem(root, "textureName")->valuestring);
|
f->texture = getTexture(cJSON_GetObjectItem(root, "textureName")->valuestring);
|
||||||
|
|
||||||
|
SDL_QueryTexture(f->texture, NULL, NULL, &f->w, &f->h);
|
||||||
|
|
||||||
if (cJSON_GetObjectItem(root, "guns"))
|
if (cJSON_GetObjectItem(root, "guns"))
|
||||||
{
|
{
|
||||||
i = 0;
|
i = 0;
|
||||||
|
@ -124,8 +126,7 @@ static void loadFighterDef(char *filename)
|
||||||
f->missiles.ammo = f->missiles.maxAmmo = cJSON_GetObjectItem(node, "ammo")->valueint;
|
f->missiles.ammo = f->missiles.maxAmmo = cJSON_GetObjectItem(node, "ammo")->valueint;
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_QueryTexture(f->texture, NULL, NULL, &w, &h);
|
f->separationRadius = MAX(f->w, f->h);
|
||||||
f->separationRadius = MAX(w, h);
|
|
||||||
f->separationRadius *= 2;
|
f->separationRadius *= 2;
|
||||||
|
|
||||||
/* all craft default to 100 system power */
|
/* all craft default to 100 system power */
|
||||||
|
|
|
@ -119,6 +119,8 @@ struct Bullet {
|
||||||
int type;
|
int type;
|
||||||
float x;
|
float x;
|
||||||
float y;
|
float y;
|
||||||
|
int w;
|
||||||
|
int h;
|
||||||
float dx;
|
float dx;
|
||||||
float dy;
|
float dy;
|
||||||
int sound;
|
int sound;
|
||||||
|
|
Loading…
Reference in New Issue