What's a good way to store a series of interconnected pipe and tank objects?
Posted
by
mars
on Game Development
See other posts from Game Development
or by mars
Published on 2011-11-19T23:07:26Z
Indexed on
2011/11/20
2:17 UTC
Read the original article
Hit count: 193
data-structure
I am working on a puzzle game with a 6 by 6 grid of storage tanks that are connected to up to 4 tanks adjacent to them via pipes. The gameplay is concerned with combining what's in a tank with an adjacent tank via the pipe than interconnects them.
Right now I store the tanks in a 6x6 array, vertical pipes in a 5x6 array, and horizontal pipes in a 6x5 array. Each tank has a reference to the object that contains both tanks and pipes and when a pipe needs to be animated filling with liquid, the selected tank just calls a method on the container object telling it to animate the pipes it is connected to (subtract 1 from row or column to find connected pipes).
This feels like the wrong way of doing it, as I've also considered just giving each tank references to the pipes connected to it to access directly.
© Game Development or respective owner