Well i'm working on a RTS bacteria game and these are the problem
1) I don't know what do to with the inheritance because i have multiple levels and normally my Game Base object should have the position the rotation,... but each instance of bacteria have their own position,rotation because this a dependant state property and my flyweight cannot handle it
You just restated your problem without really giving us any more information.
My understanding is that you're storing position and rotation in some array in your main game class?
Why does this prevent you from using it for the bacteria class? Why does bacteria have its own position and rotation?
What language are you using? Maybe if you provided some code we could understand your problems better.
Ok first of all the langage is c#
second i use XNA 4.0
my Base class
abstract class Chemotaxis_GameObject
{
#region Constructor/Destructor
protected Chemotaxis_GameObject(Texture2D texture, Vector2 origin)
{
this.texture = texture;
this.origin = origin;
}
#endregion
#region Attributes
protected Texture2D texture;
//protected Vector2 position;
//protected float rotation;
protected Vector2 origin;
#endregion Attributes
#region Functions
public virtual void Update(GameTime gameTime){}
public virtual void Render(SpriteBatch spriteBatch,Vector2 pos, float rot)
{
spriteBatch.Draw(texture, pos, null, Color.White, rot, origin, 1.0f, SpriteEffects.None, 1.0f);
}
#endregion
}
i'll keep it simple. Normally i would set the position, rotation,... in this class but the're all state dependant (extrinsic i think)
one of my flyweight abstract class
abstract class Chemotaxis_Bacteria : Chemotaxis_GameObject
{
#region Constructor/Destructor
protected Chemotaxis_Bacteria(Texture2D texture, Vector2 origin, Chemotaxis_Bacteria_Type type, Chemotaxis_Sensor sensor, float speed)
:base(texture,origin)
{
this.type = type;
this.sensor = sensor;
this.speed = speed;
}
virtual ~Chemotaxis_Bacteria()
{
}
#endregion
#region Attributes
//protected Chemotaxis_StateMachine stateMachine;
protected Chemotaxis_Bacteria_Type type;
protected Chemotaxis_Sensor sensor;
protected float speed;
#endregion
public abstract void Update(GameTime gameTime, ref Vector2 position,float rotation);
}
so i implement this class on multiples concrete flyweight and use a factory to create and return them when a flyweight client is create
a flyweight client
class Chemotaxis_BacteriaClient
{
#region Constructor/Destructor
public Chemotaxis_BacteriaClient(Vector2 pos, float rot)
{
this.position = pos;
this.rotation = rot;
bacteria = Chemotaxis_BacteriaFactory.GetBacteria(Chemotaxis_Bacteria_Type.TYPE_A);
}
#endregion
#region Attributes
Vector2 position;
float rotation;
Chemotaxis_Bacteria bacteria;
#endregion
#region Functions
public void Render(SpriteBatch spriteBatch)
{
bacteria.Render(spriteBatch, position, rotation);
}
public void Update(GameTime gameTime)
{
bacteria.Update(gameTime,ref position,rotation);
}
#endregion
}
as you can see this class hold the position, rotation and all state dependant properties. It's the first time i use a flyweight so i'm not sure if it's ok
so as you can see the code is split into many classes intrasic and extrasic and doesn't fit well with my inheritance but it's probably Ok with this pattern. If someone can confirm it could be good
and my second question is : Where shoud i put the AI behavior ? Probably in a client class if a follow the logic of the pattern but i'm not sure.
Finally the game client instances are create in the game main class
Thank for any help or advices