I am working on this game where i want to select a boat with my left mouse button and to control it after i selected it. But i cant seem to find anything about this and i have no idea where to start. Is there someone who can help me?
private boolean state = false;
public void act()
{
//locationGetting();
checkMargins();
checkEdges();
boatSelector();
}
public void boatSelector()
{
if(Greenfoot.mouseClicked(this)){
this.state = true;
if (this.state == true){
boatMovement();
}
else{
}
}
}if (state == false)
{
if (Greenfoot.mousePressed(this))
{
state = true;
}
}
else if (state == true)
{
boatMovement();
}
private boolean state = false;
public void act()
{
//locationGetting();
checkMargins();
checkEdges();
boatSelector();
if (state == true)
{
boatMovement();
}
}
public void boatSelector()
{
if (Greenfoot.mouseClicked(this)) {
if (state == false) //if the object is not yet selected, select the object
{
state = true;
} else { //if you click on the object if it is selected (state=true) it will set the state to false, thus deselecting the object
state = false;
}
}
}
private boolean state = false;
public void boatSelect()
{
if (state == false)
{
if (Greenfoot.mouseClicked(this))
{
state = true;
}
}
else if (state == true)
{
setImage(new GreenfootImage("boat1Sel.png"));
boatMovement();
boatDeselect();
//getWorld().addObject(icon1, getX(), getY());
}
}
public void boatDeselect()
{
if (this.state)
{
if (Greenfoot.mouseClicked(this))
{
state = false;
setImage(new GreenfootImage("boat02-f.png"));
return;
//getWorld().removeObject(icon1);
}
}
}