Hi guys heres just a little question i have while working on my most recent WIP game. Well here is the code to start off:
boolean rockD[] = { true, true, true, true, true, true, true };
int resourceWidth[] = { 64, 64, 64, 64, 64, 64, 64 };
int resourceHeight[] = { 58, 58, 58, 58, 58, 58, 58 };
float resourceTimer = 0;
public void resource(SpriteBatch apples, int x, int y, int id) {
//to see if the method should even do the below stuff
if (rockD[id]) {
apples.draw(material, levelX + x, levelY + y, resourceWidth[id],
resourceHeight[id]);
// my little distance formula....
if ((Math.sqrt((levelX + x - middleX) * (levelX + x - middleX)
+ (levelY + y - middleY) * (levelY + y - middleY)) < distanceFromMaterial)) {
font.draw(batch, "Press B to Pick up the Stone", 50, 50);
//starts making the image of the "resource" smaller as b is held down
if (Gdx.input.isKeyPressed(Keys.B)) {
// amountOfStone += 4;
// rockD[id] = false;
resourceTimer += Gdx.graphics.getDeltaTime();
if (resourceTimer > 1 && resourceTimer < 2) {
resourceWidth[id] = (int) (64 * .8);
resourceHeight[id] = (int) (58 * .8);
}
if (resourceTimer > 2 && resourceTimer < 3) {
resourceWidth[id] = (int) (64 * .6);
resourceHeight[id] = (int) (58 * .6);
}
if (resourceTimer > 3 && resourceTimer < 4) {
resourceWidth[id] = (int) (64 * .4);
resourceHeight[id] = (int) (58 * .4);
}
if (resourceTimer > 4 && resourceTimer < 5) {
resourceWidth[id] = (int) (64 * .2);
resourceHeight[id] = (int) (58 * .2);
}
if (resourceTimer > 5) {
amountOfStone += 1;
resourceTimer = 0;
rockD[id] = false;
}
//if b is depressed then reset values to defaults
} else {
resourceTimer = 0;
resourceWidth[id] = 64;
resourceHeight[id] = 58;
}
}
}
}
Ok, just to explain this all I use a distance formula to detect if the character is within range to pick it up, then as you hold b to pick it up the “resource” gets smaller. I know this code may need to be further organized possibly into some type of MVC, but I will use it for now. So here is my question; how can I call this method without requiring all these booleans / int’s ? This is what it looks like calling this method
//resource(SpriteBatch, xPos,yPos, ID)
resource(batch, 800, 800, 0);
resource(batch, 1200, 1200, 1);
resource(batch, 800, 1200, 2);
resource(batch, 1200, 800, 3);
resource(batch, 500, 1000, 4);
Does this code have to have all of these different objects? (I call them id’s in the method). There seems like theres no way to make unlimted objects without defining more booleans / int’s… I feel like there may be something silly that I am overlooking or possibly something lacking in my java education. Well I appreciate any suggestions here guys, thanks in advanced