I have a task to set up a mouse dragger to move my square on a labyrinth in Java, I had set up the keys already but strugging to figure out a nice way to add the other one.
public class Player extends JPanel{
int x, y;
public Player() {
this.setBackground(Color.getHSBColor(0.3f, 0.3f, 1));
this.setSize(Maze.panelSize, Maze.panelSize);
}
public void moveLeft() {
if(x > 0 && Maze.map[x-1][y] == 1){
this.setLocation(this.getX()-25, this.getY());
x--;
}
}
public void moveRight() {
if(x < Maze.columns-1 && Maze.map[x+1][y] == 1){
this.setLocation(this.getX()+25, this.getY());
x++;
}
}
public void moveUp() {
if(y > 0 && Maze.map[x][y-1] == 1){
this.setLocation(this.getX(), this.getY()-25);
y--;
}
}
public void moveDown() {
if(y < Maze.rows-1 && Maze.map[x][y+1] == 1){
this.setLocation(this.getX(), this.getY()+25);
y++;
}
}
}