Sign in to follow this  
Thors1982

Class problems in a 2d engine

Recommended Posts

I am creating my first 2d tile engine. And I am trying to keep it very organized. I read "Programming Role Playing Games with DirectX", along with many other things. I was wondering if i should use his Core_graphics class or Core_system class. or I could write my own or not use any. I didn't really like his Core_system that much so im fine with not using that, but I can't seem to write a statemanager that doesn't use a case statement. Mainly cause im not that good with passing functions around. I started by writing my own and changing small things. But seemed like so much of it was just copy and paste. I didn't see a whole lot i wanted to change... so most of it was just copy and pasting which seems pointless to me. I learned a lot when i didn't use any and just wrote the directX code myself. But, im afraid its going to get to hard and to sloppy when i start adding in maps/tile classes to not use a graphics class.

Share this post


Link to post
Share on other sites
Just a couple of fast thoughts:

  • There's nothing wrong with a state manager that uses a switch/case. That's actually a fairly normal way to do it. In many (but not necessarily all!) cases, doing it any other way is overengineering. Do what works and is simple enough to be manageable.

  • A good rule of thumb for using other people's code is to copy it by hand. Rather than cut/paste, rewrite each line, and change all the variable, function, and class names as much as you can. (They should still make sense, though.) By adding your own "style" to the code, you have to look at it carefully, which means you probably have to understand a good bit of what's going on.

  • It isn't necessarily bad if your code looks a lot like someone else's. The good solutions to common problems always look fairly similar. Despite all their differences, at some level, all game engines look more or less the same. As long as you understand what's going on, it's OK. Don't worry about being able to invent your own designs from scratch just yet - that takes a huge amount of practice. For now, getting code finished and working is more important. Design skills can come later.

  • Remember, you can always copy the good points of someone's design and still write the code yourself. Don't worry about "not using a graphics class" just because someone else did it in a book; if that design helps you write good code that does what you need, feel free to steal it. That's what we all do [wink] (As a matter of fact, some of the best designs got stolen so often, that someone came up with the idea to just call them "patterns" and openly let everyone nick them whenever they want. It's a good thing.)



Code design is a hard skill, and it will take a few projects to get a good feel for it. It'll take a very long time to master. Hang in there and don't be discouraged if things end up a little bit messy; even the best projects have some messy bits. At the very least, note down areas of the design you aren't happy with, and once the project is done, think up ways to improve them.

Good luck, and stick with it!

Share this post


Link to post
Share on other sites
Hi Thors1982,

The "Programming Roleplaying games with directx" is quite a good book, it gives out a whole ton of usefull information. The only thing is, you probably won't like the way the classes was designed in the first place. I personally like to copy by hand, as ApochPiQ said. Then along the way you will understand the code more, than just by reading through it.

Then there is also another way, look at the one in the book, and create your own design of the class.

Good luck!

Share this post


Link to post
Share on other sites
Thanks for the help..... I actually had a decent Idea but im not sure if it will work so if anyone can help.... :-) i would appreciate it

anyways I was thinking about using polymorphism with my statemanager
and having Intro, Main Menu, Game etc be a types of statemanagers.

I am kinda confused on how to distribute the DirectX though. I may be able to have it all located in the statemanager.... so they all have access.... but im thinking a Graphics Class/Input Class would be able to handle it better?

Any suggestions or problems I may encounter, with either of these?

Share this post


Link to post
Share on other sites
I guess your states are not interested in DirectX. Drawing functionality does not realy belong in the states. So from the top of my head I guess I would create a small inheritance structure for keeping the current state of the application and besides that a set of classes for drawing and special effects.

Share this post


Link to post
Share on other sites

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