Sign in to follow this  

Best way to implement new Items/Entities

Recommended Posts

Hello Forum,

I've started developing a medium-sized XNA game some days ago and now that I have outlined the basic structure I was wondering which is the best way to implement new Items in my game.


The overall structure is clear:

Characters (such as Players and Enemies) have Inventories which is basically a 2d-Array of the abstract class Item.


Item has four virtual functions: Load, Unload, Update, Draw.


There are three derivated abstract classes from Item: Weapon, Armor and Potion.

Now every derivate of these classes overrides the virtual functions of Item to implement new features.

In my game-loop Update() is called for every loaded Item in the inventory.


What do you think of this solution? Of course it has much to do with personal preferences, but I want to know how others would do this.

I know interfaces or abstract functions also do the job.


Another question would be how Entities are stored in the game's main class. Is there one big array BasicEntity[] entities or are there many, many small ones like

Tile[,] tiles;

List<Character> characters;

Pool<Particle> particles;

Pool<Shot> shots;



Thank you very much, Phil.

Share this post

Link to post
Share on other sites

I think that your solution is good if it works for your game's requirements.  However I do not think it is scalable if you will add many more different "items".  Eventually, with such hierarchies, you'll end up pushing common functionalities up to parent objects which will result in a "god" parent class.  If this works for you though, I don't see the need to change it.


The way you handle and store your entities will also be based on your game's requirements.  If holding the memory for enetities in big datastructure is good enough, then there is no problem.  This will not scale well if your have massive amount of entities.  You have to think about what you do with these entities and how many you have in the game and whether the datastructure you use will be efficient enough for your needs.  If it does become a bottleneck, then you might consider using different datastructures or reorganizing things in many smaller "pools".

Share this post

Link to post
Share on other sites

Thanks for your reply,

I decided to leave it as it is since I don't want to include many different items. If this turns out to be not dynamic enough I'll just start it new and make it Component-based.

Share this post

Link to post
Share on other sites

Do you really need to update items in inventory? Or draw them? What are you using a 2D array for?


I'll just call these methods for activated items. Maybe, a weapon needs to have it's own draw-methods to, for example, make a glowing lightsaber or somethink like this. Drunk potions need to be updated to have an effect. The 2d-array is the inventory itself. I think there might be an easier way but I just take it... when it gets too slow I consider to draw items normally without fancy effect.

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