Sign in to follow this  

Common code for 2D and 3D games

This topic is 2660 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi,
I feel that my question is stupid, but I have to ask it, so please excuse me =)

I'm working on a 3D game, it wont be done tomorrow, nor in one year, but I hope it will be done one day.
The amount of code I wrote that is related to the game is almost 0, most of the code are common components like, entity system, scripting system, resource handlers and etc.
Now working on a big 3D game alone can be exhausting, and of course I plan to find up more members that will help me, but to find them I need something that I can show, even gray boxes, which I don't have yet.
So sometimes I do want to feel that I accomplished something, and this why I like developing small 2D games like tower defense and etc. Those kind of games can be done in month (more or less) without working 24/7 on the game, and without hiring modelers/compositors.
So this brings me to my question: I don't want to write the same code over and over for my 2D games, hence I try to collect to to some reusable parts (call it engine if you wish). On the other side this code most likely wont help my main project which is a 3D game I dream to make. So my question: could those parts be shared between the games? Can Entity system for example be used both in 2D and 3D games? I mean only the renderer is different (not too much).

Ill appreciate any kind of help, and thanks to anyone who cared to read this!

skwee

Share this post


Link to post
Share on other sites
Quote:
Make 2D game by using your 3D engine/utilities/wrappers. Love quads, buffers and triangles :)

Thanks mate! Thats exactly what I thought! I just wans't sure and I need approval from different people :)

By the way, more comments are welcomed!

Thanks again!

Share this post


Link to post
Share on other sites
Certainly sounds feasible! And that's great practice in making generalized/reusable code. If you can share the same entity systems between your code, it means you've done a good job abstracting and compartmentalizing. At best, the only difference would be your entity.Draw functions.

Interesting concept, as I've never thought about creating an engine that could function in both 2D as well as 3D. Glad you brought it up, this is a neat idea to ponder!

Share this post


Link to post
Share on other sites
Building common code classes is a good practice. I currently have over 200 common classes ranging from web, file I/O, 3D, imaging etc. and it allows me to develop small and powerful programs usually in 2 weeks time or less. Once it reaches a certain size it becomes it's own programming language that you wrote.

Share this post


Link to post
Share on other sites
My 2D games and 3D game (none of which are finished ^_^;;;) all share the same codebase. Things that are common to all of them are the entity and messaging systems, the UI, the preferences (configuration), the text localization, the resource loading, the game loop (to some extent), and parts of the rendering pipeline (the effect/shader subsystem and the renderer interface for accepting chunks of geometry). So there is a lot of stuff that can be shared.

Share this post


Link to post
Share on other sites
I'm doing exactly what you're proposing (for exactly the same reason).

I have a base game framework, which deals with lots of generic concepts like scene graphs, resource management, serialisation, scripting, rendering, materials, etc. There are all the standard 3d entities (meshes, skeletal animation, physics, etc); but then I've also got a shape with is a Sprite (that wraps up the underlying quad and makes sure it's screen aligned for you - this is literally 20 lines of code), and for a few of my "small" games I've even written some 2d versions of the physics/collision code to get better performance on the iPhone.

The way it's written, all of the 2d entities can be mixed and matched with 3d - which is cool as it means the Sprites get used as the basis of the particle effects in 3d game, and the 2d games can leverage some of the 3d meshes/animation for fancier effects when they need them.

Share this post


Link to post
Share on other sites

This topic is 2660 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this