• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
bedtime

General Class Structure Question

8 posts in this topic

I've made a 2D mario style side-scroller. It works fine. My issue is that I don't think I'm using inheritance and polymorphism to the best of my ability. The result is that to use one class method I need to bring over a whole bunch of parameters from other class methods and containers.

For example:

instead of just drawing the board this way:

[CODE]
draw(imageToDraw, x, y);
[/CODE]

I end up having to do this:

[CODE]
draw(game, draw, objects, x, y);
[/CODE]

This wouldn't be an issue if it wasn't happening on so many methods of different functions and makes the code so much more complex looking and cumbersome. Another issue that makes it a little more challenging is that this game allows for multiple games at once. Basically split screen for an infinite amount of games. I do not want to drop this functionality.

So here are my basic classes:

Game - main loop
Draw - draws objects
Camera - tells Draw the location of objects to draw
Object - stores object xy velocity, characteristics...
Enemy Player Board - sets object characterists
Factory - object factory creates games objects
Move - moves objects
Collision - checks for crash
Record - records objects movement and plays back
Keyboard - game input

Here is my idea and I'd like some input on it. What do you think of combination like this ( where '->' means derived from):

game ->
camera -> draw
factory -> object -> enemy/player/board
move -> record -> collision -> keyboard


This is basically how I have it except I'm not inheriting from 'game' so I'm a lot of passing parameters. Would this be the better option and just inherit from 'game'?:

game->
camera
draw
factory
object -> enemy/player/board
move
record
collision
keyboard

I could use some ideas. I ask this because reworking this will take days. If I can get some ideas perhaps this will make things easier in the future.
0

Share this post


Link to post
Share on other sites
Hi Bedtime,

I'm having some trouble following your "derives" relationships above. Are you asking if everything should inherit from "Game" so that an instance of "Game" doesn't have to be passed in function calls where it is used?

My general thoughts would be:
1. Inheritance is an "Is A" relationship, therefore a child object should only inherit from a parent object if it is a more specialised version of the parent object. So I would think that, based on your overview above, nothing would inherit from Game.
2. Would "Has A" relationships work instead? Is it possible to pass in the "Game" instance to "Draw" at initialisation and store the reference for later use? Or are you using a single "Draw" object to do the drawing for all split-screen games?

Matt
1

Share this post


Link to post
Share on other sites
[quote name='de_mattT' timestamp='1353360741' post='5002446']
Hi Bedtime,

I'm having some trouble following your "derives" relationships above. Are you asking if everything should inherit from "Game" so that an instance of "Game" doesn't have to be passed in function calls where it is used?

My general thoughts would be:
1. Inheritance is an "Is A" relationship, therefore a child object should only inherit from a parent object if it is a more specialised version of the parent object. So I would think that, based on your overview above, nothing would inherit from Game.
2. Would "Has A" relationships work instead? Is it possible to pass in the "Game" instance to "Draw" at initialisation and store the reference for later use? Or are you using a single "Draw" object to do the drawing for all split-screen games?

Matt
[/quote]
I think 'has A' could work but would require more parameters to be passed. The thing is that that most objects are a part of game and need to be separated to work properly. This would be a different situation had I made this only a single game. Inheritance seems to make sense to me as it allows the objects to be easily divided at the beginning. Having said that, as for storing the game object reference I hadn't thought of that. It's a brilliant idea and I'll take a look into it. That could solve this, but is it good practice to do this? Not that what I have now is anywhere near good practice. But this would make it so much easier to fix.

Atm I'm using 'draw' to do both 'draws' job and 'cameras' job and so there are multiple 'draw' objects. I'm looking into changing this and making multiple 'camera' objects (camera calculates and stores the average position of multiple player objects to allow multi player camera focus). The only class that seems to have static functions is 'game' which holds the number of games as well as keyboard, which for now takes input once and gives to all games.
0

Share this post


Link to post
Share on other sites
I would say that if you are minimizing inheritance and polymorphism to the absolute best of your ability, you're doing okay. Inheritance can make for a nasty tangle. Following on de_mattT, there is a rule: [url="http://en.wikipedia.org/wiki/Composition_over_inheritance"]Favor composition over inheritance[/url]. While it's not a concrete law, it's still a pretty good rule to go by.
2

Share this post


Link to post
Share on other sites
[quote name='bedtime' timestamp='1353356110' post='5002426']
The result is that to use one class method I need to bring over a whole bunch of parameters from other class methods and containers.
[/quote]
If a class requires a lot of parameters, or if it requires a great deal of outside information, it means your work load is not properly partitioned.


[quote name='bedtime' timestamp='1353356110' post='5002426']
I could use some ideas. I ask this because reworking this will take days. If I can get some ideas perhaps this will make things easier in the future.
[/quote]

A class should be a noun. Functions/methods should be verbs. Several of your classes are verbs in disguise which is probably why they aren't working too well. Move, Collision, Record, Draw, these may be problematic.

Use composition instead of inheritance, and don't use either when it isn't necessary.

The composed data structures, not object state, should generally provide meaning. For example, object rendering doesn't take place in a vacuum, but rather in a rendering hierarchy.



Finally, start smaller. If you are having problems with it then you should probably tackle a smaller game instead.
2

Share this post


Link to post
Share on other sites
[quote]I would say that if you are minimizing inheritance and polymorphism to the absolute best of your ability, you're doing okay. Inheritance can make for a nasty tangle. Following on de_mattT, there is a rule: [url="http://en.wikipedia.org/wiki/Composition_over_inheritance"]Favor composition over inheritance[/url]. While it's not a concrete law, it's still a pretty good rule to go by.
[/quote]
Thank you. I've checked the link out and though I understand most of it I think implementing it might be a different story. But this just may be the way to go as the game objects need to be extremely flexible to do what I want them to do.


[quote name='frob' timestamp='1353363469' post='5002468']
If a class requires a lot of parameters, or if it requires a great deal of outside information, it means your work load is not properly partitioned.

[/quote]
Yes, this has been an issue from the start.

[quote]
A class should be a noun. Functions/methods should be verbs. Several of your classes are verbs in disguise which is probably why they aren't working too well. Move, Collision, Record, Draw, these may be problematic.

Use composition instead of inheritance, and don't use either when it isn't necessary.

The composed data structures, not object state, should generally provide meaning. For example, object rendering doesn't take place in a vacuum, but rather in a rendering hierarchy.

Finally, start smaller. If you are having problems with it then you should probably tackle a smaller game instead.
[/quote]
I did take on a lot with this game. I may decide to simplify it if I continue to be at a standstill. I'm going to look into tutorials on composition and see how I can implement this.

Thanks
0

Share this post


Link to post
Share on other sites
Some time back, a fellow asked for an example of object composition in a simple game such as pong. I wrote a couple examples, and while there is a whole lot about them that I would do differently now, it still might be somewhat useful to you.

http://www.gamedev.net/topic/623945-examples-of-component-design-in-simple-game-such-as-pong/
1

Share this post


Link to post
Share on other sites
[quote name='FLeBlanc' timestamp='1353365366' post='5002483']
Some time back, a fellow asked for an example of object composition in a simple game such as pong. I wrote a couple examples, and while there is a whole lot about them that I would do differently now, it still might be somewhat useful to you.

[url="http://www.gamedev.net/topic/623945-examples-of-component-design-in-simple-game-such-as-pong/"]http://www.gamedev.n...e-such-as-pong/[/url]
[/quote]
Thats a lot of information to take in so I'll likely be busy for a while before i come back to ask anymore questions. The more i read about composition the more it looks like the best fit.

and once again, thanx all.
Thanks for looking up that link for me.
0

Share this post


Link to post
Share on other sites
I don't see any obvious inheritance between any of the classes you mentioned. This is something it took me a while to understand as a beginner, but inheritance is actually quite rare.

As for your actual problem, it sounds like your code is too coupled. Too many classes want to be aware of other classes, rather than just talking to the ones they need to. The next step involves learning how to modularise your code.

I wouldn't recommend component-oriented design for the time being, it is probably overkill for the scale of the game I think you are aiming for.
1

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  
Followers 0