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 / Classes

Author
Message
Ninja_Je5us
14
Years of Service
User Offline
Joined: 1st Feb 2010
Location:
Posted: 21st Nov 2010 23:05
Hi,

I'm trying to tidy up some code on a game I'm working on by seperating it into classes. My main class is called "main" and my second class is called "JetFighter". How can I call and initialize the Jetfighter class in the main class?
JTK
14
Years of Service
User Offline
Joined: 10th Feb 2010
Location:
Posted: 22nd Nov 2010 03:07
Well, generally, we'd need more details; however, let me just say that the JetFighter class *should* know most (if not all) that it needs to know to intialize itself. Thus the advantage of "Object-Oriented" design...

This is usually done via the constructor. The Main class may need to pass some parameters to the JetFighter (to fill in the blanks - so to speak) but other than that, it will know how to handle itself.

I hope this helps,

JTK
Dodga
14
Years of Service
User Offline
Joined: 12th Dec 2009
Location:
Posted: 22nd Nov 2010 07:54
I would read up on classes a little bit more, its way to advanced of a topic to just explain it in the forums.
Matty H
15
Years of Service
User Offline
Joined: 7th Oct 2008
Location: England
Posted: 22nd Nov 2010 15:09
Using classes is not really a tidying up exercise so to speak, you may be wanting to just seperate functions into different files which is alot easier. Although learning to use classes is no bad thing, if you do that then people here will be able to help you with more specific questions if needed.

WLGfx
16
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 2nd Dec 2010 18:23
OO programming is ideal for game writing using classes but alongside classes you can use the 'list' commands in c++. Using linked lists helps tidy up your code because everything is controlled from within the class and the data is stored neatly in a linked list. Have a study of these pages for more information on lists.

http://www.java2s.com/Tutorial/Cpp/0340__list/Catalog0340__list.htm

GDK may be a bit cumbersome assigning objects to a constant number instead of a variable but used with this:


... can add a little more OO to DGDK.

Warning! May contain Nuts!
Mnemonix
21
Years of Service
User Offline
Joined: 2nd Dec 2002
Location: Skaro
Posted: 2nd Dec 2010 20:31
Can you use a static list in a class in c++ and then auto add the instance in the constructor? I forget, but you can do this i c# and the class automanages all instances of itself, really cool stuff

Join us at www.devhat.net and in #lobby at irc.devhat.net
WLGfx
16
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 4th Dec 2010 00:39
List were causing me some problems for a short while because I'd not used them for a while but here's something I've just figured out. Using classes and a linked list:
http://forum.thegamecreators.com/?m=forum_view&t=178541&b=22

Warning! May contain Nuts!

Login to post a reply

Server time is: 2024-09-28 14:06:33
Your offset time is: 2024-09-28 14:06:33