Example #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();
            }
        }
Example #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();
            }
        }
Example #3
0
 public virtual SpriteBatchObject Remove(SpriteBatchObject obj0)
 {
     pendingRemove.Add(obj0);
     if (usePhysics)
     {
         UnbindPhysics(obj0);
     }
     return(obj0);
 }
Example #4
0
        public bool IsCollision(SpriteBatchObject o)
        {
            RectBox src = GetCollisionArea();
            RectBox dst = o.GetCollisionArea();

            if (src.Intersects(dst))
            {
                return(true);
            }
            return(false);
        }
Example #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 !");
     }
 }
Example #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);
         }
     }
 }
Example #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 !");
     }
 }
Example #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 !");
     }
 }
Example #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();
        }
Example #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 !");
     }
 }
Example #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 !");
     }
 }
Example #12
0
 public PBody AddTexturePhysics(bool fix, SpriteBatchObject o)
 {
     return BindTexturePhysics(fix, Add(o), 1F);
 }
Example #13
0
 public virtual void RemoveTileObject(SpriteBatchObject o)
 {
     Remove(o);
 }
Example #14
0
 public virtual void AddTileObject(SpriteBatchObject o)
 {
     Add(o);
 }
Example #15
0
 public virtual SpriteBatchObject Remove(SpriteBatchObject obj0)
 {
     pendingRemove.Add(obj0);
     if (usePhysics)
     {
         UnbindPhysics(obj0);
     }
     return obj0;
 }
Example #16
0
 public PBody BindCirclePhysics(bool fix, SpriteBatchObject o)
 {
     return BindCirclePhysics(fix, Add(o), 1F);
 }
Example #17
0
 public PBody BindCirclePhysics(bool fix, SpriteBatchObject o)
 {
     return(BindCirclePhysics(fix, Add(o), 1F));
 }
Example #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 !");
     }
 }
Example #19
0
 public PBody BindPhysics(bool fix, SpriteBatchObject o)
 {
     return(BindPhysics(fix, o, 1F));
 }
Example #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 !");
     }
 }
Example #21
0
 public PBody BindPhysics(bool fix, SpriteBatchObject o)
 {
     return BindPhysics(fix, o, 1F);
 }
Example #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 !");
     }
 }
Example #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 !");
     }
 }
Example #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);
         }
     }
 }
Example #25
0
 public PBody AddTexturePhysics(bool fix, SpriteBatchObject o)
 {
     return(BindTexturePhysics(fix, Add(o), 1F));
 }
 public virtual void AddTileObject(SpriteBatchObject o)
 {
     Add(o);
 }
Example #27
0
 public PBody AddCirclePhysics(bool fix, SpriteBatchObject o,
                               float density)
 {
     return(BindCirclePhysics(fix, Add(o), density));
 }
 public virtual void RemoveTileObject(SpriteBatchObject o)
 {
     Remove(o);
 }
Example #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 !");
     }
 }
Example #30
0
 public PBody AddCirclePhysics(bool fix, SpriteBatchObject o,
         float density)
 {
     return BindCirclePhysics(fix, Add(o), density);
 }
Example #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);
                    }
                }
            }
Example #32
0
 public virtual void Remove(SpriteBatchObject obj0)
 {
     pendingRemove.Add(obj0);
 }
 public virtual void Remove(SpriteBatchObject obj0)
 {
     pendingRemove.Add(obj0);
 }
Example #34
0
 public virtual SpriteBatchObject Add(SpriteBatchObject obj0)
 {
     pendingAdd.Add(obj0);
     return(obj0);
 }
 public virtual void Add(SpriteBatchObject obj0)
 {
     pendingAdd.Add(obj0);
 }
Example #36
0
 public virtual void Add(SpriteBatchObject obj0)
 {
     pendingAdd.Add(obj0);
 }
 public bool IsCollision(SpriteBatchObject o)
 {
     RectBox src = GetCollisionArea();
     RectBox dst = o.GetCollisionArea();
     if (src.Intersects(dst)) {
         return true;
     }
     return false;
 }
Example #38
0
 public virtual SpriteBatchObject Add(SpriteBatchObject obj0)
 {
     pendingAdd.Add(obj0);
     return obj0;
 }