Trying to get the Boss in my game to only move up and down in my game, however I've also set a boundary because it's underwater. So I would like it to move up and down within the boundary. This is what I have, how can I fix it?
The top boundary is at Y = 237, and the bottom boundary is at Y = 465. I wanted it to stop moving left, and to move up and down when it reached 716, which is why I have it so it stops moving at that coordinate.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | public void move() { if (getX() > 716 ) { move(-speed_); } else if (getX() == 716 ) { setLocation( 716 , getY() + speed_); } else if (getY() == 465 ) { setLocation( 716 , getY() - speed_); } else if (getY() == 237 ) { setLocation( 716 , getY() + speed_); } } public void boundary() { if (getY() == 465 ) { setLocation(getX(), 465 ); } if (getY() == 237 ) { setLocation(getX(), 237 ); } } |