is there a way to randomise a plus or Minus character? I have a program where a sprite moves across the screen and when you click it, it reappears in a different place. I also want the direction it moves to be randomized as well. At the moment I can only set it to moving left to right +, or Right to left -.
private int x = random.nextInt(150);
private int y = random.nextInt(500);
private int xSpeed = random.nextInt(10);//Horizontal increment of position (speed)
private int ySpeed = random.nextInt(10);// Vertical increment of position (speed)
public void update() {
x = x +- xSpeed;
y = y +- ySpeed;
}
Aucun commentaire:
Enregistrer un commentaire