[SOLVED minor bugs] Tile based movement (Bomberman style)

yes I did that:



        public void headTowardsDestination(){
		if(!this.destinationReached){
			int currentX = this.currentPosition.getX();
			int currentY = this.currentPosition.getY();
			int destinationX = this.destinationPosition.getX();
			int destinationY = this.destinationPosition.getY();
			if(currentX < destinationX){
				this.currentPixelX++;
			}else if(currentX > destinationX){
				this.currentPixelX--;
			}else if(currentY < destinationY){
				this.currentPixelY++;
			}else if(currentY > destinationY){
				this.currentPixelY--;
			}
		}
	}


But where should should I assign destinationReached = false; ?

public void headTowardsDestination(){
this.destinationReached = false;
if(!(this.destinationPosition.getX() == this.currentPosition.getX()) ||
!(this.destinationPosition.getY() == this.currentPosition.getY()))
{
int currentX = this.currentPosition.getX();
int currentY = this.currentPosition.getY();
int destinationX = this.destinationPosition.getX();
int destinationY = this.destinationPosition.getY();
if(currentX < destinationX){
this.currentPixelX++;
}else if(currentX > destinationX){
this.currentPixelX–;
}else if(currentY < destinationY){
this.currentPixelY++;
}else if(currentY > destinationY){
this.currentPixelY–;
}
}
}else{
this.destinationReached = true;
}
}

also, where ever you set your new destination set .destinationReached to false.

I think it works, cant test it yet though, cause I have some bug in my code, the units moves downwards by default, and never reaches their destination, but I have given you an appreciate :slight_smile:

gbeebe, please use code tags: code goes here

@ra4king… Really?

Yes, really ;D

Out of curiosity, how do you escape the bbcode tags themselves?

Well this is how ra4king did it

 [code] code goes here [/code] 

It’s a clever hack I discovered in a moment of need :smiley: