We are about to switch to a new forum software. Until then we have removed the registration on this forum.
What I am trying to do is create the simplest form of a video game. I am trying to move mario left and right with the Z/X keys and Luigi with the Right/Left arrow keys. Would I use an if statement or rather do for example KeyCode?
So far my code looks like:
(mod: see comment)
Thank you so much. I have tried a few things and cannot seem to get it right.
You should start by editing your post and formatting your code for this forum properly. Hint: Select code and press Ctrl + o
(duplicate thread removed)
You can test for the left and right arrow keys using keyCode, compare it to LEFT and RIGHT. Normal keys are 'z' and 'x', of course.
I'll give this a try! Thank you!
Post your try at getting it working for more help if you need it!
Okay so I did this, but I do not think it's correct.
When Processing sees X or Z, it think it's a variable, but it doesn't know about that variable, so you get an error.
You need to compare it to the character 'z' or 'x'. A character is a single letter enclosed by single quotes.
You might also try pressing Ctrl + t to format your code's indenting. If you had indented your code properly, you might have noticed you were missing a closing brace (}).
Checking if keyPressed is true inside keyPressed() is a little redundant.
Other than that, you're very close:
I have another question for this same project.
If I am trying to make luigi flee from mario once mario get to close to him how would I do that? I am trying to make him "flee" to the right.
My code right now is: float marioX = 100; float marioY = 425; float luigiX = 400; float luigiY = 425;
DON'T FEATURE CREEP. Tell us exactly what your end goal is NOW.
DON'T START NEW THREADS ON THE SAME TOPIC. Too late. Use the other thread instead.
Someone lock this, mmk?