RUMMAKER wrote...
you also don't need the if(getWorld() != null) thing in this case

1 2 3 4 5 | shotasteroid(); if (getWorld() != null && atWorldEdge()) { // code processed when at world edge } |
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 32 33 34 35 | import greenfoot.*; public class Bullet extends Actor { public void act() { move( 5 ); if ( shotasteroid() || atWorldEdge() ) { getWorld().removeObject( this ); } } public boolean shotasteroid() { Asteroid asteroid = getOneObjectAtOffset( 2 , 2 , asteroid. class ); if (asteroid != null ) { Greenfoot.playSound( "Explosion.mp3" ); getWorld().removeObject(asteroid); return true ; } return false ; } public boolean atWorldEdge() { if (getX() < 10 || getX() > getWorld().getWidth() - 10 ) return true ; if (getY() < 10 || getY() > getWorld().getHeight() - 10 ) return true ; else return false ; } } |
1 2 3 4 5 | public Bullet() { GreenfootImage image = getImage(); image.scale(image.getWidth()*(n/d), image.getHeight()*(n/d)); } |