This site requires JavaScript, please enable it in your browser!
Greenfoot back
Ni3ls
Ni3ls wrote ...

2019/2/21

killCounter not registering kills

Ni3ls Ni3ls

2019/2/21

#
So I have a variable in BaseClass
protected int KillCount;
And when my bullet kills a Dummy (for example), it should add one to the counter
if(getWorld() != null && canSee(Dummy.class) && Enemy==false)
        {
            World world = getWorld();
            world.removeObjects(world.getObjects(Dummy.class));
            KillCount++;
            world.removeObject(this);
        }
But in another class, LittleRedCapGun, I try to see the counter, and when it is at 1, a key should be placed
if (WaveNumber==1)
        {
            if (KillCount==1)
            {
                world.addObject(new Key(),395,125);
            }
        }
But when I kill the Dummy, LittleRedCapGun doesn't seem to notice the KillCounter going up by one, so the Key isn't added to my game. The Bullet class extends BaseClass The LittleRedCapGun extends LittleRedCap, which extends BaseClass BaseClass extends Actor What should I do to make LittleRedCapGun notice when a bullet kills something?
danpost danpost

2019/2/21

#
Ni3ls wrote...
What should I do to make LittleRedCapGun notice when a bullet kills something?
Tell the LittleRedCapGun object directly instead of letting it try to figure it out by itself. Add a method to LittleRedCapGun that the bullet can call to "tell" it something was killed and have the bullet call that method when it kills something.
You need to login to post a reply.