[Add] A reverse command for @KonoM as he does not know how physics works.
This commit is contained in:
parent
08f5dcc42c
commit
474d1df755
20
src/input.c
20
src/input.c
@ -20,7 +20,7 @@ static Keybind** input_keybinds; // Contains the players keybindings.
|
||||
|
||||
|
||||
// Name of each keybinding.
|
||||
const char* keybindNames[] = { "accel", "left", "right", // Movement.
|
||||
const char* keybindNames[] = { "accel", "left", "right", "reverse", // Movement.
|
||||
"primary", "target", "target_nearest", "face", "board", // Combat.
|
||||
"secondary", "secondary_next", // Secondary weapons.
|
||||
"target_planet", "land", // Navigation.
|
||||
@ -30,6 +30,8 @@ extern double player_turn;
|
||||
extern double player_acc;
|
||||
extern unsigned int player_target;
|
||||
extern int planet_target;
|
||||
// Grabbed from main.c
|
||||
extern int show_fps;
|
||||
|
||||
|
||||
// Set the default input keys.
|
||||
@ -38,6 +40,8 @@ void input_setDefault(void) {
|
||||
input_setKeybind("accel", KEYBIND_KEYBOARD, SDLK_w, 0);
|
||||
input_setKeybind("left", KEYBIND_KEYBOARD, SDLK_a, 0);
|
||||
input_setKeybind("right", KEYBIND_KEYBOARD, SDLK_d, 0);
|
||||
input_setKeybind("reverse", KEYBIND_KEYBOARD, SDLK_s, 0);
|
||||
|
||||
// Combat.
|
||||
input_setKeybind("primary", KEYBIND_KEYBOARD, SDLK_SPACE, 0);
|
||||
input_setKeybind("target", KEYBIND_KEYBOARD, SDLK_TAB, 0);
|
||||
@ -129,6 +133,16 @@ static void input_key(int keynum, double value, int abs) {
|
||||
|
||||
if(player_turn < -1.) player_turn = -1.; // Make sure value is sane.
|
||||
}
|
||||
// Turn around to face vel.
|
||||
else if(KEY("reverse")) {
|
||||
if(value == KEY_PRESS) player_setFlag(PLAYER_REVERSE);
|
||||
else if(value == KEY_RELEASE) {
|
||||
player_rmFlag(PLAYER_REVERSE);
|
||||
player_turn = 0; // Turning corrections.
|
||||
if(player_isFlag(PLAYER_TURN_LEFT)) player_turn -= 1;
|
||||
if(player_isFlag(PLAYER_TURN_RIGHT)) player_turn += 1;
|
||||
}
|
||||
}
|
||||
// Shoot primary weapon. BOOM BOOM.
|
||||
else if(KEY("primary")) {
|
||||
if(value == KEY_PRESS) player_setFlag(PLAYER_PRIMARY);
|
||||
@ -193,11 +207,11 @@ static void input_key(int keynum, double value, int abs) {
|
||||
if(value == KEY_PRESS) player_setRadarRel(-1);
|
||||
}
|
||||
// Take a screenshot.
|
||||
if(KEY("screenshot")) {
|
||||
else if(KEY("screenshot")) {
|
||||
if(value == KEY_PRESS) player_screenshot();
|
||||
}
|
||||
// Pause the game.
|
||||
if(KEY("pause")) {
|
||||
else if(KEY("pause")) {
|
||||
if(value == KEY_PRESS) {
|
||||
if(!toolkit) {
|
||||
if(paused) unpause();
|
||||
|
10
src/player.c
10
src/player.c
@ -732,13 +732,21 @@ void gui_free(void) {
|
||||
// Used in pilot.c
|
||||
// Basically uses keyboard input instead of AI input.
|
||||
void player_think(Pilot* player) {
|
||||
double diff;
|
||||
if(player_isFlag(PLAYER_FACE) && (player_target != PLAYER_ID)) {
|
||||
double diff = angle_diff(player->solid->dir,
|
||||
diff = angle_diff(player->solid->dir,
|
||||
vect_angle(&player->solid->pos, &pilot_get(player_target)->solid->pos));
|
||||
player_turn = -10.*diff;
|
||||
if(player_turn > 1.) player_turn = 1.;
|
||||
else if(player_turn < -1.) player_turn = -1.;
|
||||
}
|
||||
else if(player_isFlag(PLAYER_REVERSE)) {
|
||||
diff = angle_diff(player->solid->dir, VANGLE(player->solid->vel));
|
||||
DEBUG("%f->%f = %f", player->solid->dir, VANGLE(player->solid->vel), diff);
|
||||
player_turn = 10.*diff;
|
||||
if(player_turn >= 0.) player_turn = 1.;
|
||||
else if(player_turn < 0.) player_turn = -1;
|
||||
}
|
||||
player->solid->dir_vel = 0.;
|
||||
if(player_turn)
|
||||
player->solid->dir_vel -= player->ship->turn * player_turn;
|
||||
|
@ -4,9 +4,10 @@
|
||||
// Flag definitions.
|
||||
#define PLAYER_TURN_LEFT (1<<0) // Player is turning left.
|
||||
#define PLAYER_TURN_RIGHT (1<<1) // Player is turning right.
|
||||
#define PLAYER_FACE (1<<2) // Player is facing target.
|
||||
#define PLAYER_PRIMARY (1<<3) // Player is shooting primary weapon.
|
||||
#define PLAYER_SECONDARY (1<<4) // Player is shooting secondary weapon.
|
||||
#define PLAYER_REVERSE (1<<2)
|
||||
#define PLAYER_FACE (1<<10) // Player is facing target.
|
||||
#define PLAYER_PRIMARY (1<<11) // Player is shooting primary weapon.
|
||||
#define PLAYER_SECONDARY (1<<12) // Player is shooting secondary weapon.
|
||||
|
||||
// Flag functions.
|
||||
#define player_isFlag(f) (player_flags & f)
|
||||
|
Loading…
Reference in New Issue
Block a user