diff --git a/dat/ship.xml b/dat/ship.xml index 43748a4..909d47c 100644 --- a/dat/ship.xml +++ b/dat/ship.xml @@ -1,7 +1,7 @@ - ship.png + ship 1 400 @@ -27,7 +27,7 @@ - ship1.png + ship1 1 180 diff --git a/gfx/gui/pilot.png b/gfx/gui/pilot.png new file mode 100644 index 0000000..c501d3b Binary files /dev/null and b/gfx/gui/pilot.png differ diff --git a/gfx/gui/planet.png b/gfx/gui/planet.png new file mode 100644 index 0000000..e2b41d3 Binary files /dev/null and b/gfx/gui/planet.png differ diff --git a/gfx/ship/ship1_target.png b/gfx/ship/ship1_target.png new file mode 100644 index 0000000..a5ee5aa Binary files /dev/null and b/gfx/ship/ship1_target.png differ diff --git a/gfx/ship/ship1_target.xcf b/gfx/ship/ship1_target.xcf new file mode 100644 index 0000000..892ccd3 Binary files /dev/null and b/gfx/ship/ship1_target.xcf differ diff --git a/gfx/ship/ship_target.png b/gfx/ship/ship_target.png new file mode 100644 index 0000000..c6fd42f Binary files /dev/null and b/gfx/ship/ship_target.png differ diff --git a/gfx/ship/ship_target.xcf b/gfx/ship/ship_target.xcf new file mode 100644 index 0000000..6082179 Binary files /dev/null and b/gfx/ship/ship_target.xcf differ diff --git a/src/main.c b/src/main.c index c986b83..410666f 100644 --- a/src/main.c +++ b/src/main.c @@ -26,6 +26,8 @@ #define CONF_FILE "conf" #define MINIMUM_FPS 0.5 +#define FONT_SIZE 10 + extern const char* keybindNames[]; // Keybindings. static int quit = 0; // Primary loop. @@ -80,6 +82,7 @@ int main(int argc, char** argv) { input_setKeybind("left", KEYBIND_KEYBOARD, SDLK_a, 0); input_setKeybind("right", KEYBIND_KEYBOARD, SDLK_d, 0); input_setKeybind("primary", KEYBIND_KEYBOARD, SDLK_SPACE, 0); + input_setKeybind("target", KEYBIND_KEYBOARD, SDLK_TAB, 0); input_setKeybind("mapzoomin", KEYBIND_KEYBOARD, SDLK_UP, 0); input_setKeybind("mapzoomout", KEYBIND_KEYBOARD, SDLK_DOWN, 0); @@ -237,7 +240,7 @@ int main(int argc, char** argv) { if(ai_init()) WARN("Error initializing AI"); - gl_fontInit(NULL, NULL, 16); + gl_fontInit(NULL, NULL, FONT_SIZE); // Init default font size. gui_init(); // Init the GUI crap. // Data loading. diff --git a/src/pilot.c b/src/pilot.c index 1266f33..8c77aff 100644 --- a/src/pilot.c +++ b/src/pilot.c @@ -25,6 +25,17 @@ static void pilot_update(Pilot* pilot, const double dt); void pilot_render(Pilot* pilot); static void pilot_free(Pilot* p); +// Get the next pilot based on player_id. +unsigned int pilot_getNext(unsigned int id) { + int i, n; + for(i = 0, n = pilots/2; n > 0; n /= 2) + i += (pilot_stack[i+n]->id > id) ? 0 : n; + + if(i == pilots-1) return 0; + + return pilot_stack[i+1]->id; +} + // Pull a pilot out of the pilot_stack based on id. Pilot* get_pilot(unsigned int id) { // Regular search. diff --git a/src/pilot.h b/src/pilot.h index 84e34ac..e86e388 100644 --- a/src/pilot.h +++ b/src/pilot.h @@ -7,6 +7,7 @@ // Aproximation for pilot size. #define PILOT_SIZE_APROX 0.8 +#define PILOT_DISABLED 0.2 // Based on armor percentage. // Creation flags. #define PILOT_PLAYER 1 // Pilot is a player. @@ -46,6 +47,7 @@ typedef struct Pilot { // Grabing pilot crap. extern Pilot* player; // The player. Pilot* get_pilot(unsigned int id); +unsigned int pilot_getNext(unsigned int id); // MISC. void pilot_shoot(Pilot* p, int secondary); diff --git a/src/player.c b/src/player.c index a5d954d..3b6b79d 100644 --- a/src/player.c +++ b/src/player.c @@ -7,6 +7,10 @@ #define POW2(x) ((x)*(x)) +#define GFX_GUI_FRAME "../gfx/gui/frame.png" +#define GFX_GUI_TARG_PILOT "../gfx/gui/pilot.png" +#define GFX_GUI_TARG_PLANET "../gfx/gui/planet.png" + #define KEY_PRESS 1. #define KEY_RELEASE -1. @@ -19,7 +23,7 @@ typedef struct { } Keybind; static Keybind** player_input; // Contains the players keybindings. // Name of each keybinding. -const char* keybindNames[] = { "accel", "left", "right", "primary", +const char* keybindNames[] = { "accel", "left", "right", "primary", "target", "mapzoomin", "mapzoomout" }; // Player stuff. @@ -27,6 +31,7 @@ Pilot* player = NULL; // extern in pilot.h static double player_turn = 0.; // Turn velocity from input. static double player_acc = 0.; // Accel velocity from input. static int player_primary = 0; // Player is shooting primary weapon. +static unsigned int player_target = 0; // Targetted pilot. // Pilot stuff for GUI. extern Pilot** pilot_stack; @@ -62,6 +67,7 @@ typedef struct { #define RADAR_RES_MAX 100. #define RADAR_RES_MIN 10. #define RADAR_RES_INTERVAL 10. +#define RADAR_RES_DEFAULT 40. typedef struct { double w,h; @@ -70,12 +76,14 @@ typedef struct { typedef struct { // graphics. gl_texture* gfx_frame; + gl_texture* gfx_targetPilot, *gfx_targetPlanet; Radar radar; Rect shield, armor, energy; // Positions. Vec2 pos_frame; Vec2 pos_radar; Vec2 pos_shield, pos_armor, pos_energy; + Vec2 pos_target, pos_target_health; } GUI; GUI gui; // Le Gui! @@ -87,6 +95,26 @@ extern void pilot_render(Pilot* pilot); // Extern is in Pilot.* // Render the player. void player_render(void) { + int i; + double x, y, sx, sy; + Pilot* p; + Vec2 v; + + if(player_target) { + p = get_pilot(player_target); + + vect_csetmin(&v, VX(p->solid->pos) - p->ship->gfx_space->sw * PILOT_SIZE_APROX/2., + VY(p->solid->pos) + p->ship->gfx_space->sh * PILOT_SIZE_APROX/2.); + gl_blitSprite(gui.gfx_targetPilot, &v, 0, 0); + VX(v) += p->ship->gfx_space->sw * PILOT_SIZE_APROX; + gl_blitSprite(gui.gfx_targetPilot, &v, 1, 0); + VY(v) -= p->ship->gfx_space->sh * PILOT_SIZE_APROX; + gl_blitSprite(gui.gfx_targetPilot, &v, 1, 1); + VX(v) -= p->ship->gfx_space->sw * PILOT_SIZE_APROX; + gl_blitSprite(gui.gfx_targetPilot, &v, 0, 1); + } + + // Render the player. pilot_render(player); // GUI! @@ -111,9 +139,6 @@ void player_render(void) { glVertex2d( -1., 0. ); glVertex2d( -2., 0. ); - int i; - double x, y, sx, sy; - Pilot* p; switch(gui.radar.shape) { case RADAR_RECT: glColor4d(COLOR(cRadar_weap)); @@ -188,19 +213,36 @@ void player_render(void) { glVertex2d(x+sx, y-sy); glVertex2d(x, y-sy); glEnd(); + + // Target. + if(player_target) { + gl_blitStatic(p->ship->gfx_target, &gui.pos_target); + if(p->armor < p->armor_max * PILOT_DISABLED) + // Disable the pilot. + gl_print(NULL, &gui.pos_target_health, "Disabled"); + else if(p->shield > p->shield_max / 100.) + // On shields. + gl_print(NULL, &gui.pos_target_health, "%s: %.0f%%", "Shield", p->shield/p->shield_max*100.); + else + // On armor. + gl_print(NULL, &gui.pos_target_health, "%s: %.0f%%", "Armor", p->armor/p->armor_max*100.); + } } // Init GUI. int gui_init(void) { -// -- Frame. - gui.gfx_frame = gl_newImage("../gfx/gui/frame.png"); + // -- Targeting. + gui.gfx_targetPilot = gl_newSprite(GFX_GUI_TARG_PILOT, 2, 2); + gui.gfx_targetPlanet = gl_newSprite(GFX_GUI_TARG_PLANET, 2, 2); + // -- Frame. + gui.gfx_frame = gl_newImage(GFX_GUI_FRAME); vect_csetmin(&gui.pos_frame, gl_screen.w - gui.gfx_frame->w, // x. gl_screen.h - gui.gfx_frame->h); // y. gui_xoff = -gui.gfx_frame->w/2.; // Offset is only horizontal and on the right side. -// -- Radar. - gui.radar.res = 10.; + // -- Radar. + gui.radar.res = RADAR_RES_DEFAULT; gui.radar.w = 128.; gui.radar.h = 128.; gui.radar.shape = RADAR_RECT; //RADAR_CIRCLE; @@ -208,7 +250,7 @@ int gui_init(void) { VX(gui.pos_frame) + 11, // x VY(gui.pos_frame) + gui.gfx_frame->h - 10); // y. -// -- Bars. + // -- Bars. gui.shield.w = gui.armor.w = gui.energy.w = 128; gui.shield.h = gui.armor.h = gui.energy.h = 10; vect_csetmin(&gui.pos_shield, @@ -223,6 +265,16 @@ int gui_init(void) { VX(gui.pos_frame) + 10, // x VY(gui.pos_frame) + gui.gfx_frame->h - 236); // y. + // Target. + vect_csetmin(&gui.pos_target, + VX(gui.pos_frame) + 10, + VY(gui.pos_frame) + gui.gfx_frame->h - 256 - SHIP_TARGET_H); + + vect_csetmin(&gui.pos_target_health, + VX(gui.pos_frame) + 10 + 10, + VY(gui.pos_frame) + gui.gfx_frame->h - 256 - SHIP_TARGET_H + 10); + + return 0; } @@ -305,9 +357,12 @@ static void input_key(int keynum, double value, int abs) { } // Shoot primary weapon. BOOM BOOM. else if(strcmp(player_input[keynum]->name, "primary")==0) { - if(value==KEY_PRESS) player_primary = 1; + if(value == KEY_PRESS) player_primary = 1; else if(value == KEY_RELEASE) player_primary = 0; } + else if(strcmp(player_input[keynum]->name, "target")==0) { + if(value == KEY_PRESS) player_target = pilot_getNext(player_target); + } else if(strcmp(player_input[keynum]->name, "mapzoomin")==0) { if(value == KEY_PRESS && gui.radar.res < RADAR_RES_MAX) gui.radar.res += RADAR_RES_INTERVAL; diff --git a/src/ship.c b/src/ship.c index 0ec4df9..da6d260 100644 --- a/src/ship.c +++ b/src/ship.c @@ -12,8 +12,10 @@ #define XML_ID "Ships" // XML section identifier. #define XML_SHIP "ship" -#define SHIP_DATA "../dat/ship.xml" -#define SHIP_GFX "../gfx/ship/" +#define SHIP_DATA "../dat/ship.xml" +#define SHIP_GFX "../gfx/ship/" +#define SHIP_EXT ".png" +#define SHIP_TARGET "_target" static Ship* ship_stack = NULL; static int ships = 0; @@ -47,9 +49,14 @@ static Ship* ship_parse(xmlNodePtr parent) { while((node = node->next)) { // Load all the data. if(strcmp((char*)node->name, "GFX")==0) { - snprintf(str, strlen((char*)node->children->content)+sizeof(SHIP_GFX), - SHIP_GFX"%s", (char*)node->children->content); + snprintf(str, strlen((char*)node->children->content)+sizeof(SHIP_GFX)+sizeof(SHIP_EXT), + SHIP_GFX"%s"SHIP_EXT, (char*)node->children->content); tmp->gfx_space = gl_newSprite(str, 6, 6); + // Target. + snprintf(str, strlen((char*)node->children->content)+sizeof(SHIP_GFX)+sizeof(SHIP_TARGET)+sizeof(SHIP_EXT), + SHIP_GFX"%s"SHIP_TARGET SHIP_EXT, (char*)node->children->content); + tmp->gfx_target = gl_newImage(str); + } else if(strcmp((char*)node->name, "class")==0) tmp->class = atoi((char*)node->children->content); @@ -192,6 +199,7 @@ void ships_free(void) { free(sot); } gl_freeTexture((ship_stack+i)->gfx_space); + gl_freeTexture((ship_stack+i)->gfx_target); } free(ship_stack); ship_stack = NULL; diff --git a/src/ship.h b/src/ship.h index 3ed5037..3c6cdb1 100644 --- a/src/ship.h +++ b/src/ship.h @@ -3,6 +3,10 @@ #include "outfit.h" #include "opengl.h" +// Target gfx dimensions. +#define SHIP_TARGET_W 128 +#define SHIP_TARGET_H 96 + enum ship_class { SHIP_CLASS_NULL, SHIP_CLASS_CIV_LIGHT, diff --git a/src/space.c b/src/space.c index 5c79e0f..2b1d64c 100644 --- a/src/space.c +++ b/src/space.c @@ -154,7 +154,7 @@ static Planet* planet_get(const char* name) { if(strcmp((char*)cur->name, "text")==0) { snprintf(str, strlen((char*)cur->content)+sizeof(PLANET_GFX), PLANET_GFX"%s", (char*)cur->content); - tmp->gfx_space = gl_newSprite(str, 1, 1); + tmp->gfx_space = gl_newImage(str); } } else if(strcmp((char*)node->name, "pos")==0) {