RUMMAKER wrote...
you also don't need the if(getWorld() != null) thing in this caseshotasteroid(); if (getWorld() != null && atWorldEdge()) { // code processed when at world edge }
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; } }
public Bullet() { GreenfootImage image = getImage(); image.scale(image.getWidth()*(n/d), image.getHeight()*(n/d)); }