The bullet is being removed when it collides with an enemy and the enemy has a method to detect collision with bullets, but it does not trigger because its being removed ... first? Dont exactly know how to describe.
Here's the bullet code
And here the Terrorist code
And how do I give the bullet a damage value?
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Shot here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class ShotL extends Fire
{
/**
* Act - do whatever the Shot wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
setLocation(getX() + speed, getY());
checkHit();
if(this.checkHit() || this.atWorldEdge())
{
getWorld().removeObject(this);
}
}
private int speed = -10;
public boolean atWorldEdge()
{
if(getX() < 10 || getX() > getWorld().getWidth() - 10)
return true;
if(getY() < 10 || getY() > getWorld().getHeight() - 10)
return true;
else
return false;
}
private boolean checkHit()
{
if(getOneIntersectingObject(Enemy.class)!= null || getOneIntersectingObject(Platform.class) != null)
{
return true;
}
else
{
return false;
}
}
}
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Shot here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class ShotL extends Fire
{
/**
* Act - do whatever the Shot wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
setLocation(getX() + speed, getY());
checkHit();
if(this.checkHit() || this.atWorldEdge())
{
getWorld().removeObject(this);
}
}
private int speed = -10;
public boolean atWorldEdge()
{
if(getX() < 10 || getX() > getWorld().getWidth() - 10)
return true;
if(getY() < 10 || getY() > getWorld().getHeight() - 10)
return true;
else
return false;
}
private boolean checkHit()
{
if(getOneIntersectingObject(Enemy.class)!= null || getOneIntersectingObject(Platform.class) != null)
{
return true;
}
else
{
return false;
}
}
}

