Esempio n. 1
0
        public Item CreateItem(float x, float y)
        {
            // generate texture.
            const int width = 16;
            const int height = 16;
            var texture = GameModel.Instance.TextureHelper.GenerateSimpleTexture(16, 16, Color.Magenta);

            var instance = new Item
                           {
                               Texture = texture,
                               Width = width,
                               Height = height,
                               DrawLayerType = DrawManager.DrawLayerType.PickableItem
                           };

            instance.Body = GameModel.Instance.BodyManager.CreatePickableBody(instance);
            instance.Position = new Vector2(x, y);

            // behaviors.
            instance.AddBehavior(new Sticky(instance, 64, 1));
            instance.AddBehavior(new Pickup(instance, 30));

            GameModel.Instance.UpdateManager.AddObjectForUpdate(instance);
            GameModel.Instance.DrawManager.AddObjectForDraw(instance);

            return instance;
        }
Esempio n. 2
0
        public bool append(Item item)
        {
            if (this.item == null)
            {
                this.item = item;
                return true;
            }

            return false;
        }
Esempio n. 3
0
 public Body CreatePickableBody(Item item)
 {
     Body body = BodyFactory.CreateRectangle(GameModel.Instance.World, ConvertUnits.ToSimUnits(item.Width), ConvertUnits.ToSimUnits(item.Height), 1f);
     body.SleepingAllowed = false;
     body.BodyType = BodyType.Dynamic;
     body.Restitution = .5f;
     body.Friction = .5f;
     body.CollisionCategories = Category.Cat3;
     body.CollidesWith = Category.Cat1;
     return body;
 }
Esempio n. 4
0
        public bool push(Item item)
        {
            Vector2? cell = findFreeSpace();

            if (cell != null)
            {
                BagItem bagItem = new BagItem();
                bagItem.append(item);
                items.Add((Vector2)cell, bagItem);
                return true;
            }

            return false;
        }