Bonk.io Grappling Hooks Gamemode

Adds a grappling hook ability to Bonk.io with aiming and rotation using arrow keys while holding Z, only in Grappling Hooks mode

  1. // ==UserScript==
  2. // @name Bonk.io Grappling Hooks Gamemode
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.4
  5. // @description Adds a grappling hook ability to Bonk.io with aiming and rotation using arrow keys while holding Z, only in Grappling Hooks mode
  6. // @author Your Name
  7. // @match *://bonk.io/*
  8. // @grant none
  9. // @license MIT
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. // Wait for the game to load
  16. function waitForGame() {
  17. if (typeof Game === 'undefined' || typeof Game.currentGame === 'undefined') {
  18. setTimeout(waitForGame, 1000);
  19. } else {
  20. addGrapplingHooksMode();
  21. initGrapplingHook();
  22. }
  23. }
  24.  
  25. // Add Grappling Hooks mode to the game mode selector
  26. function addGrapplingHooksMode() {
  27. const gameModeSelector = document.querySelector('#gameModeSelector'); // Adjust selector to actual game mode selector element
  28. if (gameModeSelector) {
  29. const grapplingHooksOption = document.createElement('option');
  30. grapplingHooksOption.value = 'grappling_hooks';
  31. grapplingHooksOption.textContent = 'Grappling Hooks';
  32. gameModeSelector.appendChild(grapplingHooksOption);
  33. }
  34. }
  35.  
  36. // Initialize the grappling hook functionality
  37. function initGrapplingHook() {
  38. let aiming = false;
  39. let aimAngle = 0;
  40. let rotatingLeft = false;
  41. let rotatingRight = false;
  42.  
  43. // Rotation speed in radians per frame
  44. const rotationSpeed = 0.05;
  45.  
  46. // Check if the current game mode is "Grappling Hooks"
  47. function isGrapplingHooksMode() {
  48. const modeSelector = document.querySelector('#gameModeSelector'); // Adjust selector to actual game mode selector element
  49. return modeSelector && modeSelector.value === 'grappling_hooks';
  50. }
  51.  
  52. // Event listener for keydown
  53. document.addEventListener('keydown', function(event) {
  54. if (!isGrapplingHooksMode()) return;
  55. if (event.key === 'z' || event.key === 'Z') {
  56. aiming = true;
  57. }
  58. if (aiming) {
  59. switch (event.key) {
  60. case 'ArrowLeft':
  61. rotatingLeft = true;
  62. break;
  63. case 'ArrowRight':
  64. rotatingRight = true;
  65. break;
  66. }
  67. }
  68. });
  69.  
  70. // Event listener for keyup
  71. document.addEventListener('keyup', function(event) {
  72. if (!isGrapplingHooksMode()) return;
  73. if (event.key === 'z' || event.key === 'Z') {
  74. aiming = false;
  75.  
  76. // Get the direction vector from the aim angle
  77. const nx = Math.cos(aimAngle);
  78. const ny = Math.sin(aimAngle);
  79.  
  80. // Get the player's current position
  81. const player = Game.currentGame.player;
  82.  
  83. // Grappling hook force multiplier
  84. const forceMultiplier = 2; // Adjust this value to control the force
  85.  
  86. // Apply force to the player towards the aim direction
  87. player.vel.x += nx * forceMultiplier;
  88. player.vel.y += ny * forceMultiplier;
  89. }
  90. if (aiming) {
  91. switch (event.key) {
  92. case 'ArrowLeft':
  93. rotatingLeft = false;
  94. break;
  95. case 'ArrowRight':
  96. rotatingRight = false;
  97. break;
  98. }
  99. }
  100. });
  101.  
  102. // Main game loop modification to handle rotation
  103. function gameLoop() {
  104. if (aiming) {
  105. if (rotatingLeft) {
  106. aimAngle -= rotationSpeed;
  107. }
  108. if (rotatingRight) {
  109. aimAngle += rotationSpeed;
  110. }
  111. }
  112. requestAnimationFrame(gameLoop);
  113. }
  114.  
  115. // Start the game loop
  116. requestAnimationFrame(gameLoop);
  117. }
  118.  
  119. // Start the wait for game function
  120. waitForGame();
  121. })();