Esempio n. 1
0
        public virtual void Commits()
        {
            if (IsClose())
            {
                return;
            }
            int additionCount = pendingAdd.Count;

            if (additionCount > 0)
            {
                for (int i = 0; i < additionCount; i++)
                {
                    SpriteBatchObject obj = pendingAdd[i];
                    objects.Add(obj);
                }
                pendingAdd.Clear();
            }
            int removalCount = pendingRemove.Count;

            if (removalCount > 0)
            {
                for (int i = 0; i < removalCount; i++)
                {
                    SpriteBatchObject obj = pendingRemove[i];
                    CollectionUtils.Remove(objects, obj);
                }
                pendingRemove.Clear();
            }
        }
Esempio n. 2
0
        public void Commits()
        {
            bool changes       = false;
            int  additionCount = pendingAdd.Count;

            if (additionCount > 0)
            {
                object[] additionsArray = pendingAdd.ToArray();
                for (int i = 0; i < additionCount; i++)
                {
                    SpriteBatchObject o = (SpriteBatchObject)additionsArray[i];
                    objects.Add(o);
                }
                pendingAdd.Clear();
                changes = true;
            }
            int removalCount = pendingRemove.Count;

            if (removalCount > 0)
            {
                object[] removalsArray = pendingRemove.ToArray();
                for (int i_0 = 0; i_0 < removalCount; i_0++)
                {
                    SpriteBatchObject object_1 = (SpriteBatchObject)removalsArray[i_0];
                    objects.Remove(object_1);
                }
                pendingRemove.Clear();
                changes = true;
            }
            if (changes)
            {
                lazyObjects = objects.ToArray();
            }
        }
Esempio n. 3
0
 public virtual SpriteBatchObject Remove(SpriteBatchObject obj0)
 {
     pendingRemove.Add(obj0);
     if (usePhysics)
     {
         UnbindPhysics(obj0);
     }
     return(obj0);
 }
Esempio n. 4
0
        public bool IsCollision(SpriteBatchObject o)
        {
            RectBox src = GetCollisionArea();
            RectBox dst = o.GetCollisionArea();

            if (src.Intersects(dst))
            {
                return(true);
            }
            return(false);
        }
Esempio n. 5
0
 public PBody FindPhysics(SpriteBatchObject o)
 {
     if (usePhysics)
     {
         PBody body = (PBody)CollectionUtils.Get(_Bodys, o);
         return(body);
     }
     else
     {
         throw new RuntimeException("You do not set the physics engine !");
     }
 }
Esempio n. 6
0
 public void UnbindPhysics(SpriteBatchObject o)
 {
     if (usePhysics)
     {
         PBody body = (PBody)CollectionUtils.Remove(_Bodys, o);
         if (body != null)
         {
             body.SetTag(null);
             _manager.world.RemoveBody(body);
         }
     }
 }
Esempio n. 7
0
 public PBody BindPhysics(PBody body, SpriteBatchObject o)
 {
     if (usePhysics)
     {
         body.SetTag(o);
         _manager.AddBody(body);
         CollectionUtils.Put(_Bodys, o, body);
         return(body);
     }
     else
     {
         throw new RuntimeException("You do not set the physics engine !");
     }
 }
Esempio n. 8
0
 public PBody BindPhysics(bool fix, SpriteBatchObject o, float density)
 {
     if (usePhysics)
     {
         PBody body = _manager.AddBox(fix, o.GetRectBox(),
                                      MathUtils.ToRadians(o.GetRotation()), density);
         body.SetTag(o);
         CollectionUtils.Put(_Bodys, o, body);
         return(body);
     }
     else
     {
         throw new RuntimeException("You do not set the physics engine !");
     }
 }
Esempio n. 9
0
        public virtual void RemoveTileObjects()
        {
            int count = objects.Count;

            SpriteBatchObject[] objectArray = objects.ToArray();
            for (int i = 0; i < count; i++)
            {
                SpriteBatchObject o = (SpriteBatchObject)objectArray[i];
                pendingRemove.Add(o);
                if (usePhysics)
                {
                    UnbindPhysics(o);
                }
            }
            pendingAdd.Clear();
        }
Esempio n. 10
0
 public PBody BindCirclePhysics(bool fix, SpriteBatchObject o,
                                float density)
 {
     if (usePhysics)
     {
         RectBox rect = o.GetRectBox();
         float   r    = (rect.width + rect.height) / 4;
         PBody   body = _manager.AddCircle(fix, o.X(), o.Y(), r,
                                           MathUtils.ToRadians(o.GetRotation()), density);
         body.SetTag(o);
         CollectionUtils.Put(_Bodys, o, body);
         return(body);
     }
     else
     {
         throw new RuntimeException("You do not set the physics engine !");
     }
 }
Esempio n. 11
0
 public PBody BindTexturePhysics(bool fix, SpriteBatchObject o,
                                 float density)
 {
     if (usePhysics)
     {
         PBody body = _manager.AddShape(fix, o.GetAnimation()
                                        .GetSpriteImage(), MathUtils.ToRadians(o.GetRotation()),
                                        density);
         if (body.Size() > 0)
         {
             body.Inner_shapes()[0].SetPosition(o.X() / _manager.scale,
                                                o.Y() / _manager.scale);
         }
         body.SetTag(o);
         CollectionUtils.Put(_Bodys, o, body);
         return(body);
     }
     else
     {
         throw new RuntimeException("You do not set the physics engine !");
     }
 }
Esempio n. 12
0
 public PBody AddTexturePhysics(bool fix, SpriteBatchObject o)
 {
     return BindTexturePhysics(fix, Add(o), 1F);
 }
Esempio n. 13
0
 public virtual void RemoveTileObject(SpriteBatchObject o)
 {
     Remove(o);
 }
Esempio n. 14
0
 public virtual void AddTileObject(SpriteBatchObject o)
 {
     Add(o);
 }
Esempio n. 15
0
 public virtual SpriteBatchObject Remove(SpriteBatchObject obj0)
 {
     pendingRemove.Add(obj0);
     if (usePhysics)
     {
         UnbindPhysics(obj0);
     }
     return obj0;
 }
Esempio n. 16
0
 public PBody BindCirclePhysics(bool fix, SpriteBatchObject o)
 {
     return BindCirclePhysics(fix, Add(o), 1F);
 }
Esempio n. 17
0
 public PBody BindCirclePhysics(bool fix, SpriteBatchObject o)
 {
     return(BindCirclePhysics(fix, Add(o), 1F));
 }
Esempio n. 18
0
 public PBody FindPhysics(SpriteBatchObject o)
 {
     if (usePhysics)
     {
         PBody body = (PBody)CollectionUtils.Get(_Bodys, o);
         return body;
     }
     else
     {
         throw new RuntimeException("You do not set the physics engine !");
     }
 }
Esempio n. 19
0
 public PBody BindPhysics(bool fix, SpriteBatchObject o)
 {
     return(BindPhysics(fix, o, 1F));
 }
Esempio n. 20
0
 public PBody BindPhysics(PBody body, SpriteBatchObject o)
 {
     if (usePhysics)
     {
         body.SetTag(o);
         _manager.AddBody(body);
         CollectionUtils.Put(_Bodys, o, body);
         return body;
     }
     else
     {
         throw new RuntimeException("You do not set the physics engine !");
     }
 }
Esempio n. 21
0
 public PBody BindPhysics(bool fix, SpriteBatchObject o)
 {
     return BindPhysics(fix, o, 1F);
 }
Esempio n. 22
0
 public PBody BindTexturePhysics(bool fix, SpriteBatchObject o,
         float density)
 {
     if (usePhysics)
     {
         PBody body = _manager.AddShape(fix, o.GetAnimation()
                 .GetSpriteImage(), MathUtils.ToRadians(o.GetRotation()),
                 density);
         if (body.Size() > 0)
         {
             body.Inner_shapes()[0].SetPosition(o.X() / _manager.scale,
                     o.Y() / _manager.scale);
         }
         body.SetTag(o);
         CollectionUtils.Put(_Bodys, o, body);
         return body;
     }
     else
     {
         throw new RuntimeException("You do not set the physics engine !");
     }
 }
Esempio n. 23
0
 public PBody BindCirclePhysics(bool fix, SpriteBatchObject o,
         float density)
 {
     if (usePhysics)
     {
         RectBox rect = o.GetRectBox();
         float r = (rect.width + rect.height) / 4;
         PBody body = _manager.AddCircle(fix, o.X(), o.Y(), r,
                 MathUtils.ToRadians(o.GetRotation()), density);
         body.SetTag(o);
         CollectionUtils.Put(_Bodys,o, body);
         return body;
     }
     else
     {
         throw new RuntimeException("You do not set the physics engine !");
     }
 }
Esempio n. 24
0
 public void UnbindPhysics(SpriteBatchObject o)
 {
     if (usePhysics)
     {
         PBody body = (PBody)CollectionUtils.Remove(_Bodys, o);
         if (body != null)
         {
             body.SetTag(null);
             _manager.world.RemoveBody(body);
         }
     }
 }
Esempio n. 25
0
 public PBody AddTexturePhysics(bool fix, SpriteBatchObject o)
 {
     return(BindTexturePhysics(fix, Add(o), 1F));
 }
Esempio n. 26
0
 public virtual void AddTileObject(SpriteBatchObject o)
 {
     Add(o);
 }
Esempio n. 27
0
 public PBody AddCirclePhysics(bool fix, SpriteBatchObject o,
                               float density)
 {
     return(BindCirclePhysics(fix, Add(o), density));
 }
Esempio n. 28
0
 public virtual void RemoveTileObject(SpriteBatchObject o)
 {
     Remove(o);
 }
Esempio n. 29
0
 public PBody BindPhysics(bool fix, SpriteBatchObject o, float density)
 {
     if (usePhysics)
     {
         PBody body = _manager.AddBox(fix, o.GetRectBox(),
                 MathUtils.ToRadians(o.GetRotation()), density);
         body.SetTag(o);
         CollectionUtils.Put(_Bodys,o, body);
         return body;
     }
     else
     {
         throw new RuntimeException("You do not set the physics engine !");
     }
 }
Esempio n. 30
0
 public PBody AddCirclePhysics(bool fix, SpriteBatchObject o,
         float density)
 {
     return BindCirclePhysics(fix, Add(o), density);
 }
Esempio n. 31
0
            public void Act(SpriteBatchObject sprite, long elapsedTime)
            {

                // 如果主角与地图上其它对象发生碰撞(以下分别验证)
                if (game.hero.IsCollision(sprite))
                {
                    // 与敌人
                    if (sprite is Enemy)
                    {
                        Enemy e = (Enemy)sprite;
                        if (game.hero.Y() < e.Y())
                        {
                            game.hero.SetForceJump(true);
                            game.hero.Jump();
                            game.RemoveTileObject(e);
                        }
                        else
                        {
                            game.Damage();
                        }
                        // 与金币
                    }
                    else if (sprite is Coin)
                    {
                        Coin coin = (Coin)sprite;
                        game.RemoveTileObject(coin);
                        // 与加速道具
                    }
                    else if (sprite is Accelerator)
                    {
                        game.RemoveTileObject(sprite);
                        Accelerator accelerator = (Accelerator)sprite;
                        accelerator.Use(game.hero);
                        // 与二次弹跳道具
                    }
                    else if (sprite is JumperTwo)
                    {
                        game.RemoveTileObject(sprite);
                        JumperTwo jumperTwo = (JumperTwo)sprite;
                        jumperTwo.Use(game.hero);
                    }
                }
            }
Esempio n. 32
0
 public virtual void Remove(SpriteBatchObject obj0)
 {
     pendingRemove.Add(obj0);
 }
Esempio n. 33
0
 public virtual void Remove(SpriteBatchObject obj0)
 {
     pendingRemove.Add(obj0);
 }
Esempio n. 34
0
 public virtual SpriteBatchObject Add(SpriteBatchObject obj0)
 {
     pendingAdd.Add(obj0);
     return(obj0);
 }
Esempio n. 35
0
 public virtual void Add(SpriteBatchObject obj0)
 {
     pendingAdd.Add(obj0);
 }
Esempio n. 36
0
 public virtual void Add(SpriteBatchObject obj0)
 {
     pendingAdd.Add(obj0);
 }
Esempio n. 37
0
 public bool IsCollision(SpriteBatchObject o)
 {
     RectBox src = GetCollisionArea();
     RectBox dst = o.GetCollisionArea();
     if (src.Intersects(dst)) {
         return true;
     }
     return false;
 }
Esempio n. 38
0
 public virtual SpriteBatchObject Add(SpriteBatchObject obj0)
 {
     pendingAdd.Add(obj0);
     return obj0;
 }