1
I’m building a game in which I want an object with given coordinates on the ground to spread, creating more pixels of himself on the ground. Each pixel of which would be represented by number 4.
Here comes the code:
public void interact(mainclass a) {
a.terrain[x][y] = 4;
Random rand = new Random();
int directionX = escolher(-1, 1);
int directionY = escolher(-1, 1);
a.terrain[x + directionX][y + directionY] = 4;
}
In class mainclass
, I have the information of the land, as well as the land itself, in the form of int[][]
.
The direction in which the given object spreads is random. The problem is that, for the function to choose, I tried to use the Random rand
to generate a random number between -1 and 1, the problem is that there is still 0, between -1 and 1.
The function escolher
does not exist, just wrote to give an example.
I mean, I can’t use the Random
. I have to find a way to choose literally between both numbers (-1 and 1).
How to do this?
Thank you. Just what I needed.
– DarkVeneno