Alex Rivera | Logout

Game Objects Talking To Each Other

Asked 2011-01-01T12:16:44.667
42

What is a good way of dealing with objects and having them talk to each other?

Up until now all my games hobby/student have been small so this problem was generally solved in a rather ugly way, which lead to tight integration and circular dependencies. Which was fine for the size of projects I was doing.

However my projects have been getting bigger in size and complexity and now I want to start re-using code, and making my head a simpler place.

The main problem I have is generally along the lines of Player needs to know about the Map and so does the Enemy, this has usually descended into setting lots of pointers and having lots of dependencies, and this becomes a mess quickly.

I have thought along the lines of a message style system. but I cant really see how this reduces the dependencies, as I would still be sending the pointers everywhere.

PS: I guess this has been discussed before, but I don't know what its called just the need I have.

Edit
Report

1 Answer

0

Be careful with "a message style system", it probably depends on implementation, but usually you would loose static type checking, and can then make some errors very difficult to debug. Note that calling object's methods it is already a message-like system.

Probably you are simply missing some levels of abstraction, for example for navigation a Player could use a Navigator instead of knowing all about the Map itself. You also say that this has usually descended into setting lots of pointers, what are those pointers? Probably, you are giving them to a wrong abstraction?.. Making objects know about others directly, without going through interfaces and intermediates, is a straight way to getting a tightly coupled design.

answered 2011-01-01T15:21:23.143

Your Answer