[Add] Feel free to name your ship!!
This commit is contained in:
parent
7ea7bf46a7
commit
2b8d4ecd82
@ -472,7 +472,8 @@ static void shipyard_buy(char* str) {
|
|||||||
shipname = toolkit_getList(secondary_wid, "lstShipyard");
|
shipname = toolkit_getList(secondary_wid, "lstShipyard");
|
||||||
ship = ship_get(shipname);
|
ship = ship_get(shipname);
|
||||||
|
|
||||||
player_newShip(ship);
|
player_newShip(ship, player->solid->pos.x, player->solid->pos.y,
|
||||||
|
0., 0., player->solid->dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Spaceport bar.
|
// Spaceport bar.
|
||||||
|
12
src/menu.c
12
src/menu.c
@ -141,14 +141,20 @@ void menu_info(void) {
|
|||||||
window_addText(wid, 20, 20, 120, INFO_HEIGHT-60,
|
window_addText(wid, 20, 20, 120, INFO_HEIGHT-60,
|
||||||
0, "txtDPilot", &gl_smallFont, &cDConsole,
|
0, "txtDPilot", &gl_smallFont, &cDConsole,
|
||||||
"Pilot:\n"
|
"Pilot:\n"
|
||||||
"Combat Rating:\n");
|
"Combat\n"
|
||||||
|
" Rating:"
|
||||||
|
"\n"
|
||||||
|
"Ship:\n");
|
||||||
|
|
||||||
snprintf(str, 128,
|
snprintf(str, 128,
|
||||||
"%s\n"
|
"%s\n"
|
||||||
|
"\n"
|
||||||
|
"%s\n"
|
||||||
|
"\n"
|
||||||
"%s\n",
|
"%s\n",
|
||||||
player_name, player_rating());
|
player_name, player_rating(), player->name);
|
||||||
|
|
||||||
window_addText(wid, 120, 20,
|
window_addText(wid, 80, 20,
|
||||||
INFO_WIDTH-120-BUTTON_WIDTH, INFO_HEIGHT-60,
|
INFO_WIDTH-120-BUTTON_WIDTH, INFO_HEIGHT-60,
|
||||||
0, "txtPilot", &gl_smallFont, &cBlack, str);
|
0, "txtPilot", &gl_smallFont, &cBlack, str);
|
||||||
|
|
||||||
|
63
src/player.c
63
src/player.c
@ -29,6 +29,9 @@
|
|||||||
|
|
||||||
// Player stuff.
|
// Player stuff.
|
||||||
Pilot* player = NULL; // extern in pilot.h
|
Pilot* player = NULL; // extern in pilot.h
|
||||||
|
static Ship* player_ship = NULL; // Temp ship to hold when naming it.
|
||||||
|
// More hacks.
|
||||||
|
static double player_px, player_py, player_vx, player_vy, player_dir;
|
||||||
// Player global properties.
|
// Player global properties.
|
||||||
char* player_name = NULL; // Player name.
|
char* player_name = NULL; // Player name.
|
||||||
int player_credits = 0; // Ze monies.
|
int player_credits = 0; // Ze monies.
|
||||||
@ -117,6 +120,8 @@ extern void planets_minimap(const double res,
|
|||||||
// Internal.
|
// Internal.
|
||||||
static void player_nameClose(char* str);
|
static void player_nameClose(char* str);
|
||||||
static void player_newMake(void);
|
static void player_newMake(void);
|
||||||
|
static void player_nameShipClose(char* str);
|
||||||
|
static void player_newShipMake(char* name);
|
||||||
static void rect_parse(const xmlNodePtr parent,
|
static void rect_parse(const xmlNodePtr parent,
|
||||||
double* x, double* y, double* w, double* h);
|
double* x, double* y, double* w, double* h);
|
||||||
static int gui_parse(const xmlNodePtr parent, const char* name);
|
static int gui_parse(const xmlNodePtr parent, const char* name);
|
||||||
@ -131,6 +136,8 @@ void player_new(void) {
|
|||||||
unsigned int wid;
|
unsigned int wid;
|
||||||
|
|
||||||
player_setFlag(PLAYER_DESTROYED);
|
player_setFlag(PLAYER_DESTROYED);
|
||||||
|
vectnull(&player_cam);
|
||||||
|
gl_bindCamera(&player_cam);
|
||||||
|
|
||||||
wid = window_create("Player Name", -1, -1, 240, 140);
|
wid = window_create("Player Name", -1, -1, 240, 140);
|
||||||
|
|
||||||
@ -209,9 +216,6 @@ static void player_newMake(void) {
|
|||||||
free(buf);
|
free(buf);
|
||||||
xmlCleanupParser();
|
xmlCleanupParser();
|
||||||
|
|
||||||
// In case we are respawning.
|
|
||||||
player_rmFlag(PLAYER_DESTROYED);
|
|
||||||
|
|
||||||
// Money.
|
// Money.
|
||||||
player_credits = RNG(l, h);
|
player_credits = RNG(l, h);
|
||||||
|
|
||||||
@ -220,21 +224,60 @@ static void player_newMake(void) {
|
|||||||
player_message("v%d.%d.%d", VMAJOR, VMINOR, VREV);
|
player_message("v%d.%d.%d", VMAJOR, VMINOR, VREV);
|
||||||
|
|
||||||
// Create the player and start the game.
|
// Create the player and start the game.
|
||||||
player_newShip(ship);
|
player_newShip(ship, x, y, 0., 0., RNG(0, 359)/180.*M_PI);
|
||||||
space_init(system);
|
space_init(system);
|
||||||
|
}
|
||||||
|
|
||||||
// Position and direction.
|
// Create a dialogue to name the new ship.
|
||||||
player_warp(x, y);
|
void player_newShip(Ship* ship, double px, double py,
|
||||||
player->solid->dir = RNG(0, 359) / 180.*M_PI;
|
double vx, double vy, double dir) {
|
||||||
|
|
||||||
|
unsigned int wid;
|
||||||
|
|
||||||
|
// Temp values while player doesn't exist.
|
||||||
|
player_ship = ship;
|
||||||
|
player_px = px;
|
||||||
|
player_py = py;
|
||||||
|
player_vx = vx;
|
||||||
|
player_vy = vy;
|
||||||
|
player_dir = dir;
|
||||||
|
|
||||||
|
wid = window_create("Ship Name", -1, 1, 240, 140);
|
||||||
|
|
||||||
|
window_addText(wid, 30, -30, 180, 20, 0, "txtInfo",
|
||||||
|
&gl_smallFont, &cDConsole, "Name your ship:");
|
||||||
|
window_addInput(wid, 20, -50, 200, 20, "inpName", 20, 1);
|
||||||
|
window_addButton(wid, -20, 20, 80, 30, "btnClose", "Done",
|
||||||
|
player_nameShipClose);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void player_nameShipClose(char* str) {
|
||||||
|
(void)str;
|
||||||
|
char* ship_name;
|
||||||
|
unsigned int wid;
|
||||||
|
|
||||||
|
wid = window_get("Ship Name");
|
||||||
|
ship_name = window_getInput(wid, "inpName");
|
||||||
|
|
||||||
|
player_newShipMake(ship_name);
|
||||||
|
|
||||||
|
window_destroy(wid);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Change the players ship.
|
// Change the players ship.
|
||||||
void player_newShip(Ship* ship) {
|
static void player_newShipMake(char* name) {
|
||||||
|
Vec2 vp, vv;
|
||||||
if(player)
|
if(player)
|
||||||
pilot_destroy(player);
|
pilot_destroy(player);
|
||||||
|
|
||||||
pilot_create(ship, "Player", faction_get("Player"), NULL,
|
// In case we're respawning.
|
||||||
0., NULL, NULL, PILOT_PLAYER);
|
player_rmFlag(PLAYER_DESTROYED);
|
||||||
|
|
||||||
|
vect_cset(&vp, player_px, player_py);
|
||||||
|
vect_cset(&vv, player_vx, player_vy);
|
||||||
|
|
||||||
|
pilot_create(player_ship, name, faction_get("Player"), NULL,
|
||||||
|
player_dir, &vp, &vv, PILOT_PLAYER);
|
||||||
|
|
||||||
gl_bindCamera(&player->solid->pos); // Set opengl camera.
|
gl_bindCamera(&player->solid->pos); // Set opengl camera.
|
||||||
}
|
}
|
||||||
|
@ -29,7 +29,8 @@ typedef enum RadarShape_ { RADAR_RECT, RADAR_CIRCLE } RadarShape; // For render
|
|||||||
|
|
||||||
// Creation.
|
// Creation.
|
||||||
void player_new(void);
|
void player_new(void);
|
||||||
void player_newShip(Ship* ship);
|
void player_newShip(Ship* ship, double px, double py,
|
||||||
|
double vx, double vy, double dir);
|
||||||
|
|
||||||
// Render.
|
// Render.
|
||||||
int gui_init(void);
|
int gui_init(void);
|
||||||
|
Loading…
Reference in New Issue
Block a user