Exemplo n.º 1
0
        public Map CreateMap(Ksids ksids)
        {
            Assert.IsTrue(Data.GroupBy(s => s.Length).Count() == 1);
            int sizex = Data[0].Length;
            int sizey = Data.Length;

            map = new Map(-sizex / 2, -sizey / 2, sizex, sizey, ksids);
            return(map);
        }
Exemplo n.º 2
0
 private void TriggerRemoveTest(Placeable p1, Placeable p2, Ksids ksids)
 {
     if (p2.IsTrigger && ksids.IsParentOrEqual(p1.Ksid, p2.TriggerTargets))
     {
         p2.RemoveTarget(p1);
     }
     if (p1.IsTrigger && ksids.IsParentOrEqual(p2.Ksid, p1.TriggerTargets))
     {
         p1.RemoveTarget(p2);
     }
 }
Exemplo n.º 3
0
    private void MovingObjTest(Placeable p)
    {
        if (Ksids.IsParentOrEqual(p.Ksid, Ksid.SandLike) && p.IsNonMoving)
        {
            float y  = Mathf.Repeat(p.Pivot.y, Map.CellSize.y);
            float dy = p.PosOffset.y + p.Size.y;

            if (y + dy > Map.CellSizeY3div4)
            {
                Map.AddCellStateTest(Map.WorldToCell(p.Pivot), p.CellZ == 0 ? CellStateCahnge.CompactSand0 : CellStateCahnge.CompactSand1);
            }
        }
    }
Exemplo n.º 4
0
        public void Add(Placeable p, Ksids ksids)
        {
            int size = listInfo.Size;

            if (size == 0)
            {
                first         = p;
                listInfo.Size = 1;
                Blocking      = p.CellBlocking;
            }
            else
            {
                if (p == first)
                {
                    Debug.LogError("Duplikujes pridavani " + p.name);
                    return;
                }
                if (size == 1)
                {
                    var arr = CellList.ReserveData(2, out listInfo, out int offset);
                    arr[offset] = p;
                    Blocking    = first.CellBlocking | p.CellBlocking;
                    TriggerAddTest(p, first, ksids);
                }
                else if (size == CellListInfo.SizeMask)
                {
                    // Throw Helper
                    throw new InvalidOperationException("Prekrocena maximalni kapacita bunky");
                }
                else
                {
                    CellList.IncSize(ref listInfo, size + 1);
                    var arr = CellList.GetData(listInfo, out int offset);
                    size--;
                    arr[offset + size] = p;
                    Blocking           = first.CellBlocking | p.CellBlocking;
                    TriggerAddTest(p, first, ksids);

                    for (int f = offset; f < offset + size; f++)
                    {
                        Blocking |= arr[f].CellBlocking;
                        TriggerAddTest(p, arr[f], ksids);
                        if (arr[f] == p)
                        {
                            Debug.LogError("Duplikujes pridavani !" + p.name);
                        }
                    }
                }
            }
        }
Exemplo n.º 5
0
        public Map(int posx, int posy, int sizex, int sizey, Ksids ksids)
        {
            this.posx  = posx;
            this.posy  = posy;
            this.sizex = sizex;
            this.sizey = sizey;
            mapSize    = new Vector2Int(sizex, sizey);
            var mo = new Vector2(posx, posy);

            mo.Scale(CellSize2d);
            mapOffset = mo;

            this.ksids = ksids;
            cells      = new Cell[sizex * sizey];
        }
Exemplo n.º 6
0
        public void Remove(Placeable p, Ksids ksids)
        {
            int size = listInfo.Size;

            if (first == p)
            {
                if (size > 1)
                {
                    Blocking = CellFlags.Free;
                    var arr = CellList.GetData(listInfo, out int offset);
                    size--;

                    for (int f = offset; f < offset + size; f++)
                    {
                        Blocking |= arr[f].CellBlocking;
                        TriggerRemoveTest(p, arr[f], ksids);
                    }

                    first = arr[offset + size - 1];
                    CellList.DecSize(ref listInfo, size);
                }
                else
                {
                    first         = null;
                    listInfo.Size = 0;
                    Blocking      = CellFlags.Free;
                }
            }
            else if (size > 1)
            {
                Blocking = first.CellBlocking;
                TriggerRemoveTest(p, first, ksids);
                bool found = false;

                size--;
                var arr = CellList.GetData(listInfo, out int offset);
                for (int f = offset; f < offset + size; f++)
                {
                    if (arr[f] == p)
                    {
                        arr[f] = arr[offset + size - 1];
                        found  = true;
                    }
                    else
                    {
                        Blocking |= arr[f].CellBlocking;
                        TriggerRemoveTest(p, arr[f], ksids);
                    }
                }
                if (found)
                {
                    CellList.DecSize(ref listInfo, size);
                }
                else
                {
                    Debug.LogError("Odebiras neco co tu neni " + p.name);
                }
            }
            else
            {
                Debug.LogError("Odebiras neco co tu neni " + p.name);
            }
        }
Exemplo n.º 7
0
 public Map(MapSettings settings, Ksids ksids)
     : this(settings.posx, settings.posy, settings.sizex, settings.sizey, ksids)
 {
 }