Beispiel #1
0
        public bool PlaceFree(FloatRect r, CollisionCondition cond = null)
        {
            var tileSize = GameOptions.TileSize;

            var minX     = Math.Max(0, ((int)r.Left / tileSize) - 1);
            var minY     = Math.Max(0, ((int)r.Top / tileSize) - 1);
            var maxX     = Math.Min(Width, minX + ((int)r.Width / tileSize) + 3);
            var maxY     = Math.Min(Height, minY + ((int)r.Height / tileSize) + 3);
            var testRect = new FloatRect(0, 0, tileSize, tileSize);

            for (var yy = minY; yy < maxY; yy++)
            {
                for (var xx = minX; xx < maxX; xx++)
                {
                    if (!tiles[xx, yy].Solid)
                    {
                        continue;
                    }

                    testRect.Left = xx * tileSize;
                    testRect.Top  = yy * tileSize;

                    if (!r.Intersects(testRect))
                    {
                        continue;
                    }
                    if (cond == null)
                    {
                        return(false);
                    }
                    if (cond(tiles[xx, yy], testRect, r))
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }
Beispiel #2
0
    public Transition(string conditionType, string targetState)
    {
        m_conditionType = conditionType;
        m_targetState   = targetState;
        switch (m_conditionType)
        {
        case "Distance":
            m_distanceCondition = new DistanceCondition();
            break;

        case "Collision":
            m_collisionCondition = new CollisionCondition();
            break;

        case "Separation":
            m_separationCondition = new SeparationCondition();
            break;

        case "Wander":
            Console.WriteLine("Default case");
            break;
        }
    }
        public bool PlaceFree(FloatRect r, CollisionCondition cond = null)
        {
            var tileSize = GameOptions.TileSize;

            var minX = Math.Max(0, ((int)r.Left / tileSize) - 1);
            var minY = Math.Max(0, ((int)r.Top / tileSize) - 1);
            var maxX = Math.Min(Width, minX + ((int)r.Width / tileSize) + 3);
            var maxY = Math.Min(Height, minY + ((int)r.Height / tileSize) + 3);
            var testRect = new FloatRect(0, 0, tileSize, tileSize);

            for (var yy = minY; yy < maxY; yy++)
            {
                for (var xx = minX; xx < maxX; xx++)
                {
                    if (!tiles[xx, yy].Solid)
                        continue;

                    testRect.Left = xx * tileSize;
                    testRect.Top = yy * tileSize;

                    if (!r.Intersects(testRect))
                        continue;
                    if (cond == null)
                        return false;
                    if (cond(tiles[xx, yy], testRect, r))
                        return false;
                }
            }

            return true;
        }
Beispiel #4
0
 private void Awake()
 {
     instance = this;
 }