Allow cycling of targets.
This commit is contained in:
parent
0125cd0765
commit
666a88e669
|
@ -131,7 +131,7 @@ void doPlayer(void)
|
||||||
{
|
{
|
||||||
selectTarget();
|
selectTarget();
|
||||||
|
|
||||||
app.keyboard[SDLK_t] = 0;
|
app.keyboard[SDL_SCANCODE_T] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (app.keyboard[SDL_SCANCODE_SPACE] && battle.boostTimer == BOOST_RECHARGE_TIME)
|
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 closest = MAX_TARGET_RANGE;
|
||||||
unsigned int dist = 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)
|
for (e = battle.entityHead.next ; e != NULL ; e = e->next)
|
||||||
{
|
{
|
||||||
|
@ -311,10 +314,42 @@ static void selectTarget(void)
|
||||||
dist = getDistance(self->x, self->y, e->x, e->y);
|
dist = getDistance(self->x, self->y, e->x, e->y);
|
||||||
if (dist < closest)
|
if (dist < closest)
|
||||||
{
|
{
|
||||||
player->target = e;
|
near = e;
|
||||||
closest = dist;
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
#include "../structs.h"
|
#include "../structs.h"
|
||||||
|
|
||||||
#define MAX_SELECTABLE_PLAYERS 8
|
#define MAX_SELECTABLE_PLAYERS 8
|
||||||
|
#define MAX_SELECTABLE_TARGETS 8
|
||||||
|
|
||||||
extern void fireGuns(Entity *owner);
|
extern void fireGuns(Entity *owner);
|
||||||
extern void fireMissile(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 int mod(int n, int x);
|
||||||
extern void playSound(int id);
|
extern void playSound(int id);
|
||||||
extern void failMission(void);
|
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 App app;
|
||||||
extern Battle battle;
|
extern Battle battle;
|
||||||
|
|
Loading…
Reference in New Issue