Allow cycling of targets.

This commit is contained in:
Steve 2015-11-23 10:14:28 +00:00
parent 0125cd0765
commit 666a88e669
2 changed files with 41 additions and 4 deletions

View File

@ -131,7 +131,7 @@ void doPlayer(void)
{
selectTarget();
app.keyboard[SDLK_t] = 0;
app.keyboard[SDL_SCANCODE_T] = 0;
}
if (app.keyboard[SDL_SCANCODE_SPACE] && battle.boostTimer == BOOST_RECHARGE_TIME)
@ -300,9 +300,12 @@ static void selectTarget(void)
{
unsigned int closest = MAX_TARGET_RANGE;
unsigned int dist = MAX_TARGET_RANGE;
Entity *e;
int i, total;
Entity *e, *near;
Entity *targets[MAX_SELECTABLE_TARGETS];
player->target = NULL;
i = 0;
memset(targets, 0, sizeof(Entity*) * MAX_SELECTABLE_TARGETS);
for (e = battle.entityHead.next ; e != NULL ; e = e->next)
{
@ -311,11 +314,43 @@ static void selectTarget(void)
dist = getDistance(self->x, self->y, e->x, e->y);
if (dist < closest)
{
player->target = e;
near = e;
closest = dist;
}
if (collision(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, e->x - battle.camera.x - (e->w / 2), e->y - battle.camera.y - (e->h / 2), e->w, e->h))
{
targets[i++] = e;
}
else if (e == player->target)
{
player->target = NULL;
}
}
}
total = i;
for (i = 0 ; i < total ; i++)
{
if (targets[i] == player->target)
{
if (i + 1 < MAX_SELECTABLE_TARGETS && targets[i + 1])
{
player->target = targets[i + 1];
return;
}
else
{
player->target = targets[0];
}
}
}
if (player->target == NULL || !targets[0])
{
player->target = near;
}
}
static void selectMissionTarget(void)

View File

@ -24,6 +24,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "../structs.h"
#define MAX_SELECTABLE_PLAYERS 8
#define MAX_SELECTABLE_TARGETS 8
extern void fireGuns(Entity *owner);
extern void fireMissile(Entity *owner);
@ -34,6 +35,7 @@ extern void addHudMessage(SDL_Color c, char *format, ...);
extern int mod(int n, int x);
extern void playSound(int id);
extern void failMission(void);
extern int collision(int x1, int y1, int w1, int h1, int x2, int y2, int w2, int h2);
extern App app;
extern Battle battle;