Hello everyone!
I have been busy with a game where you can control different ships on water. I can select the ships with the left mouse button, and move them with the right mouse button. By left clicking on an already selected ship deselects the ship.
But i want to make it in a way that when you select another ship, the other ship gets deselected automatically. I was thinking about a variable which can hold one ship (the selected ship), but i can't figure it out (still a beginner).
And here the methods involved.
I appreciate any help. Thank you for checking this out and have a nice day.
Stoeptegel
boolean state = false; GreenfootImage myImage;
public void act() { selectBoat(); if (state == true) { clickMove(); } }
public void selectBoat() { if (Greenfoot.mouseClicked(this)) { if(Greenfoot.getMouseInfo().getButton() == 1) { if (state == false) { state = true; myImage = new GreenfootImage("boatTest_t.png"); setImage(myImage); } else if (state == true) { state = false; myImage = new GreenfootImage("boat01-f.png"); setImage(myImage); } } } public void clickMove () { if (Greenfoot.getMouseInfo() != null) { if (Greenfoot.getMouseInfo().getButton() == 3) { int mouseX = Greenfoot.getMouseInfo().getX(); int mouseY = Greenfoot.getMouseInfo().getY(); this.turnTowards(mouseX, mouseY); } } }