Sign in to follow this  
Wixner

Need help with an Entity system for my platform game

Recommended Posts

Hi. I'm (trying) to develop a simple platform.game during my spare time using XNA Game Studio 2.0 and Visual Studio 2005 Express Edition but got stuck when trying to design the entity system. I had planned to use an "entity" class to provide a common interface for objects that is "interactable" in the game world: Enemies, Non-playable Characters, Event triggers, Doors, Switches etc. At the moment, I have several layers of polymorphism, where each layer appends more and more common interfaces to the end object. The polymorph-sequence for my player object is as follows: Player <- Character <- Critter <- Entity. The Entity layer currently adds the most common interfaces for all objects that the player can interact with, like position, size, direction and velocity and other physical properties (Even though the entity itself isn't physical). The Critter layer adds the most basic movement interfaces (Move, Run, Sneak), and actions that each enemy/player is able to perform (Idle, Jump, Attack) The Character (most likely to be renamed to Humanoid) layer adds movement- and action interfaces common to, and restricted to, humanoids (Crouch, Crawl, Hide, 2H Weapon Swing) The Player layer adds the movement and action interfaces only common to the player (special movements like Mid-air double-jumps, wall-jumping etc) The problem I just faced is that not all of my entities is necessarily renderable so I'm not sure if "Renderable" should be a flag in the Entity class or if I should implement another layer of polymorphism. Any comment is deeply appreciated.

Share this post


Link to post
Share on other sites
Quote:
Original post by Wixner
The problem I just faced is that not all of my entities is necessarily renderable so I'm not sure if "Renderable" should be a flag in the Entity class or if I should implement another layer of polymorphism.


You should create another hierarchy for Renderables. Then, as you said, not all your Entities need to be rendered (Triggers, Switches, etc); your Entities don't even need to know about rendering at all. You just inherit from Entity and Renderable. But, this of course requires that any Entity that needs to be drawn stores its necessary data (mesh/texture/sprite/position), and provides an interface (getter methods) to allow for access to this information that will be used in the rendering process.

Share this post


Link to post
Share on other sites
Sorry for the late reply, but I've been quite busy the latest days.

As you say, using a second polymorphism-hierarchy for renderable objects is a viable solution. I might even keep these IRenderable objects in a separate list, referenced to the IEntity list.

With separated list (all referenced to the same IEntity list) I don't need to traverse the entire IEntity list to find all IRenderable objects and then pass them to the renderer.

This can also be applied to other IEntity subobjects as well, like the IEventTrigger or the IEventReceiver object.

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