Ejemplo n.º 1
0
 internal void UnRegisterSpriteEngine(SpriteEngine engine)
 {
     lock (_engineList)
     {
         _engineList.Remove(engine);
     }
 }
Ejemplo n.º 2
0
 // Register and de-register SpriteEngines - called by the SpriteEngine.Surface setter
 internal void RegisterSpriteEngine(SpriteEngine engine)
 {
     lock (_engineList)
     {
         _engineList.Add(engine);
         SortEngines();
     }
 }
Ejemplo n.º 3
0
 // Detect collisions against a different sprite engine
 internal void PerformCollisionWith(SpriteEngine se)
 {
     lock (_spriteList)
     {
         lock (se._spriteList)
         {
             Sprites.ForEach(s1 => Sprites.Where(s2 => s1.Bounds.IntersectsWith(s2.Bounds)).ToList().ForEach(s2 => _surface.TriggerCollision(s1, s2)));
         }
     }
 }
Ejemplo n.º 4
0
        // Thread animation procedure
        protected void AnimateProc()
        {
            while (Active)
            {
                // Do we need to render a frame?
                if (DateTime.Now > _nextFrameTime)
                {
                    // Determine time stamp that next frame needs to be rendered
                    _nextFrameTime = DateTime.Now + _animationSpan;

                    // Process Sprite movement
                    lock (_engineList)
                    {
                        for (int i = 0; i < _engineList.Count; i++)
                        {
                            SpriteEngine se = _engineList[i];
                            se.MoveSprites();
                            // Handle wrapping around edges
                            if (WraparoundEdges)
                            {
                                se.WrapSprites();
                            }
                            // Handle collision detection with itself
                            if (se.DetectCollisionSelf && SpriteCollision != null)
                            {
                                se.PerformSelfCollisionDetection();
                            }
                            // Handle collision detection with other engines
                            for (int k = i + 1; k < _engineList.Count; k++)
                            {
                                SpriteEngine se2 = _engineList[k];
                                if (se.DetectCollisionTag == se2.DetectCollisionTag)
                                {
                                    se.PerformCollisionWith(se2);
                                }
                            }
                        }
                        // Remove dead sprites from engines
                        _engineList.ForEach(se => se.RemoveDeadSprites());
                    }
                    // Trigger a repaint of surface
                    Invalidate();
                }
                else
                {
                    Thread.Sleep(5);
                }
            }
        }
Ejemplo n.º 5
0
        // IComparable implementation - allows list of SpriteEngines to be sorted
        public int CompareTo(object obj)
        {
            SpriteEngine e2 = (SpriteEngine)obj;

            return(e2.Priority - Priority);
        }