Eh… Some Odd Choices.

If this was for a code size competition, I'm a bit surprised you would "let" on every joe-blasted line instead of comma delimiting. It's also curious you waste code for "onload" on things that would/should be just as easily be set when the script runs.

Likewise I'd think the slow backtick formatted strings would be a bad idea for a game, where thanks to JS being a sluggart you need to optimize out every inefficiency. I know they're hot, trendy, and new, but they're also quite often a horribly bad choice for game coding.

But what do I know? I say the same about the pointless trash let/const BS... though it's interesting your first few LET look like what should be immutables, but you used LET on them even though you used the naming convention for what in real languages would be DEFINE.

It's also curious the amount of stuff you're setting from the scripting in ways that would slow things down, that would/should probably be set from an actual stylesheet.

You've also got a LOT of "else for nothing" logic in there for things that could be handled by a simple modulo. For example:

Bad enough the painfully cryptic and wasteful arrow function/const rubbish, but even the logic is silly.

What do I mean silly? Guessing a bit wildly, but…

Is probably all you needed there. Yes, that's a single = inside the conditional, and it leverages loose typecasting.

You’re getting an array involved without using it for pre-calculation is also a bit of a wonk, more so when it's not zero indexed. Given how painfully slow JavaScript's PRETEND Arrays are (they're actually pointered lists under the hood) I'm not quite sure why you'd even have that array in the first place.

Rather than that animationLoop array, I'd have a spriteImageWidth and spriteImageInc variables in place.

Modulo (or binary AND) are your friend when working with stuff like this.

Also a great place to leverage objects. Too many globals, too hard to re-use.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store