Jump to content
  • Advertisement
Luhan M.

Should I encapsulate even in very small games?

Recommended Posts

I'm nearly finishing my Pong game, and I was wondering if I should encapsulate things such as physics, rendering, sound, in such a small game.

Share this post


Link to post
Share on other sites
Advertisement

Like always, it comes down to what your ultimate goals are.  But in general I'd say yes.  Refactoring code is usually a good learning experience, especially when you're doing so with the goal of making it more cross-platform compatible or you're factoring out engine components to use later.  You will end up with a set of tools that you can reuse, and you'll understand better what the different parts are and how they relate to each other.

Share this post


Link to post
Share on other sites

As a learning experience it would certainly be valuable. A smaller program has less complexity, and so it can be easier to experiment.

If you're just trying to get games done? Probably not worth the effort unless you're planning on reusing some of that code. With a less complex program, the problems design practices such as encapsulation aim to solve aren't such a big deal. 

Share this post


Link to post
Share on other sites
7 hours ago, jbadams said:

As a learning experience it would certainly be valuable. A smaller program has less complexity, and so it can be easier to experiment.

If you're just trying to get games done? Probably not worth the effort unless you're planning on reusing some of that code. With a less complex program, the problems design practices such as encapsulation aim to solve aren't such a big deal. 

I already started doing it, so I'll finish. I have to say even being easier, it makes you think a little more about what you really need. Thanks for the help.

Share this post


Link to post
Share on other sites

I'm not sure there is a general answer to that question, as it depends on the kind of physics your game needs.

Another idea is to show us what you have so far, and perhaps we can see what is encapsulated well and what is poorly encapsulated?

Share this post


Link to post
Share on other sites
22 minutes ago, rip-off said:

I'm not sure there is a general answer to that question, as it depends on the kind of physics your game needs.

Another idea is to show us what you have so far, and perhaps we can see what is encapsulated well and what is poorly encapsulated?

Here is the code in github, inside Pong file there is the header files and .cpp (tell me if you can see or if there is a better way to show it to you).

https://github.com/Luhanmacedo/Pong

I didn't try to encapsulate the physics yet, so it's all inside the main function, and still have to tweak the angles and the AI.

Share this post


Link to post
Share on other sites
8 hours ago, Luhan M. said:

Just one more question, how generally a physics class should be implemented?

It's hard to say.

Question: Are you planning to make another game?  Reason I ask is that if you are planning to do another game, especially one that has many similarities with the current game, then that's one of the best ways to pull out the common code that can be encapsulated from the current one.   I mean, if you just have one game, especially when you're new to game development, it can be hard to know what parts are reusable and which cant.  But as you try to make another game you will quickly see all sorts of things that are in the old game that you want in the new one.  But instead of copy-paste you can then think of how you can pull that stuff out, in a non-game-specific way, into a set of libraries that can be your common core engine.

Share this post


Link to post
Share on other sites
3 minutes ago, 0r0d said:

It's hard to say.

Question: Are you planning to make another game?  Reason I ask is that if you are planning to do another game, especially one that has many similarities with the current game, then that's one of the best ways to pull out the common code that can be encapsulated from the current one.   I mean, if you just have one game, especially when you're new to game development, it can be hard to know what parts are reusable and which cant.  But as you try to make another game you will quickly see all sorts of things that are in the old game that you want in the new one.  But instead of copy-paste you can then think of how you can pull that stuff out, in a non-game-specific way, into a set of libraries that can be your common core engine.

Well, my next game is going to be a worm, so probably not. The only reason I'm encapsulating things is because I think it'd  create a good habit, would get some experience out of it, and help me think more before actually coding. But maybe it's a little overkill for a game such as pong.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!