I have a projectile Class Bullet, which should be deleted when it hits anything.
I also have a wall that can't be passed through by any object using setLocation(int x, int y)
I want to delete the bullet when it "hits" the Bricks, but the Bullet never hits the bricks due to the code above.
I have already tried putting this in my Bricks Class, but it didn't work
And I have also tried putting this in Bullet Class, but this didn't work either
What code should I use to make the Bullet disappear and in what class should it be written?
public void setLocation(int x, int y)
{
int oldX = getX();
int oldY = getY();
super.setLocation(x, y);
if(!getIntersectingObjects(Bricks.class).isEmpty())
{
super.setLocation(oldX, oldY);
}
}public class Bricks extends Actor
{
/**
* Act - do whatever the Bricks wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
detectBullet();
}
public void detectBullet()
{
Actor actor = getOneObjectAtOffset(25, 25, Bullet.class);
if(actor!=null)
{
getWorld().removeObject(actor);
}
}
}public void detectWall()
{
Actor actor = getOneObjectAtOffset(25, 25, Bricks.class);
if(actor!=null)
{
getWorld().removeObject(this);
}
}
