Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Create Event
- // Enforce singleton pattern
- if (!variable_global_exists("Input") or !instance_exists(global.Input)){
- global.Input = id;
- } else {
- if (id != global.Input){
- instance_destroy();
- exit;
- }
- }
- // Configuration
- deadzone = .2;
- menu_mode = false;
- menu_delay_amount = 10;
- // Button/Key definitions
- activateKey = vk_space;
- activateButton = gp_face1; // Xbox:A Playstation:Cross
- attackKey = vk_shift;
- attackButton = gp_face3; // Xbox:X Playstation:Square
- itemKey = vk_control;
- itemButton = gp_face4; // Xbox:Y Playstation:Triangle
- pauseKey = vk_escape;
- pauseButton = gp_start; // Xbox:Start Playstation:Options
- // unused buttons
- //unused = gp_face2; // Xbox:B Playstation:Circle
- //unused = gp_shoulderl; // Xbox:Left Bumper Playstation:L1
- //unused = gp_shoulderlb; // Xbox:Left Trigger Playstation:L2
- //unused = gp_shoulderr; // Xbox:Right Bumper Playstation:R1
- //unused = gp_shoulderrb; // Xbox:Right Trigger Playstation:R2
- //unused = gp_select; // Xbox:View Playstation:Touchpad Down
- //unused = gp_stickl; // Xbox:Left Stick Click Playstation:L3
- //unused = gp_stickr; // Xbox:Right Stick Click Playstation:R3
- // Initialization, no need to edit these, add more as needed
- gamepad_id = undefined;
- horizontal = 0; // used for left stick, dpad, arrow keys, and wasd
- vertical = 0; // used for left stick, dpad, arrow keys, and wasd
- right_horizontal = 0; // used for right stick
- right_vertical = 0; // used for right stick
- activate = 0;
- attack = 0;
- item = 0;
- pause = 0;
- // Menu initialization, no need to edit
- menu_delay_vertical = menu_delay_amount;
- menu_delay_horizontal = menu_delay_amount;
- menu_last_vertical = undefined;
- menu_last_horizontal = undefined;
- // Async System Event
- switch (async_load[? "event_type"]){
- case "gamepad discovered":
- if (gamepad_id == undefined){ // only change the id if it isn't already set
- gamepad_id = async_load[? "pad_index"];
- gamepad_set_axis_deadzone(gamepad_id, deadzone);
- }
- break;
- case "gamepad lost":
- gamepad_id = undefined;
- break;
- }
- // Begin Step Event
- // set everything to 0
- activate = 0;
- attack = 0;
- item = 0;
- pause = 0;
- horizontal = 0;
- vertical = 0;
- right_horizontal = 0;
- right_vertical = 0;
- // check gamepad
- if (gamepad_id != undefined){
- // check left stick
- horizontal = gamepad_axis_value(gamepad_id, gp_axislh);
- vertical = gamepad_axis_value(gamepad_id, gp_axislv);
- // check right stick
- right_horizontal = gamepad_axis_value(gamepad_id, gp_axisrh);
- right_vertical = gamepad_axis_value(gamepad_id, gp_axisrv);
- // read dpad if there is no left stick input
- if (horizontal == 0 and vertical == 0){
- horizontal = gamepad_button_check(gamepad_id, gp_padr) - gamepad_button_check(gamepad_id, gp_padl);
- vertical = gamepad_button_check(gamepad_id, gp_padd) - gamepad_button_check(gamepad_id, gp_padu);
- }
- // check buttons
- activate = gamepad_button_check_pressed(gamepad_id, activateButton);
- attack = gamepad_button_check_pressed(gamepad_id, attackButton);
- item = gamepad_button_check_pressed(gamepad_id, itemButton);
- pause = gamepad_button_check_pressed(gamepad_id, pauseButton);
- }
- // check keyboard if no gamepad input
- if (horizontal == 0 and vertical == 0 and right_horizontal == 0 and right_vertical == 0 and activate == 0 and attack == 0 and item == 0 and pause == 0){
- // check arrow keys and WASD
- var keyLeft = keyboard_check(vk_left) or keyboard_check(ord("A"));
- var keyRight = keyboard_check(vk_right) or keyboard_check(ord("D"));
- var keyUp = keyboard_check(vk_up) or keyboard_check(ord("W"));
- var keyDown = keyboard_check(vk_down) or keyboard_check(ord("S"));
- horizontal = keyRight - keyLeft;
- vertical = keyDown - keyUp;
- // check other keys
- activate = keyboard_check_pressed(activateKey);
- attack = keyboard_check_pressed(attackKey);
- item = keyboard_check_pressed(itemKey);
- pause = keyboard_check_pressed(pauseKey);
- }
- if (menu_mode){
- // adjust output to work better with a menu
- // vertical
- var _v_input = round(vertical); // round the input in case it is analog
- if (_v_input == menu_last_vertical){
- menu_delay_vertical--;
- vertical = 0;
- if (menu_delay_vertical <= 0){
- menu_last_vertical = undefined;
- }
- } else {
- vertical = _v_input;
- menu_last_vertical = _v_input;
- menu_delay_vertical = menu_delay_amount;
- }
- // horizontal
- var _h_input = round(horizontal); // round the input in case it is analog
- if (_h_input == menu_last_horizontal){
- menu_delay_horizontal--;
- horizontal = 0;
- if (menu_delay_horizontal <= 0){
- menu_last_horizontal = undefined;
- }
- } else {
- horizontal = _h_input;
- menu_last_horizontal = _h_input;
- menu_delay_horizontal = menu_delay_amount;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement