We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I need to have many variables (x, y, x1, y1, x2, y2, etc) for the different positions of enemies and if I make a local variable at the start the other parts of the program wouldn't be able to see it because it is a local variable. How can I do that without making the variable local?
Answers
http://Forum.Processing.org/two/discussion/8082/from-several-variables-to-arrays
http://Forum.Processing.org/two/discussion/8081/from-several-arrays-to-classes
https://Docs.Oracle.com/javase/tutorial/java/concepts/index.html
Also note that the built-in
PVector
already contains an x and a y. So you could use an array or ArrayList of PVectors:Or, as @GoToLoop indicated, if you also have other variables for enemies (such as "health" or "speed" et cetera), then you could wrap these in a class:
....and then create an array or an ArrayList of your class objects:
Ah so instead of a variable I used an array and then I used a for loop to go through all the enemies in the array.