Created
May 4, 2015 21:47
-
-
Save boppreh/6273606f3fdc5fe07c47 to your computer and use it in GitHub Desktop.
Allow keyboard control in agar.io
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
var oldOnKeyDown = window.onkeydown | |
var canvas = document.getElementById('canvas'); | |
var oldMouseMove = canvas.onmousemove | |
canvas.onmousemove = null; | |
var pressedKeys = {} | |
window.onkeydown = function (f) { | |
pressedKeys[f.keyCode] = 1; | |
oldOnKeyDown(f); | |
updateKey(); | |
}; | |
window.onkeyup = function (f) { | |
pressedKeys[f.keyCode] = 0; | |
updateKey(); | |
}; | |
function updateKey() { | |
var maxX = window.innerWidth; | |
var maxY = window.innerHeight; | |
var dx = 0; | |
var dy = 0; | |
if (pressedKeys[37]) { | |
dx = -1; | |
} | |
if (pressedKeys[38]) { | |
dy = -1; | |
} | |
if (pressedKeys[39]) { | |
dx = 1; | |
} | |
if (pressedKeys[40]) { | |
dy = 1; | |
} | |
var x, y; | |
if (dx == -1) { | |
x = 0; | |
} else if (dx == 1) { | |
x = maxX; | |
} else if (dx === 0) { | |
x = maxX / 2; | |
} | |
if (dy == -1) { | |
y = 0; | |
} else if (dy == 1) { | |
y = maxY; | |
} else if (dy === 0) { | |
y = maxY / 2; | |
} | |
oldMouseMove({clientX: x, clientY: y}); | |
} |
How do I use this? XD
@BogdanGlisici It's mean to pasted on the console. But you really, really should not do that unless you fully understand the code you're pasting. It's the javascript equivalent of letting someone in your house (or website account, in this case).
Ok, thanks for the clarification
…On Sat, 19 Feb 2022, 00:17 BoppreH, ***@***.***> wrote:
***@***.**** commented on this gist.
------------------------------
@BogdanGlisici <https://github.com/BogdanGlisici> It's mean to pasted on
the console. But you really, really should not do that unless you fully
understand the code you're pasting. It's the javascript equivalent of
letting someone in your house (or website account, in this case).
—
Reply to this email directly, view it on GitHub
<https://gist.github.com/6273606f3fdc5fe07c47#gistcomment-4070754>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AVM5WKVIC3LXCLVGZZQLZ7LU33AOPANCNFSM5OYV57TA>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
You are receiving this because you were mentioned.Message ID:
***@***.***>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How do I use this?
Edit: nvm I found it