[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");
|
||||
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.
|
||||
|
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,
|
||||
0, "txtDPilot", &gl_smallFont, &cDConsole,
|
||||
"Pilot:\n"
|
||||
"Combat Rating:\n");
|
||||
"Combat\n"
|
||||
" Rating:"
|
||||
"\n"
|
||||
"Ship:\n");
|
||||
|
||||
snprintf(str, 128,
|
||||
"%s\n"
|
||||
"\n"
|
||||
"%s\n"
|
||||
"\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,
|
||||
0, "txtPilot", &gl_smallFont, &cBlack, str);
|
||||
|
||||
|
77
src/player.c
77
src/player.c
@ -29,18 +29,21 @@
|
||||
|
||||
// Player stuff.
|
||||
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.
|
||||
char* player_name = NULL; // Player name.
|
||||
int player_credits = 0; // Ze monies.
|
||||
int combat_crating = 0; // Ze rating.
|
||||
char* player_name = NULL; // Player name.
|
||||
int player_credits = 0; // Ze monies.
|
||||
int combat_crating = 0; // Ze rating.
|
||||
unsigned int player_flags = 0; // Player flags.
|
||||
// Input.c
|
||||
double player_turn = 0.; // Turn velocity from input.
|
||||
double player_acc = 0.; // Accel velocity from input.
|
||||
double player_turn = 0.; // Turn velocity from input.
|
||||
double player_acc = 0.; // Accel velocity from input.
|
||||
unsigned int player_target = PLAYER_ID; // Targetted pilot.
|
||||
// Internal
|
||||
int planet_target = -1; // Targetted planet.
|
||||
int hyperspace_target = -1; // Target hyperspace route.
|
||||
int planet_target = -1; // Targetted planet.
|
||||
int hyperspace_target = -1; // Target hyperspace route.
|
||||
// For death etc.
|
||||
static unsigned int player_timer = 0;
|
||||
static Vec2 player_cam;
|
||||
@ -117,6 +120,8 @@ extern void planets_minimap(const double res,
|
||||
// Internal.
|
||||
static void player_nameClose(char* str);
|
||||
static void player_newMake(void);
|
||||
static void player_nameShipClose(char* str);
|
||||
static void player_newShipMake(char* name);
|
||||
static void rect_parse(const xmlNodePtr parent,
|
||||
double* x, double* y, double* w, double* h);
|
||||
static int gui_parse(const xmlNodePtr parent, const char* name);
|
||||
@ -131,6 +136,8 @@ void player_new(void) {
|
||||
unsigned int wid;
|
||||
|
||||
player_setFlag(PLAYER_DESTROYED);
|
||||
vectnull(&player_cam);
|
||||
gl_bindCamera(&player_cam);
|
||||
|
||||
wid = window_create("Player Name", -1, -1, 240, 140);
|
||||
|
||||
@ -209,9 +216,6 @@ static void player_newMake(void) {
|
||||
free(buf);
|
||||
xmlCleanupParser();
|
||||
|
||||
// In case we are respawning.
|
||||
player_rmFlag(PLAYER_DESTROYED);
|
||||
|
||||
// Money.
|
||||
player_credits = RNG(l, h);
|
||||
|
||||
@ -220,21 +224,60 @@ static void player_newMake(void) {
|
||||
player_message("v%d.%d.%d", VMAJOR, VMINOR, VREV);
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
// Position and direction.
|
||||
player_warp(x, y);
|
||||
player->solid->dir = RNG(0, 359) / 180.*M_PI;
|
||||
// Create a dialogue to name the new ship.
|
||||
void player_newShip(Ship* ship, double px, double py,
|
||||
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.
|
||||
void player_newShip(Ship* ship) {
|
||||
static void player_newShipMake(char* name) {
|
||||
Vec2 vp, vv;
|
||||
if(player)
|
||||
pilot_destroy(player);
|
||||
|
||||
pilot_create(ship, "Player", faction_get("Player"), NULL,
|
||||
0., NULL, NULL, PILOT_PLAYER);
|
||||
// In case we're respawning.
|
||||
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.
|
||||
}
|
||||
|
@ -29,7 +29,8 @@ typedef enum RadarShape_ { RADAR_RECT, RADAR_CIRCLE } RadarShape; // For render
|
||||
|
||||
// Creation.
|
||||
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.
|
||||
int gui_init(void);
|
||||
|
Loading…
Reference in New Issue
Block a user