Yea for sure!
So in each of the player classes I have a instance health variable inside a zero-arg constructor.
[code]
public static int healthP1=100;
public player()
{
healthP1 = 100;
}
[/code]
And every time the bullet intersects with an object of bullet2.class, the yellow bullet, thirty is subtracted from the variable healthP1.
[code]
public void hitDetection()
{
Actor d = getOneIntersectingObject(player.class);
Actor e = getOneIntersectingObject(Rock.class);
Actor f = getOneIntersectingObject(Wagon.class);
if(this != null && isAtEdge())
{
getWorld().removeObject(this);
}
else if(d != null)
{
player.healthP1-=30;
getWorld().removeObject(this);
}
else if(e != null || f != null)
{
getWorld().removeObject(this);
}
}
[/code]
To delete the bullet when it hits the edge, as you can see above, I made a large if/else statement and made sure that if noting else happened to it, it was deleted. If you remove it and then another method or class tries to use it, you will get a null error because it won't exist anymore
Recent Comments
2019/3/6
Wild West Showdown, no clipping
2019/3/6
Wild West Showdown, no clipping