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

Design: Where would you program behavior for an object?

4 posts in this topic

So I recently read Head First: Object Oriented Analysis and Design, and in one particular part of the book, it states that instead of having a base class with a bunch of derived classes for each object such as a soldier, tank, plane, etc. you should have one class called Unit that would get properties, set properties, get the type, set the type, and hold a container for you're different properties a.k.a. game objects.

Using that kind of approach, you would need one class only for an infinite number of gameobjects whereas if you derived from a base class you would need one class for each object. My question is, where exactly would you program the behavior for each "property"? Say I get a soldier and his properties from my Unit class, where and what would be the best way to implement it's behavior in game? What class would you place it in, how would you do it? The book doesn't explain how we'd program a gameobject's behavior.

Hope this made sense to you guys. Thanks.
0

Share this post


Link to post
Share on other sites
There are as always lot's of possibilities. One approach I never took into account but with which I am very happy at the moment is to define all behaviour outside of the actual game objects. So the objects are reduced to nothing more but a collection of data, which is manipulated from external systems.

Simplified I have this: I would have a function or whatever that takes a list of gameobjects of a specific type (for example "Soldier") and manipulates it's internal state according to typical soldier-behaviour. For tanks, there would be another function, for aeroplanes yet another and so on.

As I said, that's the simplified version which should work fine for small projects with limited requirements to flexibility. In reality, a component entity system like the one Goran describes is more extensible and easier to maintain (but takes a bit more work to get up and running in the first place). So what I actually do in my current project is to have a class "EntitySystem" which allows to create entities which are nothing more than identifiers (represented as integers) for game objects. Once I obtain a valid identifier, I can add components to them using another function of the EntitySystem.

Neither the entity nor the components contain any logic but are rather stupid data stores which are manipulated from the outside.

Then I have a bunch of "Systems" which can request the EntitySystem to call a function of their choice for every entity that has a specific combination of components. For example an Entity which qualifies as a soldier may have one component called "WithSoldierBehaviour" and one component "WithPosition". The system responsible for adding behaviour to soldiers (let's call it "SoldierBehaviourSystem") would then ask the EntitySystem to call a function like "SoldierBehaviourSystem::update_soldier(Entity e, WithSoldierBehaviour& behaviour_component, WithPosition& position_component)" for every entity which has both: a WithSoldierBehaviour- and a WithPosition-component.

In reality, soldier behaviour would need a lot more of information, thus needing more components to be added to the entity, like WithHealth, Waypointable, SubmachineGun, and so forth. The SoldierBehaviourSystem would have to take all of these into account.

Using this system also means that there will not be a single way to represent a soldier. This is a great way to add flexibility to your game. Want a Jetpack-Soldier? Add a JetPack-component. Want a vampire soldier? Add a BloodThirsty-component. I think you get the idea ;-)

I hope C++ syntax is okay for you, you didn't mention what language you are using, so my examples are in C++ ;-)
1

Share this post


Link to post
Share on other sites
For my games so far, I've been happy with a single all-encompassing object with a variable "Type" or some such. This is mainly for stategy games, where each trooper would boil down to only a few stats and behavioural differences.

In the initialisation methods, I check the type and fill the statistics for that unit. In the AI I check type and switch to determine behaviour. Some variables will exist to define behaviour (eg ability to fly or go on water).

I find it easier to conceptualise this way, and if most of the behaviour between units is similar, with only differences in stats / minor ability differences (move through water / fly), it is simpler than defining a new unit class every time.

You get a slightly bloated class, but most of it is pretty simple to understand - just a few switch statements.

However it might not work for a more complicated object - like a soldier in a FPS. His behaviour would be variable - defined by his equipment (jetpacks, grenade launchers would be different to a normal rifle-trooper), status (elites, grunts, bosses), and would be extremely different to a tank or helicopter (for example). For that I imagine rnlf's approach would be better - with separate components strung together.
0

Share this post


Link to post
Share on other sites
I use a data based design and do the behavior only with a scripting language like Lua.
This is cache friendly and extensible but it is much more complex and not really easy.

Every entity has his properties and you can access them via C++/Java/C#... with a hash map or a normal map (other containers are welcome [img]http://public.gamedev.net//public/style_emoticons/default/biggrin.png[/img]). The scripting interface can be object oriented, so that you will get an object pointer, where you can access the members and change the properties in an object oriented manner, or also be data based.

[CODE]
/* Stupid Example */
/* C++ */
Point pt = dataManager->property("block1", "pos").toPoint();
/* Lua - Object Oriented*/
function blockClickHandler (block)
Point pt = block.position();
end
/* Lua - Data Based*/
function blockClickHandler (position)
Point pt = position;
end
[/CODE]

This above is really a simple and incomplete example but shows some ways.
Many big games (with scripting languages), applications and websites use data based design. I really suggest it!
0

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