├── LICENSE ├── README.md ├── src ├── trex-runner-bot.js ├── trex-runner-bot.min.js ├── trex-runner-break-rule.js ├── trex-runner-break-rule.min.js ├── trex-runner-score-hacking.js └── trex-runner-score-hacking.min.js └── standalone ├── index.html ├── package.json └── t-rex.js /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Uku Pattak 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Chrome Offline page "T-Rex Runner" game bot 2 | 3 |  4 | 5 | **Are you tired of failing like this?** Try using this bot to show off to Your friends what "mad skills" you have in T-Rex Runner game. 6 | 7 | ## Try it out 8 | 9 | 1. Copy the minified source code, 10 | 2. disconnect from the Internet, 11 | 3. paste the code to the Chrome Dev tools Console and 12 | 4. let the T-Rex run! 13 | 14 | ```javascript 15 | function TrexRunnerBot(){function n(){if(Runner&&Runner().horizon.obstacles[0]){var n=Runner().horizon.obstacles[0];e(n)&&o(n)&&r(n)}}function e(n){return 50!==n.yPos}function o(n){return n.xPos<=18*Runner().currentSpeed}function r(n){u(n)?t():c(n)}function u(n){return 75===n.yPos}function t(){Runner().onKeyDown(R),setTimeout(function(){Runner().onKeyUp(R)},500)}function c(n){i(n)?f():Runner().onKeyDown(s)}function i(n){var e=Runner().horizon.obstacles[1];return e&&e.xPos-n.xPos<=42*Runner().currentSpeed}function f(){Runner().onKeyDown(s),Runner().onKeyUp(s)}var s={keyCode:38},R={keyCode:40,preventDefault:function(){}};return{conquerTheGame:n}}var bot=TrexRunnerBot(),botInterval=setInterval(bot.conquerTheGame,2); 16 | ``` 17 | 18 | ## License 19 | 20 | [MIT](//github.com/ukupat/trex-runner-bot/blob/master/LICENSE) 21 | -------------------------------------------------------------------------------- /src/trex-runner-bot.js: -------------------------------------------------------------------------------- 1 | function TrexRunnerBot() { 2 | 3 | const makeKeyArgs = (keyCode) => { 4 | const preventDefault = () => void 0; 5 | return {keyCode, preventDefault}; 6 | }; 7 | 8 | const upKeyArgs = makeKeyArgs(38); 9 | const downKeyArgs = makeKeyArgs(40); 10 | const startArgs = makeKeyArgs(32); 11 | 12 | if (!Runner().playing) { 13 | Runner().onKeyDown(startArgs); 14 | setTimeout(() => { 15 | Runner().onKeyUp(startArgs); 16 | }, 500); 17 | } 18 | 19 | function conquerTheGame() { 20 | if (!Runner || !Runner().horizon.obstacles[0]) return; 21 | 22 | const obstacle = Runner().horizon.obstacles[0]; 23 | 24 | if (obstacle.typeConfig && obstacle.typeConfig.type === 'SNACK') return; 25 | 26 | if (needsToTackle(obstacle) && closeEnoughToTackle(obstacle)) tackle(obstacle); 27 | } 28 | 29 | function needsToTackle(obstacle) { 30 | return obstacle.yPos !== 50; 31 | } 32 | 33 | function closeEnoughToTackle(obstacle) { 34 | return obstacle.xPos <= Runner().currentSpeed * 18; 35 | } 36 | 37 | function tackle(obstacle) { 38 | if (isDuckable(obstacle)) { 39 | duck(); 40 | } else { 41 | jumpOver(obstacle); 42 | } 43 | } 44 | 45 | function isDuckable(obstacle) { 46 | return obstacle.yPos === 50; 47 | } 48 | 49 | function duck() { 50 | Runner().onKeyDown(downKeyArgs); 51 | 52 | setTimeout(() => { 53 | Runner().onKeyUp(downKeyArgs); 54 | }, 500); 55 | } 56 | 57 | function jumpOver(obstacle) { 58 | if (isNextObstacleCloseTo(obstacle)) 59 | jumpFast(); 60 | else 61 | Runner().onKeyDown(upKeyArgs); 62 | } 63 | 64 | function isNextObstacleCloseTo(currentObstacle) { 65 | const nextObstacle = Runner().horizon.obstacles[1]; 66 | 67 | return nextObstacle && nextObstacle.xPos - currentObstacle.xPos <= Runner().currentSpeed * 42; 68 | } 69 | 70 | function jumpFast() { 71 | Runner().onKeyDown(upKeyArgs); 72 | Runner().onKeyUp(upKeyArgs); 73 | } 74 | 75 | return {conquerTheGame: conquerTheGame}; 76 | } 77 | 78 | let bot = TrexRunnerBot(); 79 | let botInterval = setInterval(bot.conquerTheGame, 2); 80 | -------------------------------------------------------------------------------- /src/trex-runner-bot.min.js: -------------------------------------------------------------------------------- 1 | function TrexRunnerBot(){function f(){Runner().onKeyDown(d);setTimeout(function(){Runner().onKeyUp(d)},500)}var b=function(a){return{keyCode:a,preventDefault:function(){}}},c=b(38),d=b(40),e=b(32);Runner().playing||(Runner().onKeyDown(e),setTimeout(function(){Runner().onKeyUp(e)},500));return{conquerTheGame:function(){if(Runner&&Runner().horizon.obstacles[0]){var a=Runner().horizon.obstacles[0];if((!a.typeConfig||"SNACK"!==a.typeConfig.type)&&50!==a.yPos&&a.xPos<=18*Runner().currentSpeed)if(50=== a.yPos)f();else{var b=Runner().horizon.obstacles[1];if(b&&b.xPos-a.xPos<=42*Runner().currentSpeed)Runner().onKeyDown(c),Runner().onKeyUp(c);else Runner().onKeyDown(c)}}}}}var bot=TrexRunnerBot(),botInterval=setInterval(bot.conquerTheGame,2); -------------------------------------------------------------------------------- /src/trex-runner-break-rule.js: -------------------------------------------------------------------------------- 1 | Runner.instance_.gameOver = () => {}; 2 | -------------------------------------------------------------------------------- /src/trex-runner-break-rule.min.js: -------------------------------------------------------------------------------- 1 | Runner.instance_.gameOver=function(){}; -------------------------------------------------------------------------------- /src/trex-runner-score-hacking.js: -------------------------------------------------------------------------------- 1 | let hackScore = 0; 2 | 3 | Object.defineProperty(Runner.instance_, 'distanceRan', { 4 | get: () => hackScore, 5 | set: (value) => hackScore = value + Math.floor(Math.random() * 1000), 6 | configurable: true, 7 | enumerable: true, 8 | }); -------------------------------------------------------------------------------- /src/trex-runner-score-hacking.min.js: -------------------------------------------------------------------------------- 1 | var hackScore=0;Object.defineProperty(Runner.instance_,"distanceRan",{get:function(){return hackScore},set:function(a){return hackScore=a+Math.floor(1E3*Math.random())},configurable:!0,enumerable:!0}); 2 | -------------------------------------------------------------------------------- /standalone/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 | 5 | 6 | 7 |i?i:t}else A&&(this.currentSpeed=A)},init:function(){this.adjustDimensions(),this.setSpeed(),this.containerEl=document.createElement("div"),this.containerEl.className=t.classes.CONTAINER,this.canvas=e(this.containerEl,this.dimensions.WIDTH,this.dimensions.HEIGHT,t.classes.PLAYER),this.canvasCtx=this.canvas.getContext("2d"),this.canvasCtx.fillStyle="#f7f7f7",this.canvasCtx.fill(),t.updateCanvasScaling(this.canvas),this.horizon=new I(this.canvas,this.spriteDef,this.dimensions,this.config.GAP_COEFFICIENT),this.tRex=new c(this.canvas,this.spriteDef.TREX),this.outerContainerEl.appendChild(this.containerEl),this.outerContainerEl.style.background="transparent",this.update(),window.addEventListener(t.events.RESIZE,this.debounceResize.bind(this))},debounceResize:function(){this.resizeTimerId_||(this.resizeTimerId_=setInterval(this.adjustDimensions.bind(this),250))},adjustDimensions:function(){clearInterval(this.resizeTimerId_),this.resizeTimerId_=null;var A=window.getComputedStyle(this.outerContainerEl),i=Number(A.paddingLeft.substr(0,A.paddingLeft.length-2));this.dimensions.WIDTH=this.outerContainerEl.offsetWidth-2*i,this.canvas&&(this.canvas.width=this.dimensions.WIDTH,this.canvas.height=this.dimensions.HEIGHT,t.updateCanvasScaling(this.canvas),this.clearCanvas(),this.horizon.update(0,0,!0),this.tRex.update(0),this.activated||this.paused?(this.containerEl.style.width=this.dimensions.WIDTH+"px",this.containerEl.style.height=this.dimensions.HEIGHT+"px",this.stop()):this.tRex.draw(0,0))},playIntro:function(){if(!this.started){this.playingIntro=!0,this.tRex.playingIntro=!0;var A="@-webkit-keyframes intro { from { width:"+c.config.WIDTH+"px }to { width: "+this.dimensions.WIDTH+"px }}";document.styleSheets[0].insertRule(A,0),this.containerEl.addEventListener(t.events.ANIM_END,this.startGame.bind(this)),this.containerEl.style.webkitAnimation="intro .4s ease-out 1 both",this.containerEl.style.width=this.dimensions.WIDTH+"px",this.activated=!0,this.started=!0}},startGame:function(){this.runningTime=0,this.playingIntro=!1,this.tRex.playingIntro=!1,this.containerEl.style.webkitAnimation="",this.playCount++,document.addEventListener(t.events.VISIBILITY,this.onVisibilityChange.bind(this)),window.addEventListener(t.events.BLUR,this.onVisibilityChange.bind(this)),window.addEventListener(t.events.FOCUS,this.onVisibilityChange.bind(this))},clearCanvas:function(){this.canvasCtx.clearRect(0,0,this.dimensions.WIDTH,this.dimensions.HEIGHT)},update:function(){this.drawPending=!1;var A=o(),i=A-(this.time||A);if(this.time=A,this.activated){this.clearCanvas(),this.tRex.jumping&&this.tRex.updateJump(i),this.runningTime+=i;var s=this.runningTime>this.config.CLEAR_TIME;if(1!=this.tRex.jumpCount||this.playingIntro||this.playIntro(),this.playingIntro?this.horizon.update(0,this.currentSpeed,s):(i=this.started?i:0,this.horizon.update(i,this.currentSpeed,s,this.inverted)),s){var e=h(this.horizon.obstacles[0],this.tRex);switch(e){case t.actions.JUMP:this.doJump();break;case t.actions.SUPER_JUMP:this.doJump(!0);break;case t.actions.DUCK:this.doDuck();break;case t.actions.DAZE:this.distanceRan+=this.currentSpeed*i/this.msPerFrame,this.currentSpeed