Hello I need to implement a slider bar to my game to be able to change its difficulty level. Right now my game is about a creature appearing and disapearing in a panel every second randomly. If I'm able to click on the creature when it appear I gain a point. I need to slider so the user can change the speed of the creature appearing and disapearing.
This is what i have.
public class Creature implements ActionListener{
private GamePanel gamePanel;
private int x = 250;
private int y = 250;
private ImageIcon image = new ImageIcon("creature.gif");
private boolean visible = true;
private Random random = new Random();
private Timer timer; //= new Timer(1000, this);
//private int numberOfTimeCreatureIsCaught = 0;
public Creature(GamePanel gamePanel){
this.gamePanel = gamePanel;
timer = new Timer(1000, this);
timer.start();
}
public void draw(Graphics g){
if(visible){
image.paintIcon(gamePanel, g, x, y);
}
}
public void actionPerformed(ActionEvent e){
int delay = random.nextInt(1000) + 1;
timer.setDelay(delay);
if(visible)
{
visible = false;
}
else{
visible = true;
x = random.nextInt(500 - 80);
y = random.nextInt(500 - 67);
}
gamePanel.repaint();
}
public boolean isClicked(int a, int b)
{
if(a > x + 80) return false;
if(a < x) return false;
if(b > y + 67) return false;
if(b < y) return false;
return true;
}
}
Thank you