[Add] Planets in minimap - Never lose the planet again!!

[Add] NPC's in minimap have different colors based on faction.
This commit is contained in:
Allanis 2013-02-06 23:49:22 +00:00
parent f06270d589
commit 27fa5d774f
2 changed files with 96 additions and 25 deletions

View File

@ -39,6 +39,7 @@ extern int pilots;
// Weapon stuff for GUI.
extern void weapon_minimap(double res, double w, double h);
extern void planets_minimap(double res, double w, double h);
// GUI crap.
// Need these offsets to render properly. -- Used in opengl.c
@ -46,11 +47,15 @@ extern void weapon_minimap(double res, double w, double h);
typedef struct {
double r, g, b, a;
} Color;
#define COLOR(x) (x).r, (x).g, (x).b, (x).a
#define COLOR(x) glColor4d((x).r, (x).g, (x).b, (x).a)
// Factions.
Color cRadar_player = { .r = 0.4, .g = 0.8, .b = 0.9, .a = 1. };
Color cRadar_neut = { .r = 0.8, .g = 0.8, .b = 0.8, .a = 1. };
Color cRadar_inert = { .r = 0.6, .g = 0.6, .b = 0.6, .a = 1. };
Color cRadar_neut = { .r = 0.9, .g = 1.0, .b = 0.3, .a = 1. };
Color cRadar_friend = { .r = 0.0, .g = 1.0, .b = 0.0, .a = 1. };
Color cRadar_targ = { .r = 0.0, .g = 0.7, .b = 1.0, .a = 1. };
Color cRadar_weap = { .r = 0.8, .g = 0.2, .b = 0.2, .a = 1. };
// Bars.
Color cShield = { .r = 0.2, .g = 0.2, .b = 0.8, .a = 1. };
Color cArmor = { .r = 0.5, .g = 0.5, .b = 0.5, .a = 1. };
Color cEnergy = { .r = 0.2, .g = 0.8, .b = 0.2, .a = 1. };
@ -126,22 +131,15 @@ void player_render(void) {
glTranslated(VX(gui.pos_radar) - gl_screen.w/2. + gui.radar.w/2.,
VY(gui.pos_radar) - gl_screen.h/2. - gui.radar.h/2., 0.);
glBegin(GL_POINTS);
// Player.
glColor4d(COLOR(cRadar_player));
glVertex2d( 0., 2. );
glVertex2d( 0., 1. );
glVertex2d( 0., 0. );
glVertex2d( 0., -1. );
glVertex2d( 0., -2. );
glVertex2d( 2., 0. );
glVertex2d( 1., 0. );
glVertex2d( -1., 0. );
glVertex2d( -2., 0. );
switch(gui.radar.shape) {
case RADAR_RECT:
glColor4d(COLOR(cRadar_weap));
// Planets.
COLOR(cRadar_friend);
planets_minimap(gui.radar.res, gui.radar.w, gui.radar.h);
// Weapons.
glBegin(GL_POINTS);
COLOR(cRadar_weap);
weapon_minimap(gui.radar.res, gui.radar.w, gui.radar.h);
glEnd(); // Put end to those points.
for(i = 1; i < pilots; i++) {
@ -158,7 +156,9 @@ void player_render(void) {
continue; // Pilot isn't in range.
glBegin(GL_QUADS);
glColor4d(COLOR(cRadar_neut));
// Colors.
if(p->id == player_target) COLOR(cRadar_targ);
else COLOR(cRadar_neut);
glVertex2d(MAX(x-sx, -gui.radar.w/2.), MIN(y+sx, gui.radar.w/2.)); // top left.
glVertex2d(MIN(x+sx, gui.radar.w/2.), MIN(y+sy, gui.radar.h/2.)); // Top right.
glVertex2d(MIN(x+sx, gui.radar.w/2.), MAX(y-sy, -gui.radar.h/2.)); // Bottom right.
@ -166,20 +166,34 @@ void player_render(void) {
glEnd(); // The Quads.
}
case RADAR_CIRCLE:
glBegin(GL_POINTS);
for(i = 1; i < pilots; i++) {
p = pilot_stack[i];
glColor4d(COLOR(cRadar_neut));
COLOR(cRadar_neut);
glVertex2d((p->solid->pos.x - player->solid->pos.x) / gui.radar.res,
(p->solid->pos.y - player->solid->pos.y) / gui.radar.res);
}
glEnd();
break;
}
// Player. -- Drawn last.
COLOR(cRadar_player);
glVertex2d( 0., 2. ); // We represent the player with a small '+'
glVertex2d( 0., 1. );
glVertex2d( 0., 0. );
glVertex2d( 0., -1. );
glVertex2d( 0., -2. );
glVertex2d( 2., 0. );
glVertex2d( 1., 0. );
glVertex2d( -1., 0. );
glVertex2d( -2., 0. );
glEnd();
glPopMatrix(); // GL_PROJECTION.
// Health.
glBegin(GL_QUADS); // Shield.
glColor4d(COLOR(cShield));
COLOR(cShield);
x = VX(gui.pos_shield) - gl_screen.w/2.;
y = VY(gui.pos_shield) - gl_screen.h/2.;
sx = player->shield / player->shield_max * gui.shield.w;
@ -191,7 +205,7 @@ void player_render(void) {
glEnd();
glBegin(GL_QUADS); // Armor.
glColor4d(COLOR(cArmor));
COLOR(cArmor);
x = VX(gui.pos_armor) - gl_screen.w/2.;
y = VY(gui.pos_armor) - gl_screen.h/2.;
sx = player->armor / player->armor_max * gui.armor.w;
@ -203,7 +217,7 @@ void player_render(void) {
glEnd();
glBegin(GL_QUADS); // Energy.
glColor4d(COLOR(cEnergy));
COLOR(cEnergy);
x = VX(gui.pos_energy) - gl_screen.w/2.;
y = VY(gui.pos_energy) - gl_screen.h/2.;
sx = player->energy / player->energy_max * gui.energy.w;

View File

@ -94,6 +94,63 @@ static int nstars = 0; // Total stars.
static Planet* planet_get(const char* name);
static StarSystem* system_parse(const xmlNodePtr parent);
// Draw the planet. Used in planet.c
#define PIXEL(x,y) if(ABS(x)<w/2. && ABS(y)<h/2.) glVertex2i((x),(y))
void planets_minimap(double res, double w, double h) {
int i;
int cx, cy, x, y, r;
double p;
glBegin(GL_POINTS);
glMatrixMode(GL_PROJECTION);
for(i = 0; i < cur_system->nplanets; i++) {
r = (int)(cur_system->planets[i].gfx_space->sw / res);
cx = (int)((cur_system->planets[i].pos.x - player->solid->pos.x) / res);
cy = (int)((cur_system->planets[i].pos.y - player->solid->pos.y) / res);
x = 0;
y = r;
p = (5. - (double)(r*3)) / 4.;
PIXEL(cx, cy+y);
PIXEL(cx, cy-y);
PIXEL(cx+y, cy);
PIXEL(cx-y, cy);
while(x < y) {
x++;
if(p < 0) p += 2*(double)(x)+1;
else p += 2*(double)(x-(--y))+1;
if(x == 0) {
PIXEL(cx, cy+y);
PIXEL(cx, cy-y);
PIXEL(cx+y, cy);
PIXEL(cx-y, cy);
} else
if(x == y) {
PIXEL(cx+x, cy+y);
PIXEL(cx-x, cy+y);
PIXEL(cx+x, cy-y);
PIXEL(cx-x, cy-y);
} else
if(x < y) {
PIXEL(cx+x, cy+y);
PIXEL(cx-x, cy+y);
PIXEL(cx+x, cy-y);
PIXEL(cx-x, cy-y);
PIXEL(cx+y, cy+x);
PIXEL(cx-y, cy+x);
PIXEL(cx+y, cy-x);
PIXEL(cx-y, cy-x);
}
}
}
if(ABS(x) < w/2. && ABS(y) < h/2.) {}
glEnd();
}
#undef PIXEL
// Init the system.
void space_init(const char* sysname) {
int i;