Hello JGO,
How do I make an array?
Thanks in advance,
ShadowMoses
Hello JGO,
How do I make an array?
Thanks in advance,
ShadowMoses
I really don’t see the issue with creating a new object for this sort of thing. If it’s just a static thing though, you can just make an array of objects, and reset them. Something sort of like:
Spear spearArray[] = new Spear[5];
for(int i = 0; i < 5; i++){
spearArray[i] = new Spear(x,y,width,height);
}
on initializing, then on update something like this:
for(int i = 0; i < 5; i++){
if(spearArray[i].x > 0 - spearArray[i].width){
spearArray[i].x -= SPEAR_SPEED;
}else{
spearArray[i].x = screenWidth;
}
}
with a spear class that looks like this:
public class Spear{
int x, y, width, height;
Spear(int xx, int yy, int w, int h){
x = xx;
y = yy;
width = w;
height = h;
}
}
You’ll have to handle rendering and collision yourself.
Okay so do I put these in the Spear Class?
or the Render Class?
The methods there need to be wherever you render.
You have to work out the exact details yourself, if you can’t get through this simple of a thing after being given this much you probably need to work more on basics of logic and the Java language before making games. Just throwing that out there. This is all the help I can give you without me literally writing parts of the game for you at this point. (Although I already gave you a bit of code, albeit not much)