Monday 15 April 2013

game engine - Messages Between Two Distant Classes In Java -


I am working on Java games for a few months now and I have a problem.

My player runs around a environment , which contains tiles, in which everyone has their own CollisionBox Just keep: When player s collision box matches any other collision box (like a box or something like that) , Then the player can not move. That part is taken care of.

I am trying to implement Interactive Tile s, in which player will be caused if something happens to a specific collision box , especially like stairs or doors, I want to be able to make a new environment if specific * interactive tile * s hits

I have the functionality of transition and collision maps, but I know O the collision event to become environment (which is not easily hierarchy code for the collision event).

I am familiar with the supervisor pattern, in which environment can "hear" this collision, but I do not really know how it will be implemented here, Or even if this is the right design pattern for this situation!

Even just ...

When Player.IsCollidingWithDoorLeadingToNewEnvironment is environment. New environment for protection ( New Environment) should be called, but they are far apart in code structure from each other.

More generally: How can I send messages between the two classes without the layers on the layers of the constructor / constructor injection?

Have you heard about model-view-controller models? It's nothing, but maybe it can help, basically your program will have three parts:

  1. Ideal - this is all the teetotal words you have in your question, some of that program Represent parts that interact to include it.
  2. View - Display; It is not as relevant here, it is absolutely fine like how things are prepared on the screen
  3. Controller - this is what I think will help you, it's a class that runs the whole show . This class controls all the parts generated in the model component of the program and allows it to communicate with them. I think the environment class in your case would be good for this.

    Your controller group may contain arrays / array lists, which are included in all parts that were created during the game, such as collision boxes for each collision box (I I am using an instance variable (maybe by calling this ID) which represents its position in the array (this index can be as simple as an integer). When two boxes collide, you can call a method in the controller class which takes two IDs, and these IDs will easily find where they are in the array. Of course, you can use other data structures, but I hope this will give you the original idea.

No comments:

Post a Comment