fp: Only allow one keyboard player, allocate remainder to gamepads
This commit is contained in:
parent
943bea72f1
commit
1c82071686
@ -109,16 +109,22 @@ static bool FP_ListenForNewPlayer(TELY_PlatformInput *input, FP_Game *game)
|
||||
if (game->play.players.size == 2)
|
||||
return result;
|
||||
|
||||
FP_GamePlay *play = &game->play;
|
||||
uint32_t gamepad_index = 0;
|
||||
FP_GamePlay *play = &game->play;
|
||||
bool keyboard_already_allocated = false;
|
||||
uint32_t gamepad_index = 0;
|
||||
if (play->players.size) {
|
||||
FP_GameEntityHandle first_player_handle = play->players.data[0];
|
||||
FP_GameEntity *player = FP_Game_GetEntity(game, first_player_handle);
|
||||
if (player->controls.mode == FP_GameControlMode_Gamepad)
|
||||
if (player->controls.mode == FP_GameControlMode_Gamepad) {
|
||||
gamepad_index = 1;
|
||||
} else {
|
||||
// NOTE: We only allow one player to use the keyboard, everyone
|
||||
// else must use a gamepad.
|
||||
keyboard_already_allocated = true;
|
||||
}
|
||||
}
|
||||
|
||||
bool keyboard_pressed = TELY_Platform_InputScanCodeIsPressed(input, TELY_PlatformInputScanCode_B);
|
||||
bool keyboard_pressed = !keyboard_already_allocated && TELY_Platform_InputScanCodeIsPressed(input, TELY_PlatformInputScanCode_B);
|
||||
bool gamepad_pressed = TELY_Platform_InputGamepadKeyIsPressed(input, gamepad_index, TELY_PlatformInputGamepadKey_Start);
|
||||
|
||||
if (keyboard_pressed || gamepad_pressed) {
|
||||
@ -136,39 +142,23 @@ static bool FP_ListenForNewPlayer(TELY_PlatformInput *input, FP_Game *game)
|
||||
FP_GameEntity *terry = FP_Game_GetEntity(game, terry_handle);
|
||||
FP_GameControls *controls = &terry->controls;
|
||||
if (keyboard_pressed) {
|
||||
controls->mode = FP_GameControlMode_Keyboard;
|
||||
if (play->players.size == 1) {
|
||||
controls->up.scan_code = TELY_PlatformInputScanCode_W;
|
||||
controls->down.scan_code = TELY_PlatformInputScanCode_S;
|
||||
controls->left.scan_code = TELY_PlatformInputScanCode_A;
|
||||
controls->right.scan_code = TELY_PlatformInputScanCode_D;
|
||||
controls->attack.scan_code = TELY_PlatformInputScanCode_G;
|
||||
controls->range_attack.scan_code = TELY_PlatformInputScanCode_H;
|
||||
controls->build_mode.scan_code = TELY_PlatformInputScanCode_F;
|
||||
controls->strafe.scan_code = TELY_PlatformInputScanCode_J;
|
||||
controls->dash.scan_code = TELY_PlatformInputScanCode_V;
|
||||
controls->buy_building.scan_code = TELY_PlatformInputScanCode_T;
|
||||
controls->buy_upgrade.scan_code = TELY_PlatformInputScanCode_Y;
|
||||
controls->move_building_ui_cursor_left.scan_code = TELY_PlatformInputScanCode_Q;
|
||||
controls->move_building_ui_cursor_right.scan_code = TELY_PlatformInputScanCode_E;
|
||||
} else {
|
||||
controls->up.scan_code = TELY_PlatformInputScanCode_O;
|
||||
controls->down.scan_code = TELY_PlatformInputScanCode_L;
|
||||
controls->left.scan_code = TELY_PlatformInputScanCode_K;
|
||||
controls->right.scan_code = TELY_PlatformInputScanCode_Semicolon;
|
||||
controls->attack.scan_code = TELY_PlatformInputScanCode_Right;
|
||||
controls->range_attack.scan_code = TELY_PlatformInputScanCode_Left;
|
||||
controls->build_mode.scan_code = TELY_PlatformInputScanCode_Up;
|
||||
controls->strafe.scan_code = TELY_PlatformInputScanCode_N;
|
||||
controls->dash.scan_code = TELY_PlatformInputScanCode_Down;
|
||||
controls->buy_building.scan_code = TELY_PlatformInputScanCode_Backslash;
|
||||
controls->buy_upgrade.scan_code = TELY_PlatformInputScanCode_Apostrophe;
|
||||
controls->move_building_ui_cursor_left.scan_code = TELY_PlatformInputScanCode_I;
|
||||
controls->move_building_ui_cursor_right.scan_code = TELY_PlatformInputScanCode_P;
|
||||
}
|
||||
controls->mode = FP_GameControlMode_Keyboard;
|
||||
controls->up.scan_code = TELY_PlatformInputScanCode_W;
|
||||
controls->down.scan_code = TELY_PlatformInputScanCode_S;
|
||||
controls->left.scan_code = TELY_PlatformInputScanCode_A;
|
||||
controls->right.scan_code = TELY_PlatformInputScanCode_D;
|
||||
controls->attack.scan_code = TELY_PlatformInputScanCode_J;
|
||||
controls->range_attack.scan_code = TELY_PlatformInputScanCode_K;
|
||||
controls->build_mode.scan_code = TELY_PlatformInputScanCode_H;
|
||||
controls->strafe.scan_code = TELY_PlatformInputScanCode_L;
|
||||
controls->dash.scan_code = TELY_PlatformInputScanCode_N;
|
||||
controls->buy_building.scan_code = TELY_PlatformInputScanCode_U;
|
||||
controls->buy_upgrade.scan_code = TELY_PlatformInputScanCode_I;
|
||||
controls->move_building_ui_cursor_left.scan_code = TELY_PlatformInputScanCode_Q;
|
||||
controls->move_building_ui_cursor_right.scan_code = TELY_PlatformInputScanCode_E;
|
||||
} else {
|
||||
controls->mode = FP_GameControlMode_Gamepad;
|
||||
controls->gamepad_index = gamepad_index;
|
||||
controls->mode = FP_GameControlMode_Gamepad;
|
||||
controls->gamepad_index = gamepad_index;
|
||||
FP_SetDefaultGamepadBindings(controls);
|
||||
}
|
||||
|
||||
@ -2831,11 +2821,16 @@ void FP_Render(FP_Game *game, TELY_Platform *platform, TELY_Renderer *renderer,
|
||||
TELY_Render_PopTransform(renderer);
|
||||
};
|
||||
|
||||
FP_GameEntity *first_player = FP_Game_GetEntity(game, game->play.players.data[0]);
|
||||
Dqn_String8 join_game_key = {};
|
||||
if (first_player->controls.mode == FP_GameControlMode_Keyboard)
|
||||
join_game_key = DQN_STRING8("<Gamepad: Start>");
|
||||
else
|
||||
join_game_key = DQN_STRING8("<Gamepad: B>");
|
||||
|
||||
Dqn_f32 font_height = TELY_Render_FontHeight(renderer, assets);
|
||||
Dqn_V2 base_p = player_avatar_base_pos[game->play.players.size];
|
||||
TELY_Render_TextF(renderer, base_p, Dqn_V2_Zero, "Press <B>"); base_p.y += font_height;
|
||||
TELY_Render_TextF(renderer, base_p, Dqn_V2_Zero, "or"); base_p.y += font_height;
|
||||
TELY_Render_TextF(renderer, base_p, Dqn_V2_Zero, "<Gamepad: Start> to join!"); base_p.y += font_height;
|
||||
TELY_Render_TextF(renderer, base_p, Dqn_V2_Zero, "Press %.*s", DQN_STRING_FMT(join_game_key)); base_p.y += font_height;
|
||||
FP_ListenForNewPlayer(input, game);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user