/// <summary> /// 当たった部屋との位置修正 /// </summary> /// <param name="other">他の部屋</param> public void Hit(MapRoom other) { Direction direction = CheckDirection(other); //他の部屋のどの方向 //一マスずつ修正 switch (direction) { case Direction.Xplus: xCell += 1; break; case Direction.Xminus: xCell -= 1; break; case Direction.Zplus: zCell += 1; break; case Direction.Zminus: zCell -= 1; break; } //Debug 表示用 cube = new Cube( new Vector3(xCell, 0, zCell), new Vector3(widthCell / 2.0f, 0.5f, lengthCell / 2.0f), gameDevice); }
/// <summary> /// 別部屋との相対位置 /// </summary> /// <param name="other">他の部屋</param> /// <returns>別部屋のどの辺</returns> private Direction CheckDirection(MapRoom other) { Vector2 dir = new Vector2( //中心座標で計算 xCell - other.xCell, zCell - other.zCell); if (Math.Abs(dir.X) > Math.Abs(dir.Y)) //X軸の変化量がY軸より大きい場合 { if (dir.X > 0) //自分のXが相手のXより大きい場合 { return(Direction.Xplus); } else { return(Direction.Xminus); } } //Vector2で計算なのでYはZの代用 if (dir.Y > 0) //自分のZが相手のZより大きい場合 { return(Direction.Zplus); } return(Direction.Zminus); }
/// <summary> /// 廊下を追加 /// </summary> private void UpdateCreateHall() { foreach (Edge e in edges) { //線分の中点 Point center = new Point( (e.FirstPoint.X + e.SecondPoint.X) / 2, (e.FirstPoint.Y + e.SecondPoint.Y) / 2); //横 MapRoom hall = new MapRoom( halls.Count, Math.Abs(e.FirstPoint.X - e.SecondPoint.X) + 2, 2, center.X, e.SecondPoint.Y, gameDevice); hall.SetColor(Color.Blue); halls.Add(hall); //縦 hall = new MapRoom( halls.Count, 2, Math.Abs(e.FirstPoint.Y - e.SecondPoint.Y) + 2, e.FirstPoint.X, center.Y, gameDevice); hall.SetColor(Color.Blue); halls.Add(hall); } currentState = GenerateState.ChooseSubRoom; //次の段階へ移行 }
/// <summary> /// 部屋同士の当たり判定 /// </summary> /// <param name="other">他の部屋</param> /// <returns>当たっているか</returns> public bool RoomCollision(MapRoom other) { return(Rect().Intersects(other.Rect())); }