I am having an existential crisis over an issue I'm having in which my lives variable doesn't decrease when I tell it to and I can't figure out how to successfully make my character invincible for a period of time. During this invincibility, I want BulletSlow.class to pass through the character (so I want to stop getObjectsInRange).
Here's the relevant code:
Getting hit in the below method should remove 1 PippiLives but doesn't:
This is the invincibility timer, which I also tried to make remove 1 PippiLives but it didn't work either:
Could someone show me how to make the character's hitbox actually turn off for a bit and then back on and have the character being hit actually remove 1 PippiLives? Thanks <3
public int PippiLives = 3;
private boolean HitboxState = true;
private int contactTimer; public void circularCollision()
{
if (HitboxState && getWorld().getObjects(Pippi.class).size() != 0)
{
List<BulletSlow> bulletList=getObjectsInRange(25, BulletSlow.class); /** Adjust range for sprite */
for (BulletSlow bulletSlow:bulletList)
{
if (bulletList.size() > 0)
{
PippiLives--;
getWorld().removeObjects(bulletList);
/** doesn't exist if Pippi removed, so nullpointerexception
* In future stop this method when lives = 0 */
}
}
} public void invincibility()
{
if (HitboxState = false)
{
contactTimer = (contactTimer + 1) % 20;
if (contactTimer == 0)
{
HitboxState = true;
PippiLives--;
if (PippiLives == 0)
{
Greenfoot.stop();
return;
}
}
}
