Within the draw function, “key” will only have one value, even if you’re pressing multiple keys simultaneously. Meanwhile, the keyPressed() function is run once every time a key is pressed down, and the keyReleased() function is run once every time a key is released. Every time keyPressed() is run, the variable “key” will become whatever key was just pressed, and every time keyReleased() is run, the variable “key” will become whatever key was just released.
My advice is to create a set of booleans, each of which are true if and only if a particular key is currently being held down. If your controls were limited to just WASD, we’d have 4 booleans: one for w, one for a, one for s, and one for d. Since we’re also using the arrow keys, we need to have 4 more booleans, one for up, one for down, one for left, and one for right. That’s 8 booleans total.
Using the keyPressed() and keyReleased() functions, it should hopefully be fairly straightforward how to do this. If you still need help, though, I have several code fragments which I’ve used over the years for similar issues. I do recommend, however, you try to figure this one out for yourself. Part of the fun of coding is figuring things out for yourself!
Excellent work! You’re a fast learner my friend!
A few quick notes, though: firstly, unless of course you planned on having more code within the “if(wKey==true)” statement, I recommend fusing your nested if statements into a single if statement using logical AND (&&). That is, rather, than saying: