How do i make it to where if an object touches another instance of its self it will remove i of the objects
if (!getIntersectingObjects(getClass()).isEmpty()) getWorld().removeObject(this);
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class dumpster here. * * @author (your name) * @version (a version number or a date) */ public class dumpster extends coming { /** * Act - do whatever the dumpster wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { move(); if(this.getX() < 5) { getWorld().removeObject(this); } if (!getIntersectingObjects(getClass()).isEmpty()) getWorld().removeObject(this); } }
public void act() { move(); getWorld().removeObjects(getIntersectingObjects(dumpster.class)); if (getX() < 5) getWorld().removeObject(this); }