Created
July 5, 2017 14:13
-
-
Save shockwaves/7ce581e2db1e74a8efb36b47ec5344f7 to your computer and use it in GitHub Desktop.
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
(function(Runner) { | |
var ctx = document.getElementsByTagName('canvas')[0].getContext('2d'); | |
var pixelEnv = ctx.getImageData(1, 1, 1, 1).data; | |
var distantion = 150; | |
Runner.instance_.play(); | |
Runner.instance_.tRex.startJump(1); | |
function getPixelData(x, y) { | |
return ctx.getImageData(x, y, 1, 1).data; | |
} | |
function isPixelsIdenty(env, read) { | |
return env[0] === read[0] && env[1] === read[1] && env[2] === read[2]; | |
} | |
function jump() { | |
Runner.instance_.tRex.startJump(1); | |
} | |
function duck() { | |
Runner.instance_.tRex.setDuck(1); | |
} | |
function run() { | |
var bottomRead = getPixelData(distantion, 110); | |
var middleRead = getPixelData(distantion, 82); | |
var isBottomBarrier = !isPixelsIdenty(pixelEnv, bottomRead); | |
var isMiddleBarrier = !isPixelsIdenty(pixelEnv, middleRead); | |
if (isBottomBarrier) { | |
jump(); | |
} else if (isMiddleBarrier) { | |
duck(); | |
} | |
// run(); | |
} | |
//window.requestAnimationFrame(run); | |
//run(); | |
setInterval(function() { | |
run(); | |
}, 1); | |
})(Runner); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment