Exemple #1
0
    public CellController ReplaceCell(MapPoint point, CellController prefab)
    {
        if (point.X < 0 || point.Y < 0 || point.X > 0xffff || point.Y > 0xffff)
        {
            return(null);
        }


        CellController newCell = CellController.InstantiateMe(prefab, transform, point);


        MapRect rect = prefab.GetCellIndexes(point, selectedRotation);

        rect.Foreach((MapPoint p) => {
            int key = p.toInt();
            if (cells.ContainsKey(key))
            {
                GameObject.Destroy(cells[key].gameObject);
                cells.Remove(key);
                cells[key] = newCell;
            }
        });

        newCell.SetRotation(selectedRotation);

        return(newCell);
    }
Exemple #2
0
        public void ShouldStuckPlayerBetweenTwoWalls()
        {
            // Arrange
            var r        = _player.Radius;
            var mapRect1 = new MapRect(r, 3 * r, 4 * r, 2 * r);
            var mapRect2 = new MapRect(4 * r, r, 2 * r, 6 * r);

            _mapState.MapObjects.Add(mapRect1);
            _mapState.MapObjects.Add(mapRect2);

            // Act
            _player.Keys = new List <KeyEnum> {
                KeyEnum.Down
            };
            for (var i = 1; i <= 200; i++)
            {
                _gameEngine.PhysicsEngine.ApplyPhysics();
            }

            _player.Keys = new List <KeyEnum> {
                KeyEnum.Right
            };
            for (var i = 1; i <= 200; i++)
            {
                _gameEngine.PhysicsEngine.ApplyPhysics();
            }

            // Assert
            var expectedY = mapRect1.Position.Y - (mapRect1.Height / 2) - _player.Radius;
            var expectedX = mapRect2.Position.X - (mapRect2.Width / 2) - _player.Radius;

            Assert.AreEqual(expectedY, _player.Position.Y, _config.IntersectionInterval);
            Assert.AreEqual(expectedX, _player.Position.X, _config.IntersectionInterval);
        }
 private static bool DoesRectContainsVertex(MapRect rect, Vector2 point)
 {
     return(point.X >= rect.Position.X - (rect.Width / 2) &&
            point.X <= rect.Position.X + (rect.Width / 2) &&
            point.Y >= rect.Position.Y - (rect.Height / 2) &&
            point.Y <= rect.Position.Y + (rect.Height / 2));
 }
Exemple #4
0
    public void PlaceIndicators(Dictionary <int, CellController> cells,
                                Dictionary <int, WallController> walls,
                                WallController wallPrefab)
    {
        bool isDoor = wallPrefab.PrefabIsDoor();

        foreach (CellController c in cells.Values)
        {
            if (c.IsMultiCell)
            {
                MapRect rect = c.GetCurCellIndexes();
                rect.Foreach((MapPoint p) => {
                    WallPoint wp = new WallPoint(p.X, p.Y);
                    if ((isDoor || !walls.ContainsKey(wp.toInt())) && wallPrefab.PrefabValidatePosition(M, wp))
                    {
                        InstantiateIndicator(wp, isDoor);
                    }
                });
            }
            else
            {
                WallPoint wp = new WallPoint(c.Position.X, c.Position.Y);
                if ((isDoor || !walls.ContainsKey(wp.toInt())) && wallPrefab.PrefabValidatePosition(M, wp))
                {
                    InstantiateIndicator(wp, isDoor);
                }
            }
        }
    }
        public void RectRayCasting_ShouldReturnNull_WhenInOppositeDirection()
        {
            // arrange
            MapRect rect = new MapRect(1, 0, 2, 2);
            Ray     ray  = new Ray(-3, 0, -1, 0);

            // act
            Trace trace = RayCast.CheckBulletTrace(ray, rect);

            // assert
            Assert.IsNull(trace);
        }
        public void RectRayCasting_ShouldReturnHitPosition_3()
        {
            // arrange
            MapRect rect = new MapRect(10, 10, 1, 1);
            Ray     ray  = new Ray(10, 12, 0, -1);

            // act
            Trace trace = RayCast.CheckBulletTrace(ray, rect);

            // assert
            Assert.IsNotNull(trace);
            Assert.AreEqual(trace.Position, new Vector2(10, 10.5));
        }
Exemple #7
0
    protected override void Update()
    {
        //已爆炸跳过
        if (m_IsExploded)
        {
            return;
        }

        //移动
        transform.Translate(Direction * Speed * Time.deltaTime, Space.World);

        //旋转
        transform.Rotate(Vector3.forward, RotateSpeed * Time.deltaTime, Space.World);

        //检测(存活/死亡)
        GameObject[] monsterObjects = GameObject.FindGameObjectsWithTag("Monster");

        foreach (GameObject monsterObject in monsterObjects)
        {
            Monster monster = monsterObject.GetComponent <Monster>();

            //忽略已死亡的怪物
            if (monster.IsDead)
            {
                continue;
            }

            if (Vector3.Distance(transform.position, monster.transform.position) <= Consts.RangeClosedDistance)
            {
                //敌人受伤
                monster.Damage(this.Attack);
                if (monster.Hp <= 0)
                {
                    Random    random = new Random();
                    GameModel gm     = MVC.GetModel <GameModel>();
                    gm.Gold += Random.Range(5, 15);
                }
                //爆炸
                Explode();

                //退出(重点)
                break;
            }
        }

        //边间检测
        if (!m_IsExploded && !MapRect.Contains(transform.position))
        {
            Explode();
        }
    }
        public static bool CheckIntersection(MapRect r1, MapRect r2)
        {
            var r1x1 = r1.Position.X - (r1.Width / 2);
            var r1x2 = r1.Position.X + (r1.Width / 2);
            var r1y1 = r1.Position.Y - (r1.Height / 2);
            var r1y2 = r1.Position.Y + (r1.Height / 2);

            var r2x1 = r2.Position.X - (r2.Width / 2);
            var r2x2 = r2.Position.X + (r2.Width / 2);
            var r2y1 = r2.Position.Y - (r2.Height / 2);
            var r2y2 = r2.Position.Y + (r2.Height / 2);

            return((r2x2 >= r1x1 && r2x1 <= r1x2) && (r2y2 >= r1y1 && r2y1 <= r1y2));
        }
Exemple #9
0
    protected override void Update()
    {
        //已爆炸无需跟踪
        if (m_IsExploded)
        {
            return;
        }

        //目标检测
        if (Target != null)
        {
            if (!Target.IsDead)
            {
                //计算方向
                Direction = (Target.transform.position - transform.position).normalized;
            }

            //角度
            LookAt();

            //移动
            transform.Translate(Direction * Speed * Time.deltaTime, Space.World);

            //打中目标
            if (Vector3.Distance(transform.position, Target.transform.position) <= Consts.DotClosedDistance)
            {
                //敌人受伤
                Target.Damage(this.Attack);
                if (Target.Hp <= 0)
                {
                    Random    random = new Random();
                    GameModel gm     = MVC.GetModel <GameModel>();
                    gm.Gold += Random.Range(5, 15);
                }
                //爆炸
                Explode();
            }
        }
        else
        {
            //移动
            transform.Translate(Direction * Speed * Time.deltaTime, Space.World);

            //边界检测
            if (!m_IsExploded && !MapRect.Contains(transform.position))
            {
                Explode();
            }
        }
    }
	//returns true if this phantom already has been placed
	public bool PlacePhantom(MapPoint pos,MapRect rect)
	{
		LastPhantomPosition = pos;
		if(lastRect.Equals(rect))
			return true;

		RemovePhantom();

		rect.Foreach((MapPoint p) => {
			InstantiatePhantom(p,true);
		});

	
		lastRect = new MapRect(rect);
		return false;
	}
    protected override void Update()
    {
        //已爆炸跳过
        if (m_IsExploded)
        {
            return;
        }

        //移动
        transform.Translate(Direction * Speed * Time.deltaTime, Space.World);

        //旋转
//		transform.Rotate(Vector3.forward, RotateSpeed * Time.deltaTime, Space.World);

        //检测(存活/死亡)
        GameObject[] enemyObjects = GameObject.FindGameObjectsWithTag("Enemy");

        foreach (GameObject enemyObject in enemyObjects)
        {
            Enemy enemy = enemyObject.GetComponent <Enemy>();

            //忽略已死亡的怪物
            if (enemy.IsDead)
            {
                continue;
            }

            if (Vector3.Distance(transform.position, enemy.transform.position) <= Consts.RangeClosedDistance)
            {
                //敌人受伤
                enemy.Damage(this.Attack);

                //爆炸
                Explode();

                //退出(重点)
                break;
            }
        }

        //边间检测
        if (!m_IsExploded && !MapRect.Contains(transform.position))
        {
            return;
        }
        //Explode();
    }
    protected override void Update()
    {
        //已爆炸跳过
        if (IsExploded)
        {
            return;
        }

        //移动
        transform.Translate(Direction * Speed * Time.deltaTime, Space.World);

        //旋转
        transform.Rotate(Vector3.forward, RotateSpeed * Time.deltaTime, Space.World);

        //检测(存活/死亡)
        GameObject[] monsterObjects = GameObject.FindGameObjectsWithTag("Monster");

        foreach (GameObject monsterObject in monsterObjects)
        {
            Monster monster = monsterObject.GetComponent <Monster>();

            //忽略已死亡的怪物
            if (monster.IsDead)
            {
                continue;
            }

            if (Vector3.Distance(transform.position, monster.transform.position) <= 0.7f)
            {
                //敌人受伤
                monster.Damage((int)Attack);

                //爆炸
                Explode();

                //退出(重点)
                break;
            }
        }

        //边间检测
        if (!IsExploded && !MapRect.Contains(transform.position))
        {
            Explode();
        }
    }
Exemple #13
0
    // we need manager here because we call this method in prefab context
    public bool PrefabValidatePosition(Manager m, MapPoint point, CellRotation rotation)
    {
        manager = m;

        MapRect rect = GetCellIndexes(point, rotation);

        bool res = m.House.Phantom.PlacePhantom(point, rect);


        if (IsRectFree(rect, true) == false)
        {
            res = false;
        }


        return(res);
    }
        protected override void Update()
        {
            //已爆炸无需跟踪
            if (f_isExploded)
            {
                return;
            }

            //目标检测
            if (Target != null)
            {
                if (!Target.IsDead)
                {
                    //计算方向
                    Direction = (Target.transform.position - transform.position).normalized;
                }

                //角度
                LookAt();

                //移动
                transform.Translate(Direction * Speed * Time.deltaTime, Space.World);

                //打中目标
                if (Vector3.Distance(transform.position, Target.transform.position) <= FBConsts.DotClosedDistance)
                {
                    //敌人受伤
                    Target.Damage(Attack);

                    //爆炸
                    Explode();
                }
            }
            else
            {
                //移动
                transform.Translate(Direction * Speed * Time.deltaTime, Space.World);

                //边界检测
                if (!f_isExploded && !MapRect.Contains(transform.position))
                {
                    Explode();
                }
            }
        }
Exemple #15
0
        private void DrawItems(Graphics gfx, List <MapItem> items, Color color)
        {
            foreach (MapItem item in items)
            {
                MapRect rect = item.Bounds;

                if (item.IsLeaf())
                {
                    gfx.FillRectangle(new SolidBrush(((MapFile)item).Color), (int)rect.X, (int)rect.Y, (int)rect.W, (int)rect.H);
                    gfx.DrawRectangle(new Pen(Color.Black), (int)rect.X, (int)rect.Y, (int)rect.W, (int)rect.H);
                }
                else
                {
                    gfx.DrawRectangle(new Pen(color), (int)rect.X, (int)rect.Y, (int)rect.W, (int)rect.H);
                    DrawItems(gfx, item.Items, color);
                }
            }
        }
Exemple #16
0
    //returns true if this phantom already has been placed
    public bool PlacePhantom(MapPoint pos, MapRect rect)
    {
        LastPhantomPosition = pos;
        if (lastRect.Equals(rect))
        {
            return(true);
        }

        RemovePhantom();

        rect.Foreach((MapPoint p) => {
            InstantiatePhantom(p, true);
        });


        lastRect = new MapRect(rect);
        return(false);
    }
Exemple #17
0
    public bool IsRectFree(MapRect rect, bool usePhantom)
    {
        bool res = true;

        rect.Foreach((MapPoint p) => {
            CellController c = M.House.GetCell(p);
            if (c == null || c.CellObject != null)
            {
                res = false;
                if (usePhantom)
                {
                    M.House.Phantom.SetRedPhantom(p);
                }
            }

            if (p.X > rect.MinX && p.Y > rect.MinY)
            {
                WallController w = M.House.GetWall(new WallPoint(p.X, p.Y));
                if (w != null)
                {
                    res = false;
                }
            }
        });

        for (int x = rect.MinX + 1; x <= rect.MaxX; x++)
        {
            WallController w = M.House.GetWall(new WallPoint(x, rect.MinY));
            if (w != null && w.wallSprite.Top == true)
            {
                res = false;
            }
        }

        for (int y = rect.MinY + 1; y <= rect.MaxY; y++)
        {
            WallController w = M.House.GetWall(new WallPoint(rect.MinX, y));
            if (w != null && w.wallSprite.Right == true)
            {
                res = false;
            }
        }
        return(res);
    }
Exemple #18
0
    public bool IsRectFree(MapRect rect)
    {
        bool res = true;

        rect.Foreach((MapPoint p) => {
            LogicCell c = null;
            if (res && !LogicCells.TryGetValue(p.toInt(), out c))
            {
                res = false;
            }

            if (res && p.X > rect.MinX && p.Y > rect.MinY)
            {
                LogicWall w = null;
                if (Seg.LogicWalls.TryGetValue(new WallPoint(p.X, p.Y).toInt(), out w))
                {
                    res = false;
                }
            }
        });
        if (res)
        {
            for (int x = rect.MinX + 1; x <= rect.MaxX; x++)
            {
                LogicWall w = null;
                if (Seg.LogicWalls.TryGetValue(new WallPoint(x, rect.MinY).toInt(), out w) && w.Top)
                {
                    res = false;
                }
            }

            for (int y = rect.MinY + 1; y <= rect.MaxY; y++)
            {
                LogicWall w = null;
                if (Seg.LogicWalls.TryGetValue(new WallPoint(rect.MinX, y).toInt(), out w) && w.Right)
                {
                    res = false;
                }
            }
        }
        return(res);
    }
Exemple #19
0
    private void OnRemoveObject(Vector3 pz)
    {
        MapPoint       mp           = new MapPoint(Mathf.FloorToInt(pz.x), Mathf.FloorToInt(pz.y));
        CellController cellToRemove = null;

        if (cells.TryGetValue(mp.toInt(), out cellToRemove))
        {
            if (cellToRemove.CellObject != null)
            {
                M.UI.bCostsPanel.Expences.AddValue(-cellToRemove.CellObject.GetCost());
            }

            MapRect rect = cellToRemove.GetCellIndexes(cellToRemove.Position, cellToRemove.Rotation);
            rect.Foreach((MapPoint p) => {
                cells.Remove(p.toInt());
                EditorSetCell(p, CellPrefab);
            });
            Destroy(cellToRemove.gameObject);
        }
    }
Exemple #20
0
        public void ShouldAllowParallelMovement2()
        {
            // Arrange
            var r        = _player.Radius;
            var mapRect1 = new MapRect(4 * r, 0, 2 * r, 1000 * r);

            _mapState.MapObjects.Add(mapRect1);

            // Act
            _player.Keys = new List <KeyEnum> {
                KeyEnum.Down, KeyEnum.Right
            };
            for (var i = 1; i <= 200; i++)
            {
                _gameEngine.PhysicsEngine.ApplyPhysics();
            }

            // Assert
            Assert.IsTrue(_player.Position.X < _player.Position.Y);
        }
        public static bool CheckIntersection(MapRect b, MapCircle s)
        {
            var x = Math.Abs(s.Position.X - b.Position.X);
            var y = Math.Abs(s.Position.Y - b.Position.Y);

            if (x > b.Width / 2 + s.Radius ||
                y > b.Height / 2 + s.Radius)
            {
                return(false);
            }

            if (x <= b.Width / 2 || y <= b.Height / 2)
            {
                return(true);
            }

            var cornerDistance_sq = Math.Pow(x - b.Width / 2, 2) + Math.Pow(y - b.Height / 2, 2);

            return(cornerDistance_sq <= s.RadiusSquared);
        }
        public static Trace CheckBulletTrace(Ray ray, MapRect rect)
        {
            Trace closestTrace = null;

            var verticies = rect.GetVerticies();

            for (int i = 0; i < verticies.Length - 1; i++)
            {
                Trace trace = CheckBulletTrace(ray, verticies[i], verticies[i + 1]);
                if (trace != null && (closestTrace == null || trace.Distance < closestTrace.Distance))
                {
                    closestTrace = trace;
                }
            }

            if (closestTrace != null)
            {
                closestTrace.MapObject = rect;
            }

            return(closestTrace);
        }
Exemple #23
0
    protected override void Update()
    {
        base.Update();
        if (IsExploded)
        {
            return;
        }

        if (_target != null)
        {
            if (!_target.IsDead)
            {
                _direction = (_target.transform.position - transform.position).normalized;
            }

            //角度
            LookAt();

            //移动
            transform.Translate(_direction * Speed * Time.deltaTime, Space.World);

            //击中
            if (Vector3.Distance(_target.transform.position, transform.position) <= 0.1f)
            {
                _target.Damage((int)Attack);
                Explode();
            }
        }
        else
        {
            //移动中,monster被消灭
            transform.Translate(_direction * Speed * Time.deltaTime, Space.World);

            if (!MapRect.Contains(transform.position) && !IsExploded)
            {
                Explode();
            }
        }
    }
Exemple #24
0
        public void ShouldNotAllowPassingThroughWalls()
        {
            // Arrange
            var r       = _player.Radius;
            var mapRect = new MapRect(0, r * 2, 2, 2);

            _mapState.MapObjects.Add(mapRect);
            var config = new Config();

            // Act
            _player.Keys.Add(KeyEnum.Down);
            for (int i = 1; i <= 200; i++)
            {
                _gameEngine.PhysicsEngine.ApplyPhysics();

                var playerObject = new MapCircle(_player.Position, _player.Radius);
                Assert.IsFalse(Intersection.CheckIntersection(playerObject, mapRect));
            }

            // Assert
            Assert.AreNotEqual(_player.Position.Y, 0);
            Assert.AreEqual(_player.Position.Y, mapRect.Position.Y - (mapRect.Height / 2) - _player.Radius, config.IntersectionInterval);
        }
	public bool IsRectFree(MapRect rect, bool usePhantom)
	{
		bool res = true;
		rect.Foreach((MapPoint p) => {
			
			CellController c =M.House.GetCell(p);
			if(c==null || c.CellObject!=null)
			{
				res = false;
				if(usePhantom)
					M.House.Phantom.SetRedPhantom(p);
			}
			
			if(p.X>rect.MinX && p.Y>rect.MinY)
			{
				WallController w = M.House.GetWall(new WallPoint(p.X,p.Y));
				if(w!=null)
					res = false;
			}
			
		});
		
		for(int x = rect.MinX+1;x<=rect.MaxX;x++)
		{
			WallController w = M.House.GetWall(new WallPoint(x,rect.MinY));
			if(w!=null && w.wallSprite.Top==true)
				res = false;
		}
		
		for(int y = rect.MinY+1;y<=rect.MaxY;y++)
		{
			WallController w = M.House.GetWall(new WallPoint(rect.MinX,y));
			if(w!=null && w.wallSprite.Right==true)
				res = false;
		}
		return res;
	}
	public LogicVentshaft(MapRect objectRect, int cost) 
		: base(CellObjects.Ventshaft,objectRect,cost)
	{
		
	}
Exemple #27
0
	public LogicHob(MapRect objectRect, int cost) 
		: base(CellObjects.Hob,objectRect,cost)
	{
		
	}
Exemple #28
0
 public LogicHob(MapRect objectRect, int cost)
     : base(CellObjects.Hob, objectRect, cost)
 {
 }
Exemple #29
0
 public LogicFireplace(MapRect objectRect, int cost)
     : base(CellObjects.Fireplace, objectRect, cost)
 {
 }
	public LogicBoiler(MapRect objectRect, int cost) 
		: base(CellObjects.Boiler,objectRect,cost)
	{
	
	}
Exemple #31
0
 public LogicHeater(MapRect objectRect, int cost)
     : base(CellObjects.Heater, objectRect, cost)
 {
 }
        private void CalculateBounds()
        {
            int weight = GameConstants.MinVoxelActorWeight;
            int size   = m_map.GetMapSizeWith(weight);

            Debug.Assert(size >= m_minMapBoundsSize, "map size < m_minMapBoundsSize");

            MapPos min = new MapPos(0, 0);
            MapPos max = new MapPos(size - 1, size - 1);

            MapCell col0 = m_map.Get(0, 0, weight);

            for (int row = 0; row < size; ++row)
            {
                MapCell cell     = col0;
                bool    nonEmpty = false;
                for (int col = 0; col < size; ++col)
                {
                    nonEmpty = IsNonEmpty(cell);
                    if (nonEmpty)
                    {
                        break;
                    }
                    cell = cell.SiblingPCol;
                }

                if (nonEmpty)
                {
                    min.Row = row;
                    break;
                }
                else
                {
                    min.Row = row;
                }

                col0 = col0.SiblingPRow;
            }

            col0 = m_map.Get(size - 1, 0, weight);
            for (int row = size - 1; row >= 0; --row)
            {
                MapCell cell     = col0;
                bool    nonEmpty = false;
                for (int col = 0; col < size; ++col)
                {
                    nonEmpty = IsNonEmpty(cell);
                    if (nonEmpty)
                    {
                        break;
                    }
                    cell = cell.SiblingPCol;
                }

                if (nonEmpty)
                {
                    max.Row = row;
                    break;
                }
                else
                {
                    max.Row = row;
                }

                col0 = col0.SiblingMRow;
            }

            MapCell row0 = m_map.Get(0, 0, weight);

            for (int col = 0; col < size; ++col)
            {
                MapCell cell     = row0;
                bool    nonEmpty = false;
                for (int row = 0; row < size; ++row)
                {
                    nonEmpty = IsNonEmpty(cell);
                    if (nonEmpty)
                    {
                        break;
                    }
                    cell = cell.SiblingPRow;
                }

                if (nonEmpty)
                {
                    min.Col = col;
                    break;
                }
                else
                {
                    min.Col = col;
                }

                row0 = row0.SiblingPCol;
            }

            row0 = m_map.Get(0, size - 1, weight);
            for (int col = size - 1; col >= 0; --col)
            {
                MapCell cell     = row0;
                bool    nonEmpty = false;
                for (int row = 0; row < size; ++row)
                {
                    nonEmpty = IsNonEmpty(cell);
                    if (nonEmpty)
                    {
                        break;
                    }
                    cell = cell.SiblingPRow;
                }

                if (nonEmpty)
                {
                    max.Col = col;
                    break;
                }
                else
                {
                    max.Col = col;
                }

                row0 = row0.SiblingMCol;
            }

            if (min.Col > max.Col)
            {
                min.Col = max.Col;
            }

            if (min.Row > max.Row)
            {
                min.Row = max.Row;
            }

            int centerCol = min.Col + (max.Col - min.Col) / 2;
            int centerRow = min.Row + (max.Row - min.Row) / 2;

            int minCol = Mathf.Max(0, centerCol - m_minMapBoundsSize / 2);
            int minRow = Mathf.Max(0, centerRow - m_minMapBoundsSize / 2);

            int maxCol = minCol + m_minMapBoundsSize;
            int maxRow = minRow + m_minMapBoundsSize;

            if (maxCol >= size)
            {
                maxCol = size - 1;
                minCol = maxCol - m_minMapBoundsSize;
            }

            if (maxRow >= size)
            {
                maxRow = size - 1;
                minRow = maxRow - m_minMapBoundsSize;
            }

            if (minCol < min.Col)
            {
                min.Col = minCol;
            }
            if (minRow < min.Row)
            {
                min.Row = minRow;
            }
            if (maxCol > max.Col)
            {
                max.Col = maxCol;
            }
            if (maxRow > max.Row)
            {
                max.Row = maxRow;
            }


            m_mapBounds = new MapRect(min, max);
        }
	public ILogicObject(CellObjects objectType, MapRect objectRect, int cost)
	{
		ObjectType = objectType;
		ObjectRect = objectRect;
		Cost = cost;
	}
Exemple #34
0
 public LogicBathtub(MapRect objectRect, int cost)
     : base(CellObjects.Bathtub, objectRect, cost)
 {
     HasHotWater = false;
 }
Exemple #35
0
	public LogicRiser(MapRect objectRect, int cost) 
		: base(CellObjects.Riser,objectRect,cost)
	{
	
	}
	public LogicHeater(MapRect objectRect, int cost) 
		: base(CellObjects.Heater,objectRect,cost)
	{
		
	}
Exemple #37
0
 public LogicHeatingPipe(MapRect objectRect, int cost)
     : base(CellObjects.HeatingPipe, objectRect, cost)
 {
 }
Exemple #38
0
	public LogicSink(MapRect objectRect, int cost) 
		: base(CellObjects.Sink,objectRect,cost)
	{
		HasHotWater = false;
	}
	public LogicFireplace(MapRect objectRect, int cost) 
		: base(CellObjects.Fireplace,objectRect,cost)
	{
	
	}
	public LogicHeatingPipe(MapRect objectRect, int cost) 
		: base(CellObjects.HeatingPipe,objectRect,cost)
	{
		
	}
Exemple #41
0
	public MapRect(MapRect copy)
	{
		p1 = new MapPoint(copy.p1);
		p2 = new MapPoint(copy.p2);
	}
	public LogicBathtub(MapRect objectRect, int cost) 
		: base(CellObjects.Bathtub,objectRect,cost)
	{
		HasHotWater = false;
	}
	public LogicShower(MapRect objectRect, int cost) 
		: base(CellObjects.Shower,objectRect,cost)
	{
		HasHotWater = false;
	}
	public LogicToilet(MapRect objectRect, int cost) 
		: base(CellObjects.Toilet,objectRect,cost)
	{
		
	}
Exemple #45
0
    public void Launch(LevelConditions conditions, Dictionary <int, CellController> cells,
                       Dictionary <int, WallController> walls)
    {
        rooms.Clear();
        processed.Clear();
        Doors.Clear();
        LCache.Clear();
        LogicCells.Clear();
        Conditions = conditions;

        // Filling logic walls
        foreach (WallController w in walls.Values)
        {
            LogicWalls[w.Position.toInt()] = new LogicWall(w.Position, w.wallSprite.Top,
                                                           w.wallSprite.Bottom,
                                                           w.wallSprite.Left,
                                                           w.wallSprite.Right);
        }

        // Filling logic cells
        foreach (CellController cell in cells.Values)
        {
            if (LogicCells.ContainsKey(cell.Position.toInt()))
            {
                continue;
            }
            LogicCells.Add(cell.Position.toInt(), new LogicCell(cell.Position));
            if (cell.SizeX > 1 || cell.SizeY > 1)
            {
                MapRect rect = cell.GetCurCellIndexes();
                rect.Foreach((MapPoint p) => {
                    if (!LogicCells.ContainsKey(p.toInt()))
                    {
                        LogicCells.Add(p.toInt(), new LogicCell(p));
                    }
                });
            }
        }

        // Calculating reaches
        foreach (LogicCell cell in LogicCells.Values)
        {
            WallController w = null;
            LogicCell      c = null;


            //left
            c = GetLogicCell(cell.Position.X - 1, cell.Position.Y);
            w = GetWall(cell.Position.X, cell.Position.Y);
            if (c != null && (w == null || w.wallSprite.Top == false))
            {
                cell.ReachableCells.Add(c);
            }


            //right
            c = GetLogicCell(cell.Position.X + 1, cell.Position.Y);
            w = GetWall(cell.Position.X + 1, cell.Position.Y + 1);
            if (c != null && (w == null || w.wallSprite.Bottom == false))
            {
                cell.ReachableCells.Add(c);
            }

            //top
            c = GetLogicCell(cell.Position.X, cell.Position.Y + 1);
            w = GetWall(cell.Position.X + 1, cell.Position.Y + 1);
            if (c != null && (w == null || w.wallSprite.Left == false))
            {
                cell.ReachableCells.Add(c);
            }

            //bottom
            c = GetLogicCell(cell.Position.X, cell.Position.Y - 1);
            w = GetWall(cell.Position.X, cell.Position.Y);
            if (c != null && (w == null || w.wallSprite.Right == false))
            {
                cell.ReachableCells.Add(c);
            }


            cell.AdjacentWalls += GetWall(cell.Position.X, cell.Position.Y) == null?0:1;
            cell.AdjacentWalls += GetWall(cell.Position.X + 1, cell.Position.Y) == null?0:1;
            cell.AdjacentWalls += GetWall(cell.Position.X, cell.Position.Y + 1) == null?0:1;
            cell.AdjacentWalls += GetWall(cell.Position.X + 1, cell.Position.Y + 1) == null?0:1;
        }
        // Finding Rooms
        curRoom = new Room(this);
        foreach (LogicCell cell in LogicCells.Values)
        {
            if (processed.Contains(cell))
            {
                continue;
            }
            Next(cell);
            if (curRoom.Size > 0)
            {
                rooms.Add(curRoom);
                Debug.Log(string.Format("Found room #{1} with {0} cells", curRoom.Size, curRoom.Number));
                curRoom        = new Room(this);
                curRoom.Number = rooms.Count;
            }
        }


        // STEP 2 - Recognize rooms
        Recognize();

        // STEP 3 - Calculate connections
        Connections();

        foreach (Room r in rooms)
        {
            M.Overlay.DrawRoom(r);
            Debug.Log(string.Format("Room #{0} is {1}, {2} objects", r.Number,
                                    Enum.GetName(typeof(RoomType), r.TypeOfRoom),
                                    r.LogicObjects.Count));
            foreach (Door d in r.Doors)
            {
                if (d.Rooms.Count == 1)
                {
                    Debug.Log(string.Format("  Room #{0} contains door that leads to nothing", r.Number));
                }
                else if (d.Rooms.Count == 2)
                {
                    Debug.Log(string.Format("  Room #{0} contains door that leads to room #{1}",
                                            r.Number, d.GetAnotherRoom(r).Number));
                }
                else
                {
                    Debug.Log(string.Format("  Buggy room #{0}", r.Number));
                }
            }
        }
        evaluator.Launch();
    }