Problem with a 2d game in java...

Hey guys, I have a space invaders type game pretty much done but i’m trying to limit the amount of player bullets on screen to 5.

Player (the ship) and Bullet are two seperate sub-classes of Actor and I want an int in the Player class to be updated in a method in the Bullet class.

It just wont seem to work.

I have within a method in Bullet a part that removes the bullet when it goes off-screen (y < 0) and it is here that i want to change an int in the Player class.

Then I want the int to be used again in the player class.

If i havent made any sense i could post the code as well.

Thanks

You are not making much sense, please post your code.

basically, as far as I understand it, what you want is something this:


class SomethingA {
   private int myInt;

   public int getMyInt() {
       return myInt;
   }

   public void setMyInt(int newInt) { 
       this.myInt = newInt;
   }
}
class SomethingB {
   private SomethingA myReferenceToTheOtherClass;

   public SomethingB(SomethingA other) {
      // lets change something in the other class!
     this.myReferenceToTheOtherClass = other;

     this.myReferenceToTheOtherClass.setMyInt(666); // hah! 666 is evil
   }
}

Hey :slight_smile:
Thanks a lot for the help, i managed to do what i wanted thanks to you!

in terms of your words

in the somethingB class i didnt have the somethingA other, i had just this other class and forgot completely to put in the somethingA class

again, thank you.

:slight_smile:

Just dont forget to post the final invaders game. I want to play it!

Regards,

  • Vincent

i have to start studying for exams so I won’t be working on it for around 2 and half weeks but i will post when its finished