Added Shadow Mine.

This commit is contained in:
Steve 2016-04-14 11:56:42 +01:00
parent 8defda34e7
commit 9c8b7af0d6
8 changed files with 73 additions and 11 deletions

BIN
gfx/entities/shadowMine.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 588 B

View File

@ -23,29 +23,40 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
static void think(void);
static void die(void);
static void lookForFighters(void);
static void lookForPlayer(void);
static void doSplashDamage(void);
static SDL_Texture *mineWarning = NULL;
static SDL_Texture *mineNormal = NULL;
static SDL_Texture *shadowMine = NULL;
Entity *spawnMine(void)
Entity *spawnMine(int type)
{
Entity *mine = spawnEntity();
if (!mineNormal || !mineWarning)
if (!mineWarning)
{
shadowMine = getTexture("gfx/entities/shadowMine.png");
mineNormal = getTexture("gfx/entities/mine.png");
mineWarning = getTexture("gfx/entities/mineWarning.png");
}
mine->type = ET_MINE;
STRNCPY(mine->name, "Mine", MAX_NAME_LENGTH);
mine->type = type;
mine->health = mine->maxHealth = 1;
mine->speed = 1;
mine->systemPower = SYSTEM_POWER;
mine->texture = mineNormal;
mine->texture = (type == ET_MINE) ? mineNormal : shadowMine;
mine->action = think;
mine->die = die;
mine->flags = EF_TAKES_DAMAGE+EF_NO_PLAYER_TARGET;
mine->flags = EF_TAKES_DAMAGE+EF_NO_PLAYER_TARGET+EF_SHORT_RADAR_RANGE;
if (type == ET_SHADOW_MINE)
{
mine->flags &= ~EF_NO_PLAYER_TARGET;
mine->speed = 100 + rand() % 100;
mine->speed *= 0.01;
}
SDL_QueryTexture(mine->texture, NULL, NULL, &mine->w, &mine->h);
@ -54,7 +65,7 @@ Entity *spawnMine(void)
static void think(void)
{
self->texture = mineNormal;
self->texture = (self->type == ET_MINE) ? mineNormal : shadowMine;
self->angle += 0.1;
@ -66,7 +77,14 @@ static void think(void)
self->dx *= 0.99;
self->dy *= 0.99;
lookForFighters();
if (self->type == ET_MINE)
{
lookForFighters();
}
else
{
lookForPlayer();
}
if (self->systemPower < SYSTEM_POWER && battle.stats[STAT_TIME] % 8 < 4)
{
@ -101,6 +119,44 @@ static void lookForFighters(void)
self->systemPower = SYSTEM_POWER;
}
static void lookForPlayer(void)
{
float dx, dy, norm;
int distance;
if (player != NULL)
{
distance = getDistance(self->x, self->y, player->x, player->y);
if (distance < SCREEN_WIDTH)
{
dx = player->x - self->x;
dy = player->y - self->y;
norm = sqrt(dx * dx + dy * dy);
dx /= norm;
dy /= norm;
self->dx = dx * self->speed;
self->dy = dy * self->speed;
if (distance <= TRIGGER_RANGE)
{
self->systemPower--;
if (self->systemPower <= 0)
{
self->health = 0;
}
return;
}
}
}
self->systemPower = SYSTEM_POWER;
}
static void die(void)
{
@ -116,6 +172,8 @@ static void die(void)
playBattleSound(SND_EXPLOSION_5, self->x, self->y);
self->alive = ALIVE_DEAD;
updateObjective(self->name, TT_DESTROY);
}
static void doSplashDamage(void)

View File

@ -31,6 +31,7 @@ extern int getDistance(int x1, int y1, int x2, int y2);
extern void addMineExplosion(void);
extern void damageFighter(Entity *e, int amount, long flags);
extern void playBattleSound(int id, int x, int y);
extern void updateObjective(char *name, int type);
extern Battle battle;
extern Entity *player;

View File

@ -88,7 +88,7 @@ void drawRadar(void)
SDL_SetRenderDrawColor(app.renderer, 255, 255, 255, 255);
}
if (e->type == ET_MINE || e->type == ET_JUMPGATE || (e->owner && e->owner->type == ET_JUMPGATE))
if (e->type == ET_MINE || e->type == ET_SHADOW_MINE || e->type == ET_JUMPGATE || (e->owner && e->owner->type == ET_JUMPGATE))
{
SDL_SetRenderDrawColor(app.renderer, 255, 255, 255, 255);
}

View File

@ -162,7 +162,8 @@ enum
ET_COMPONENT_ENGINE,
ET_CAPITAL_SHIP,
ET_JUMPGATE,
ET_MINE
ET_MINE,
ET_SHADOW_MINE
};
enum

View File

@ -321,7 +321,8 @@ static void loadEntities(cJSON *node)
break;
case ET_MINE:
e = spawnMine();
case ET_SHADOW_MINE:
e = spawnMine(type);
break;
default:

View File

@ -58,7 +58,7 @@ extern void loadItems(cJSON *node);
extern void loadLocations(cJSON *node);
extern void loadSpawners(cJSON *node);
extern void loadChallenge(Mission *mission, cJSON *node);
extern Entity *spawnMine(void);
extern Entity *spawnMine(int type);
extern void activateNextWaypoint(void);
extern Battle battle;

View File

@ -46,6 +46,7 @@ void initLookups(void)
addLookup("ET_JUMPGATE", ET_JUMPGATE);
addLookup("ET_CAPITAL_SHIP", ET_CAPITAL_SHIP);
addLookup("ET_MINE", ET_MINE);
addLookup("ET_SHADOW_MINE", ET_SHADOW_MINE);
addLookup("EF_NO_KILL", EF_NO_KILL);
addLookup("EF_DISABLED", EF_DISABLED);