Hey all,
I want to remove a ball that i shoot out of a cannon once it reaches the outer limits of the world,
having troubles getting the right coding for all sides of the world. thanks


1 2 3 4 5 | boolean topEdge = getY() == 0 ; boolean leftEdge = getX() == 0 ; boolean rightEdge = getX() >= getWorld().getWidth() - 1 ; boolean bottomEdge = getY() >= getWorld().getHeight() - 1 ; if (topEdge || leftEdge || rightEdge || bottomEdge) getWorld().removeObject( this ); |
1 2 3 4 5 | public boolean atLeftEdge() { boolean leftEdge = getX() == 0 ; if (leftEdge) { getWorld().removeObject( this ); } |
1 2 3 4 5 | public boolean atLeftEdge() { boolean leftEdge = getX() == 0 ; if (leftEdge) { getWorld().removeObject( this ); } |
1 2 3 4 5 6 7 8 9 | public boolean objectAtLeftEdge() { boolean leftEdge = getX() == 0 ; if (leftEdge){ return true } else { return false } } |
1 2 3 4 5 6 7 8 9 | public void act { if (objectAtLeftEdge()== true ) { getWorld().removeObject( this ); return ; } else { //whatever you want to do instead } } |
1 2 3 4 5 6 7 8 9 | public boolean objectAtLeftEdge() { boolean leftEdge = getX() == 0 ; if (leftEdge){ return true } else { return false } } |
1 2 3 4 5 6 7 8 9 | public void act { if (objectAtLeftEdge()== true ) { getWorld().removeObject( this ); return ; } else { //whatever you want to do instead } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | public boolean objectAtLeftEdge() { return getX() == 0 ; } // and public void act() { if (objectAtLeftEdge()) { getWorld().removeObject( this ); return ; } // whatever you want to do instead } // if checking all edges, then public void act() { if (objectAtLeftEdge() || objectAtRightEdge() || objectAtTopEdge() || objectAtBottomEdge()) { getWorld().removeObject( this ); return ; } // whatever you want to do instead } |