1
\$\begingroup\$

I am working on simple 3D version of Snake game. I created classes like snake and grid so far. My concern is, putting all render logic (draws cubes - to show snake, and lines to show the grid) in above class could obscure the "pure" logic which should be divided from "view" layer.

So my question is, how to handle the whole render layer, separately from entity objects?

My current idea is to add object of "renderer" to each class which will encapsulate whole canvas work inside. There will be also master-renderer always looking for renderer inside all entities.

PS. I use JavaScript and Three.js

\$\endgroup\$
2
\$\begingroup\$

That said, there is no golden rule for that kind of thing, but it will mainly affect your architecture.

I would suggest you to take a look at the component pattern (which is used by some game engines such as Unity). This pattern will allow you to to "attach" component on game entity. In your case you will have, for example, a SnakeController component in charge of the snake movement, a SnakeDisplay component in charge of displaying it on screen... etc etc.

Every component will be in charge of its own stuff. So, combined with other you will have a complete and clean logic.

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ This is usually good advice, however for a game as simple as snake, this might be a bit overkill \$\endgroup\$ – CobaltHex Oct 2 '14 at 22:29
  • \$\begingroup\$ True. However it seems to me that this snake game is the first game developed so it can be interesting for him to learn about how things are done in case he wants to continue to develop games. \$\endgroup\$ – lvictorino Oct 3 '14 at 6:14
  • \$\begingroup\$ Yes, I would like to expand it for a lot of extra features so robust and components architecture is what I am looking for here. \$\endgroup\$ – IProblemFactory Oct 3 '14 at 9:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.