Jump to content
  • Advertisement
Sign in to follow this  
Theis_Bane

Objects with Collections with Objects with Collections...

This topic is 2343 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Okay, this seems like it should be relatively obvious, but days and days of programming have made my head into jello. I'm currently building a text-based game with my own version of a component-based entity system. I say my own because I'm trying to take what little I know about it and work my way though the problems as I go. I've got my entities contained within one another as follows:

World.List(Zone).List(Area).List(Feature).List(Components).Method and Properties

World - Overall game world.
Zone - A house.
Area - A specific room.
Feature - A door.
Component - Openable.
Property - IsOpen.

Now, this makes sense to me. However, I can't seem to wrap my head around how to efficiently access and change the address of the part of the world I'm want to. Especially considering function calls and whatnot. Like I said, I'm sure this isn't the problem I'm making it out to be, my head just hurts. Edited by Theis_Bane

Share this post


Link to post
Share on other sites
Advertisement

how to efficiently access and change the address of the part of the world?

Can you expand on that, and we (and possibly you aswell) get clearer picture what you're after?

Access from where? Do you have a single class (or function) which is requiring access to everywhere?

Change what address? Does this mean modifying the current world?

Share this post


Link to post
Share on other sites
I'm not sure how your world/game is constructed, but with your entities being accessible like that, I get the feeling the player knows the world(zone) with everything in it. What you can do is make make a class for each object like this: (pseudocode)

[source lang="cpp"]class World
{
List Zones<Zone>; // list of zones in this world
}

class Zone
{
List Areas<Area> // list of areas in this zone
}

class Area
{
List Features<Feature> // list of features in this area
}

class Feature
{
//whatever properties you want/need or components, you get the idea
}

// Now you can access individual classes more easily

int main
{
Feature door = World.zone.area.feature
// You can let the player know beforehand in what part of the world/zone/area he is in at the moment so you only have to access the features of that part, with its components/properties.
}[/source]
Hope this clears it a bit up for you.

Share this post


Link to post
Share on other sites
Basically, what I've got is a single BaseEntity class that possesses a Name and ID property. From there, I have more specialized Entity classes that inherit from this class. These are my components. I have an EntityCollection Class that is designed to hold a list of components that collectively represent an area or object.

An item is the world might have a collection containing - IsObtainable(a component telling the game that the player can pick this up), IsWieldable(a component telling the game that the player can use this as a weapon), Points(a component telling the game that obtaining this item gives the player a certain number of points). Each object is also a component, and is a member of another object's EntityCollection all the way up until the world object.

I am going to have a Manager class which will look at where the player is, describe the area, take in and parse a line of commands, manipulate the data, and present the results. What I'm guess is that once the game world is completely loaded into my World object, I basically just pass small parts of it to functions and methods for processing. I think. It's a lot to get my head around.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!