Example #1
0
        public static void UnitTest()
        {
            ItemBase item = null;
            TestGame.StartTest("ItemBase测试 F1-开启正交包围盒",
                null,
                delegate
                {
                    // item1
                    item = new ItemBase("GameandMe");
                    item.SetSize(new Vector2(100,100));
                    item.Position = new Vector2(400, 300);
                    item.origin = new Vector2(100, 100);
                    item.Rotation = 1.90f;
                    SceneMgr.Instance.AddItem(item);

                    // item2
                    item = new ItemBase("GameandMe");
                    item.SetSize(new Vector2(100, 100));
                    item.origin = new Vector2(100, -100);
                    item.Position = new Vector2(400, 300);
                    item.Rotation = -0.78f;
                    SceneMgr.Instance.AddItem(item);

                    // item3
                    item = new ItemBase("GameandMe");
                    item.SetSize(new Vector2(100, 100));
                    item.origin = new Vector2(0, 100);
                    item.Position = new Vector2(400, 300);
                    item.Rotation = -1.57f;
                    SceneMgr.Instance.AddItem(item);
                },
                delegate
                {
                },
                delegate
                {
                });
        }
Example #2
0
 /// <summary>
 /// 添加Item
 /// </summary>
 /// <param name="item"></param>
 virtual public void AddItem(ItemBase item)
 {
     item.layer = MaxLayer + 1;
     itemList.Add(item);
 }
Example #3
0
        // 需要补充排序方法等等...
        #endregion

        #region UnitTest
        public static void UnitTest()
        {
            ItemMgr boxMgr = null;
            ItemBase selItem = null;

            TestGame.StartTest("层级管理: 单击-选择 Up-上一级 Down-下一级 Left-底层 Right-顶层", null,
                delegate
                {
                    SceneMgr.Instance.backgroundMgr = new ItemMgr();
                    boxMgr = SceneMgr.Instance.backgroundMgr;
                    // 随机添加Box (ItemBase)
                    Random r = new Random(DateTime.Now.Millisecond);
                    Random r2 = new Random(DateTime.Now.Millisecond);
                    for (int i = 0; i < 10; i++)
                    {
                        ItemBase box = new ItemBase("GameandMe");
                        Vector2 boxPos = new Vector2();
                        boxPos.X = (int)(BaseGame.Width * r.NextDouble());
                        boxPos.Y = (int)(BaseGame.Height * r.NextDouble());
                        box.Position = boxPos;
                        box.Rotation = (float)(r2.NextDouble() * Math.PI *2);
                        // 添加到列表
                        boxMgr.AddItem(box);
                    }
                },
                delegate
                {
                    // 获取鼠标单击,确定选中的item
                    if (InputMouse.isLeftMouseClick())
                    {
                        selItem = null;
                        for (int i = boxMgr.MaxLayer; i >= 0; i--)
                        {
                            ItemBase item = boxMgr.itemList[i];
                            if (InputMouse.GetMouseClickRect().Intersects(item.GetOrthoBound()))
                            {
                                selItem = boxMgr.itemList[i];
                                Console.WriteLine("Select Item on Layer: "+i);
                                break;
                            }
                        }
                        if (selItem == null)
                        {
                            Console.WriteLine("--- Nothing Selected in this click ---");
                        }
                    }
                    // 获取键盘按键,调整层级
                    if (selItem != null)
                    {
                        // 向上箭头 -- 上移一级
                        if (InputKeyboards.isKeyJustPress(Keys.Up))
                        {
                            boxMgr.MoveToUpperLayer(selItem.layer);
                        }
                        // 向下箭头 -- 下移一级
                        if (InputKeyboards.isKeyJustPress(Keys.Down))
                        {
                            boxMgr.MoveToLowerLayer(selItem.layer);
                        }
                        // pageup   -- 移到顶部
                        if (InputKeyboards.isKeyJustPress(Keys.Right))
                        {
                            boxMgr.MoveToTop(selItem.layer);
                        }
                        // pagedown -- 移到底部
                        if (InputKeyboards.isKeyJustPress(Keys.Left))
                        {
                            boxMgr.MoveToBottom(selItem.layer);
                        }
                    }
                },
                delegate
                {
                }
                );
        }
Example #4
0
 public bool HasItem(ItemBase item)
 {
     // 拥有物品吗..
     return false;
 }