• Post Reply Bookmark Topic Watch Topic
  • New Topic

Objects in a Game  RSS feed

 
Ryan Ramsdenr
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay, im making a Game, but I can't understand how I can add objects to it, which I can later tell to do things.. D: For Example, adding a button and when it is pressed, "button.isPressed", will do something..



cry is a Crystal, when It activates, I want it to Change levels, but If I add any more Crystals, then when I activate them.. They will all change levels..



So I need to be able to determine 1 from another..

 
Campbell Ritchie
Marshal
Posts: 56518
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not quite sure I understand the problem, but I can see several pieces of iffy code:
The join-the-dots game is something you should use a pencil for. There is usually an easier way to write it than Level1.cry.hit. Why have you got a capital L? Is cry a static field? It is usually dubious practice to have static fields, and to have non-private fields. You should think of a way to write if (myLevel1.hasBeenHit()) ...
I think you should avoid == true and == false as far as possible. I think it’s simply if (myLevel1.hasBeenHit()) ...or if (!myLevel1.hasBeenHit()) ...

Your problem about all crystal activating simultaneously might be caused by their being static.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!