Ejemplo n.º 1
0
 public void ReturnToPool(GameObject o)
 {
     if (z_pool != null)
     {
         o.Reset();
         z_pool.Push(o);
     }
 }
Ejemplo n.º 2
0
 // remove an object from the main object list
 public void RemoveObject(GameObject obj)
 {
     // if we are in the update loop, we cannot modify the stage structure,
     // as it would invalidate the enumerator
     if (z_isUpdating)
         z_removes.Push(obj);
     else
         z_stage.Remove(obj);
 }
Ejemplo n.º 3
0
 public ObjectFactoryNode(int objectTypeID, GameObject defaultObject, bool isPooled, int initialSize)
 {
     z_objectTypeID = objectTypeID;
     z_default = defaultObject;
     z_initialSize = initialSize;
     if (isPooled)
     {
         z_pool = new Stack<GameObject>(initialSize);
     }
     else z_pool = null;
 }
Ejemplo n.º 4
0
 // Create a new GameObject with the exact same values as the original
 // It copies the references for the sprite and sprite rect arrays,
 // but does not copy child lists. This MUST be implemented by classes
 // utilizing Pool<T>, as it is used to create the copies for the pool.
 public GameObject(GameObject obj)
 {
     z_typeID = GameObject.ObjectTypeID;
     z_game = obj.z_game;
     z_position = obj.z_position;
     z_direction = obj.z_direction;
     z_layer = obj.z_layer;
     z_speed = obj.z_speed;
     z_maxSpeed = obj.z_maxSpeed;
     z_acceleration = obj.z_acceleration;
     z_accelerateTo = obj.z_accelerateTo;
     z_sprite = obj.z_sprite;
     z_spriteRects = obj.z_spriteRects;
     z_firstFrameToDraw = obj.z_firstFrameToDraw;
     z_lastFrameToDraw = obj.z_lastFrameToDraw;
     z_currentFrame = obj.z_currentFrame;
     z_animationTimer = obj.z_animationTimer;
     z_animationDelay = obj.z_animationDelay;
     z_visible = obj.z_visible;
     z_width = obj.z_width;
     z_height = obj.z_height;
     z_scaleX = obj.z_scaleX;
     z_scaleY = obj.z_scaleY;
     z_drawRotation = obj.z_drawRotation;
     z_spriteOrientation = obj.z_spriteOrientation;
     z_maxTurnRate = obj.z_maxTurnRate;
     z_spriteWidth = obj.z_spriteWidth;
     z_spriteHeight = obj.z_spriteHeight;
     z_spriteColor = obj.z_spriteColor;
     z_SpriteCenter = obj.z_SpriteCenter;
     z_removeMe = false;
     z_moveTo = obj.z_moveTo;
     z_spriteAlpha = obj.z_spriteAlpha;
     z_parent = null;
     z_children = new List<GameObject>();
 }
Ejemplo n.º 5
0
 public virtual void Reset()
 {
     z_animationTimer = 0;
     z_position = z_moveTo = Vector2.Zero;
     z_direction = Vector2.UnitX;
     z_accelerateTo = z_acceleration = z_speed = 0.0f;
     z_removeMe = false;
     z_visible = true;
     z_drawRotation = 0;
     z_children.Clear();
     z_parent = null;
     FirstFrameToDraw = LastFrameToDraw = 0;
 }
Ejemplo n.º 6
0
 public void RemoveChild(GameObject child)
 {
     z_children.Remove(child);
     if (child.Parent == this)
         child.Parent = null;
 }
Ejemplo n.º 7
0
 public void AddChild(GameObject child)
 {
     child.Parent = this;
     z_children.Add(child);
 }
Ejemplo n.º 8
0
 public static void ReturnObject(GameObject o)
 {
     foreach (ObjectFactoryNode node in z_objects)
     {
         if (node.ObjectTypeID == o.TypeID)
         {
             node.ReturnToPool(o);
             return;
         }
     }
 }
Ejemplo n.º 9
0
 public static void AddObjectType(int objectTypeID, GameObject defaultObject, bool isPooled, int initialSize)
 {
     z_objects.Add(new ObjectFactoryNode(objectTypeID, defaultObject, isPooled, initialSize));
 }