jestanoff
Re:JavaScript Code Plays Google Dinosaur/T-Rex Game Automatically
on Saturday August 15, 2020 @05:32AM (#24167455)
May be it is something small as dividing the width by 2 and setting a lower milliseconds value for the setinterval so it runs the checks more often.
Essentially this is the same solution as in the post, just stripped down to the bare minimum of code, but I haven't tested it enough. There must be some edge case that it fails on
Re:JavaScript Code Plays Google Dinosaur/T-Rex Game Automatically
on Friday August 14, 2020 @06:54PM (#24164225)
I don't like the length of their solution, quite the same logic can be shortened to just a few lines of code
setInterval(() => {
const { currentSpeed, horizon: { obstacles: [{ xPos, width, yPos } = {}] } } = Runner?.instance_;
if (xPos < 25 * currentSpeed - width && yPos >= 75)
document.dispatchEvent(new KeyboardEvent('keydown', { keyCode: 32 }));
}, 100);