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

Handling of game objects (projectiles, players etc)

6 posts in this topic

I started to write some code for weapons and firing them when I realized the structure of the game code was a bit weird. I store an array of players in my Game class, I store an array of enemies in my AIManager class but I didn't know where to store the projectiles. I wanted to store the projectiles in Game first, but I can't "put it there" because Game includes Projectile.h and Projectile.h would then have to include Game.h to be able to call its methods, right? Now I wonder how a good way to structure all of the game code would be. It's a very broad term I know and there are probably very many different ways to go about it.

Say I have stored my projectiles somewhere and then I want to detonate it and deal damage to everyone around it, then I need access to all players and enemies and perhaps doodads to check the distance and calculate damage. But how do I access it? What's a general good advice? I thought of sending a pointer to the array of objects to be possible victims but then again I stored all objects in different arrays depending on what kind of object, and in different places and I then I took a break.

What are some general ways to structure this whole mess? I want to have some kind of decoupling of the responsibilities. For example the renderer class is separate from everything. I would like the objects to handle themselves like the projectile would do the exploding itself and doing damage in its own method or something similar.

I suppose the question is kind of unclear and I'm sorry for that, but I don't really know how to put it in a different way. I'm very thankful for any input I may receive!


EDIT: I was thinking of a system where every object handled everything themselves, collision detection and response, updating health points, animations and other possible events. I was looking at the SC2 map editor and it seems kind of complex but incredibly powerful and flexible. Are they doing something close to this?

Right now the code is kind of like containers of players, projectiles, enemies and the Game performs the calculations and updates, I suppose it would generally be a better idea to leave this to the individual objects considering they do different things in their updates. But then I imagine everything would be like a huge array of objects that are just looped through and have their Update method called, more or less. What are you thoughts on this? Edited by Hannesnisula
1

Share this post


Link to post
Share on other sites
I don't really understand why your code in ProjectTile.h should call methods from Game.h... Normaly I would call methods in the source file and not the header.

Although it is doable, I think the method you want to choose, is a complex one. A tile that handle an explosion and damage other tiles? Is that really the responsibility of the tile, or is that the responsibility of the "Explosion". It is a though decission and both ways are correct, but in my opinion, putting to much logic in an object is generally not a good thing.
Other than this I can't give you much advise...
-1

Share this post


Link to post
Share on other sites
What I do is that I have all objects (player, enemies, projectiles) in a single array. They are all derived from a base class "Agent" and have a property Type, which says if they are creature or projectile.

So, if you had an explosion damaging only enemies, you could have:
[CODE]
explode()
{
foreach (Agent a in AllAgents)
if (a.Type == Enemy) a.Die();
}
[/CODE]
1

Share this post


Link to post
Share on other sites
Storing all the objects in a huge array? Basically it is ok. However, for things such as projectiles and other short time existing objects, I'd make another system which would allow fast spawning of projectile objects and other stuff (spells etc)

Loop through the huge array to update them? Not a good idea. First of all, not all objects need to update every frame. Some objects need to update more often and others less often. So, if each object could be tweaked to update at desired interval you'd save a huge amount of CPU power. Also, the update frequency may be affected by things such as proximity to player.

Causing explosive damage to entities: I assume that you use some kind of accelerator tree (octree perhaps) for storing objects. You may use that tree to fetch objects at certain radius to your explosive center and then for each object send a message "explosion of x force at point x,y,z" and each object reacts to the explosion if they need to.

Render components are easily separated from the entities. You may create a separate octree for objects you wish to cull and render. You could check for discussions about game entities composed of components.

Best regards!
1

Share this post


Link to post
Share on other sites
If you want to decouple your objects, why do they handle everything to begin with?

SC2 objects don't control collisions, they have attributes that tell the engine how it should handle them.

It makes a lot more sense (at least to me) that all objects are owned by some logic game class that actually runs the game. That class, then, has access to all the needed components (rendering code, physics code, etc.) and runs them on the objects it owns.

The objects themselves only own attributes to tell the game what they are and what to do with them (which by itself is a whole new topic on how to design this, e.g. Inheritence vs components).
2

Share this post


Link to post
Share on other sites
I agree with wolfscaptain, I just didn't found the right words to say it [img]http://public.gamedev.net//public/style_emoticons/default/rolleyes.gif[/img]
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