This site requires JavaScript, please enable it in your browser!
Greenfoot back
Bigbobatesloppyjoe
Bigbobatesloppyjoe wrote ...

2020/1/7

collisions

I'm making a shooter's game and I want the bullet to disappear when I hit a bad guy. But the code for the collision doesn't seem to work with my if at edge remove the object. here's the code.
public void shot(){
        if(isTouching(snake.class)){
            removeTouching(snake.class);
            
            getWorld().removeObject(this);
            return;
        }
        
    }
    public void checkEdge() {
       if(isAtEdge()){
          getWorld().removeObject(this);
          return;
        }
        
    }
danpost danpost

2020/1/7

#
Bigbobatesloppyjoe wrote...
I'm making a shooter's game and I want the bullet to disappear when I hit a bad guy. But the code for the collision doesn't seem to work with my if at edge remove the object. here's the code. << Code Omitted >>
Between shot and checkEdge calls in act, place the following line:
if (getWorld() == null) return;
Btw, the return statements in your given code are kind of pointlessly placed at the end of the methods. Methods are automatically returned from when the end is reached.
You need to login to post a reply.