Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / OOP Organization

Author
Message
fedekun
14
Years of Service
User Offline
Joined: 28th Dec 2009
Location: Argentina
Posted: 29th Dec 2009 02:06
Hello all, i'm pretty new to C++ and Dark GDK but i have made some games in other languages, anyways i am looking for tips and advices, which is the best oop way of organizing a game? I though about making an object for each game state and then in the main loop update only the current state but that doesn't seem very nice... Any suggestions? How do you organize your games code?
Freedom Fighters
14
Years of Service
User Offline
Joined: 2nd Nov 2009
Location:
Posted: 29th Dec 2009 11:58
well organizing a game would to be have many things.

-keep media kept in the media folder nice and neat.
keeping your media file neat is a easy way to sort them out and look neat and professional. if you just left them around the place it looks messy

-make simple and easy to understand names for files
keyword you files to understand them and its easier to single them out.

-leave a small not explaining what a function
does and notes inside of that functions give some small key word, this helps to understand what it is and does. Note: you would only use this if the project starts to require more complex functions and extra files (*.h,*.cpp,Etc)

-using a functions for multiple functions under the same header
if you have say like 3 or more functions from the same header that need to be called in a while loop just use a functions like <HeaderName>FunctionsUpDateAll()

Example: WeaponsHeader.h
Function:

i use something like that to make it simpler


well hope these tips are easy to understand.
ill check back if you need any help.

Problem Solution That Never Fails: "Build A Bridge And Get Over It"
fedekun
14
Years of Service
User Offline
Joined: 28th Dec 2009
Location: Argentina
Posted: 29th Dec 2009 18:26
Thanks a lot, although that was not what i really ment that will help

I refer more to the code organization, for example



In the examples that is what it use, but its not object oriented, so i am looking for a more OO way
Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 29th Dec 2009 21:21
I'm starting to take a lot of my inspiration from the XNA architecture, though C++ provides a little more flexibility. In C# you're pretty much forced to make an object of everything. The XNA framework essentially has functions in each object that call the update and the draw sequences in which you place all the functionality to update all the other object then draw everything at once in a batch. Each object has their own draw function so the drawing function is simplified by calling the draw sequence using its internal data. Of course, in DGDK you just call dbsync() to update all the sprites.

In C++ I'm more inclined to make a function out of each game state and use a switch/case sequence to invoke the function. I'm also inclined to use a globally declared enum to control the gamestate.



When any of the currently running game state is ready to exit the function just changes the value of gamestate to reflect whatever state it figures will be next, possibly determined by user input.

I have worked my C++ code to be more completely object oriented by making the game an object with a Run() function that kicks off the game sequence. The constructor takes care of all the setup.

Lilith, Night Butterfly
I'm not a programmer but I play one in the office
fedekun
14
Years of Service
User Offline
Joined: 28th Dec 2009
Location: Argentina
Posted: 30th Dec 2009 01:50
Yes, that's what i have been doing so far but i though there was a more OO way to do that
Thanks.
Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 30th Dec 2009 02:50
Have you looked at GDK.NET? Although I have it I really haven't looked at it yet. However, if images and sprites are truly OO in it then you're almost assured of working in a strictly OO environment.

XNA provides "game components" from which you can derive your own component. These game components have their update and draw functions built in and the components themselves have an active/inactive type of switch. The primary control runs through a list of each of the game components and calls the update and draw functions of the components that are active. This would be very easy to build into your own coding in C++.

One of the GDK games I started to work on is designed something like this:




I could have designed this a little bit more compactly and had theGame declared as a global except that there are things you can't do in Dark GDK until the system has been initialized.

Not to get too complete here but the DarkCap header file looks like this.


So you can see how the constructor takes care of setting up the system. This could be used, in part, as a parent class for your own games to derive from. If I hadn't been in a hurry I'd have created a constructor that took parameters also.

Lilith, Night Butterfly
I'm not a programmer but I play one in the office

Login to post a reply

Server time is: 2024-10-01 20:33:03
Your offset time is: 2024-10-01 20:33:03