• 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
Plethora

Organizing my code (specifically regarding graphics)

8 posts in this topic

So, in taking all the CS classes I took in school something that the department seemed to want to stress was to keep graphics related classes apart from the rest of your code.  I never really questioned this and for the small projects I've worked on since it always worked well enough. 

 

As an example, let's say I am making a very simple soccer game.  I'm basically going to draw the field, the movable objects, and then an overlay of some sort that might say the time or the score.  Well based on the above I would have a graphics class and it would have a drawField method, a drawPlayers method, and a drawOverlay method.  I would have some kind of "main" method that would pass the player objects (for example) to the Graphics class and it would draw them, simple simple.  The field class, overlay class, and player class wouldn't even know what graphics api I was even using.

 

Well, as I've been trying to build some bigger and more complex games this method of doing things seems less than optimal.  I find I'm passing various objects all over the place and that my Graphics class can "see" basically every single bit of my code, which doesn't seem quite right to me.  I've looked up some open source games to see how they did it and I've seen a few different ways of doing things, but it seems like many have drawable objects drawing themselves.  So is that a better way to do things?  Is my original way of organizing ok?  Is there a "standard" way to do it?

0

Share this post


Link to post
Share on other sites
I would rather have a "physical" game logic side representation of the object, and a graphical representation.

Then you make the actual object which links all those together.

So in a way the object still draws itself, but the drawing is separated and there is no dependency between the game logic and rendering.

You can then make the "glue" class also link player controls and lets say networking or sound to the game logic side representation.

This will also let you store the graphical versions in one place so you can quickly iterate through them telling them to render themselves.
0

Share this post


Link to post
Share on other sites

Having a separate drawing system is better than having all objects draw themselves.


 

so its mean we can optimize our game by using the same sprite/texture which only loaded once on the Drawing class, then apply to all game objects ??

 

correct me if i'm wrong smile.png

Edited by Fs02
0

Share this post


Link to post
Share on other sites

Having a separate drawing system is better than having all objects draw themselves.


 

so its mean we can optimize our game by using the same sprite/texture which only loaded once on the Drawing class, then apply to all game objects ??

 

correct me if i'm wrong smile.png

 

That's correct.  Load every texture you need just once, and have each object reference the sprite texture. All sprite objects have the following in common- a location, a size (dimensions), and a texture. Those get passed to the Drawing class and it's the minimum amount of information that the Drawing class needs to draw the object.

1

Share this post


Link to post
Share on other sites

Also it means that changing the way you handle graphics can be done without completely re-writing all of your entities and physics code, etc. Decoupling is a very good idea in general. You want to try to design things such that changes to one aspect of the program inflict minimal redesign in other areas.

0

Share this post


Link to post
Share on other sites

Have a look at the Model-View-Controller (MVC) pattern. smile.png

 

Thanks, I spent some time reading up on MVC and it was well worth it. 

0

Share this post


Link to post
Share on other sites

As an example, for each Minecraft mob there is a dedicated class that knows how to render it (from what I've "researched"). It probably was good idea when they had only creepers but when you have 20 or more different kind of enemies (without even counting NPCs, wildlife, structures, items, etc), it can easily get out of hand.

 

Lots of boilerplate code (hard to maintain/improve), state switches (bad for performance) and so on.

 

MVC patter is pretty nice for those things since it defines a clear barrier between what you're showing to the player (ie, guy getting hit by an arrow) and what is happening at the "game logic" level (instance of class Guy got its health reduced by 20 units).

 

You can change what is shown to the player (ie, arrows got changed by flying magical projectiles that now have some sparkle effect) and the behavior of the logic of the game can remain the same (guy instance got hit, health reduction by 20).

2

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