Created
February 7, 2021 16:23
-
-
Save Asgarrrr/a8a29fcfb4ea18e399ff4034993d37e6 to your computer and use it in GitHub Desktop.
Never lose at Dino Runner
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 1. Open your browser's console | |
* 2. Turn off your internet connection (or press `⌘ + P` or `ctrl + P` and write 'Offline') | |
* 3. Paste the code in the "console" section | |
* 4. Start the game | |
* 5 🌵 🦖 | |
*/ | |
const game = Runner.instance_; | |
(function tick() { | |
if (game.crashed || game.paused) | |
return requestAnimationFrame(tick); | |
const obstacles = game.horizon.obstacles; | |
if (obstacles.length) { | |
const tRex = game.tRex | |
, tRexWidth = tRex.config.WIDTH | |
, obstacle = obstacles[0] | |
, obstacleWidth = obstacles[0].width | |
, obstacleHeight = obstacles[0].typeConfig.height | |
, gravity = game.config.GRAVITY | |
, safety = 2 * game.currentSpeed | |
, jumpHeight = obstacleHeight + safety | |
, jumpVelocityY = Math.sqrt(2 * gravity * jumpHeight) | |
, jumpAngle = 60 * Math.PI / 180 | |
, jumpVelocity = jumpVelocityY / Math.sin(jumpAngle) | |
, jumpDistance = safety + Math.pow(jumpVelocity, 2) * Math.sin(2 * jumpAngle) / gravity; | |
if (obstacle.xPos - tRex.xPos - tRexWidth <= 0.5 * (jumpDistance - obstacleWidth)) { | |
if (obstacle.yPos > 75 && !tRex.jumping ) | |
pressKey(38) && (tRex.jumpVelocity = -jumpVelocityY); | |
if (obstacle.yPos === 75 && !tRex.ducking) | |
pressKey(40); | |
} | |
} | |
requestAnimationFrame(tick); | |
}()); | |
const dispatchKeyEvent = function(eventName, keyCode) { | |
const e = new Event(eventName); | |
e.keyCode = keyCode; | |
document.dispatchEvent(e); | |
} | |
const pressKey = (keyCode) => { | |
dispatchKeyEvent('keydown', keyCode); | |
setTimeout( () => dispatchKeyEvent('keyup', keyCode), 300 ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Jumpy.mp4