5 Replies - 1381 Views - Last Post: 17 June 2012 - 03:29 PM Rate Topic: -----

#1 Mr_Fraggs   User is offline

  • D.I.C Head

Reputation: 10
  • View blog
  • Posts: 89
  • Joined: 17-June 12

DirectX and Game Programming Organization

Posted 17 June 2012 - 12:44 PM

Hey guys, i'm just starting some actual programming with DirectX, and I was hoping someone could go over my code so far and tell me how well it's organized, and how well I could fix it. Thanks! All the program does so far is display a sprite that moves itself across the screen.

Spoiler


Is This A Good Question/Topic? 0
  • +

Replies To: DirectX and Game Programming Organization

#2 stayscrisp   User is offline

  • フカユ
  • member icon

Reputation: 1040
  • View blog
  • Posts: 4,325
  • Joined: 14-February 08

Re: DirectX and Game Programming Organization

Posted 17 June 2012 - 01:02 PM

First of all, why aren't you using classes?

Game, DXGraphics and Sprite can all be classes and the functions used can be member functions of those classes. It makes a lot more sense to do something like:

Sprite mainCharacter;

mainCharacter.init("graphic.bmp");



Than have to do that sprite loading code for each graphic you want to use in your game. The purpose of classes is so that you can stop repeating code and also nicely encapsulate your objects and their functionality and data.

Do you have any experience using classes?
Was This Post Helpful? 0
  • +
  • -

#3 v0rtex   User is offline

  • Caffeine: db "Never Enough!"
  • member icon

Reputation: 223
  • View blog
  • Posts: 773
  • Joined: 02-June 10

Re: DirectX and Game Programming Organization

Posted 17 June 2012 - 01:19 PM

as stayscrisp said, you should be using classes and not structs.
And this is probably nitpicking but I am a bit against the use of #define
and would rather have say use const as since you are using #define. The constants are replaced by the pre-processor at time of precompilation So if you receive an error during compilation, it will be confusing because the error message wont refer to the macro name but the value.

For example if you have the following:
#define sum 102451



and something goes wrong, the debugger will just tell you that your error is cause of literal value 102451 and not because you have used the macro wrong.

With const, the debugger will tell you that something has gone wrong with your constant. This may sound irrelevant but when you are debugging lots of defines, You might wish that you used const

So as an example, instead of:

#define SCREEN_WIDTH 1280



You would use:
const int SCREEN_WIDTH = 1280;



Just saying.
Was This Post Helpful? 1
  • +
  • -

#4 Mr_Fraggs   User is offline

  • D.I.C Head

Reputation: 10
  • View blog
  • Posts: 89
  • Joined: 17-June 12

Re: DirectX and Game Programming Organization

Posted 17 June 2012 - 01:40 PM

Sweet, i'll definitely switch over to consts instead of #defines. Thanks for the advice!

I do have some experience with classes, although not much because everything i've done so far is self taught. I was planning on making most of them into classes actually. The sprites was going to be the first class I tackled, but putting all the DirectX and Windows code into classes is beyond what I know right now. The main reason I actually posted this was to hopefully get some advice on putting the classes together, which I guess is what I meant by advice organizing.
Was This Post Helpful? 0
  • +
  • -

#5 stayscrisp   User is offline

  • フカユ
  • member icon

Reputation: 1040
  • View blog
  • Posts: 4,325
  • Joined: 14-February 08

Re: DirectX and Game Programming Organization

Posted 17 June 2012 - 02:42 PM

It might be a good idea for you to look at the tutorials that are linked in my signature. They use SDL as the graphics library but the concepts and classes will be of great use to you in learning how to structure your game and classes :)
Was This Post Helpful? 0
  • +
  • -

#6 Mr_Fraggs   User is offline

  • D.I.C Head

Reputation: 10
  • View blog
  • Posts: 89
  • Joined: 17-June 12

Re: DirectX and Game Programming Organization

Posted 17 June 2012 - 03:29 PM

Appreciate it! I'll definitely look over them. And I understand SDL so i'll have some kind of idea of what's going on. Appreciate all the help guys, keep it coming!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1