public void Setup(Vector2 startingPoint, ObjectDirection direction) { _startingPoint = startingPoint; BuildHallwayTriggers.Add(this); _midpoint = new Vector2(_startingPoint.x, _startingPoint.y + 7.5f); transform.position = Camera.main.WorldToScreenPoint(_midpoint); RectTransform rect = GetComponent <RectTransform>(); switch (direction) { case ObjectDirection.LeftDown: rect.Rotate(new Vector3(0, 0, 180)); break; case ObjectDirection.LeftUp: rect.Rotate(new Vector3(0, 0, 90)); break; case ObjectDirection.RightUp: break; case ObjectDirection.RightDown: rect.Rotate(new Vector3(0, 0, -90)); break; default: Logger.Error("Not implemented direction {0}", direction); break; } }
public WorldObject(int GivenX, int GivenY, WorldState GivenType, ObjectDirection GivenDirection) { X = GivenX; Y = GivenY; State = GivenType; Direction = GivenDirection; }
private void SetPointerLocomotionTarget(Vector2 target, ObjectDirection moveDirection) { //Logger.Warning($"SetPointerLocomotionTarget to target {target.x}, {target.y} in the direction {moveDirection}"); GridLocation targetGridLocation = GridLocation.FindClosestGridTile(target); if (!ValidateTarget(new TargetLocation(targetGridLocation, moveDirection))) { return; } Vector2 gridVectorTarget = GridLocation.GridToVector(targetGridLocation); if (CurrentGridLocation.X == targetGridLocation.X && CurrentGridLocation.Y == targetGridLocation.Y) { return; } if (!_animationHandler.InLocomotion) { _animationHandler.SetLocomotion(true); } IsCalculatingPath = true; PathToTarget = _pathfinding.FindNodePath(CurrentGridLocation, targetGridLocation); PathToTarget.RemoveAt(0); IsCalculatingPath = false; SetHasCalculatedTarget(true); }
public WorldObject(int GivenX, int GivenY, WorldState GivenType) { X = GivenX; Y = GivenY; State = GivenType; Direction = ObjectDirection.NULL; }
internal static MapPoint TransformPointDirection(MapPoint mpAccessPoint, ObjectDirection objectDirection) { switch (objectDirection) { case ObjectDirection.Down: return(mpAccessPoint); break; case ObjectDirection.Right: return(new MapPoint(mpAccessPoint.y * -1, mpAccessPoint.x)); break; case ObjectDirection.Up: return(new MapPoint(mpAccessPoint.x * -1, mpAccessPoint.y * -1)); break; case ObjectDirection.Left: return(new MapPoint(mpAccessPoint.y, mpAccessPoint.x * -1)); break; default: return(mpAccessPoint); break; } return(mpAccessPoint); }
private void setupWorld() { fillWithWalls(); //fillWithFloors(); // Dig a room in the center of the map fillRect(rows / 2, columns / 2, 5, 5, floorTiles); float startingTime = Time.realtimeSinceStartup; while (featuresCount < roomsNumber) { if (Time.realtimeSinceStartup - startingTime > timeAllowed) { Debug.Log("Allowed generation time is elapsed."); break; } ObjectDirection randomWall = levelMap.pickRandomWall(); if (randomWall == null) { return; } if (featureList[Random.Range(0, featureList.Count)](randomWall)) // Pick a random feature to build { featuresCount++; } } Debug.Log(roomsCount + " rooms were generated."); Debug.Log(corridorsCount + " corridors were generated."); }
public void SetDirection(ObjectDirection direction) { switch (direction) { case ObjectDirection.Down: SetHorizontal(0); SetVertical(-1f); break; case ObjectDirection.Left: SetHorizontal(-1f); SetVertical(0); break; case ObjectDirection.Right: SetHorizontal(1f); SetVertical(0); break; case ObjectDirection.Up: SetHorizontal(0); SetVertical(1f); break; default: Logger.Warning("Unhandled locomotion direction {0}", direction); break; } }
public void CreateBuildHallwayTrigger(Vector2 startingPoint, ObjectDirection direction) { BuildHallwayTrigger buildHallwayTrigger = GameManager.Instance.InstantiatePrefab( BuilderManager.Instance.BuildHallwayTriggerPrefab, MainCanvas.Instance.TriggersContainer.transform, startingPoint).GetComponent <BuildHallwayTrigger>(); buildHallwayTrigger.Setup(startingPoint, direction); }
public bool ValidateTarget(TargetLocation targetLocation) { if (GameManager.Instance.CurrentGameLevel.TilesByLocation.TryGetValue(targetLocation.TargetGridLocation, out Tile targetTile)) { ObjectDirection direction = targetLocation.TargetDirection; if (targetTile.Walkable) { Tile currentTile = GameManager.Instance.CurrentGameLevel.TilesByLocation[CurrentGridLocation]; BridgePiece bridgePieceOnCurrentTile = currentTile.TryGetBridgePiece(); BridgePiece bridgePieceOnTarget = targetTile.TryGetBridgePiece(); // optimisation: keep bridge locations of the level in a separate list, so we don't have to go over all the tiles in the level // there are no bridges involved if (bridgePieceOnCurrentTile == null && bridgePieceOnTarget == null) { return(true); } // Make sure we go in the correct bridge direction if (bridgePieceOnCurrentTile && bridgePieceOnTarget) { if (bridgePieceOnCurrentTile.BridgePieceDirection == BridgePieceDirection.Horizontal && bridgePieceOnTarget.BridgePieceDirection == BridgePieceDirection.Horizontal && (direction == ObjectDirection.Left || direction == ObjectDirection.Right)) { return(true); } if (bridgePieceOnCurrentTile.BridgePieceDirection == BridgePieceDirection.Vertical && bridgePieceOnTarget.BridgePieceDirection == BridgePieceDirection.Vertical && (direction == ObjectDirection.Up || direction == ObjectDirection.Down)) { return(true); } return(false); } if ((bridgePieceOnCurrentTile?.BridgePieceDirection == BridgePieceDirection.Horizontal || bridgePieceOnTarget?.BridgePieceDirection == BridgePieceDirection.Horizontal) && (direction == ObjectDirection.Left || direction == ObjectDirection.Right)) { return(true); } if ((bridgePieceOnCurrentTile?.BridgePieceDirection == BridgePieceDirection.Vertical || bridgePieceOnTarget?.BridgePieceDirection == BridgePieceDirection.Vertical) && (direction == ObjectDirection.Up || direction == ObjectDirection.Down)) { return(true); } return(false); } } return(false); }
public int GetOriginY(ObjectDirection direction, int gridFactor) { float sizeScaleFactor = Editor.DEFAULT_GRID_FACTOR / (float)gridFactor; int originY = -GetHeight(direction, gridFactor) + gridFactor; originY -= (int)Math.Floor(ImagePosition[1] / sizeScaleFactor); return(originY); }
public int GetOriginX(ObjectDirection direction, int gridFactor) { float sizeScaleFactor = Editor.DEFAULT_GRID_FACTOR / (float)gridFactor; int originX = 0; originX += (int)Math.Floor(ImagePosition[0] / sizeScaleFactor); return(originX); }
public void MoveCharacter() { PathNode nextNode = PathToTarget[0]; GridLocation nextGridLocation = nextNode.Tile.GridLocation; GridLocation currentGridLocation = CurrentGridLocation; Vector3 moveDir; ObjectDirection direction = ObjectDirection.Right; if (nextGridLocation.X > currentGridLocation.X) { direction = ObjectDirection.Right; _animationHandler.SetDirection(direction); } else if (nextGridLocation.X < currentGridLocation.X) { direction = ObjectDirection.Left; _animationHandler.SetDirection(direction); } else if (nextGridLocation.Y > currentGridLocation.Y) { direction = ObjectDirection.Up; _animationHandler.SetDirection(direction); } else if (nextGridLocation.Y < currentGridLocation.Y) { direction = ObjectDirection.Down; _animationHandler.SetDirection(direction); } Vector2 targetVector2Pos = GridLocation.GridToVector(nextGridLocation); moveDir = (new Vector3(targetVector2Pos.x + GridLocation.OffsetToTileMiddle, targetVector2Pos.y + GridLocation.OffsetToTileMiddle, transform.position.z) - transform.position).normalized; float speed = 2.5f; transform.position = transform.position + moveDir * speed * Time.deltaTime; // Character reaches a tile grid location (its middle) if ((direction == ObjectDirection.Right && transform.position.x > targetVector2Pos.x + GridLocation.OffsetToTileMiddle) || (direction == ObjectDirection.Left && transform.position.x < targetVector2Pos.x + GridLocation.OffsetToTileMiddle) || (direction == ObjectDirection.Down && transform.position.y < targetVector2Pos.y + GridLocation.OffsetToTileMiddle) || direction == ObjectDirection.Up && transform.position.y > targetVector2Pos.y + GridLocation.OffsetToTileMiddle) { SetCurrentGridLocation(nextGridLocation); PathToTarget.RemoveAt(0); //Logger.Log($"New Grid location{currentGridLocation.X}, {currentGridLocation.Y}. Remaining path length is {PathToTarget.Count}"); if (PathToTarget.Count == 0) { OnTargetReached(); } return; } }
public bool ValidateForBridge(PathNode currentNode, PathNode targetNode, ObjectDirection direction) { Tile targetTile = targetNode.Tile; Tile currentTile = currentNode.Tile; if (targetTile.Walkable) { BridgePiece bridgePieceOnCurrentTile = currentTile.TryGetBridgePiece(); BridgePiece bridgePieceOnTarget = targetTile.TryGetBridgePiece(); // optimisation: keep bridge locations of the level in a separate list, so we don't have to go over all the tiles in the level // there are no bridges involved if (bridgePieceOnCurrentTile == null && bridgePieceOnTarget == null) { return(true); } // Make sure we go in the correct bridge direction if (bridgePieceOnCurrentTile && bridgePieceOnTarget) { if (bridgePieceOnCurrentTile.BridgePieceDirection == BridgePieceDirection.Horizontal && bridgePieceOnTarget.BridgePieceDirection == BridgePieceDirection.Horizontal && (direction == ObjectDirection.Left || direction == ObjectDirection.Right)) { return(true); } if (bridgePieceOnCurrentTile.BridgePieceDirection == BridgePieceDirection.Vertical && bridgePieceOnTarget.BridgePieceDirection == BridgePieceDirection.Vertical && (direction == ObjectDirection.Up || direction == ObjectDirection.Down)) { return(true); } return(false); } if ((bridgePieceOnCurrentTile?.BridgePieceDirection == BridgePieceDirection.Horizontal || bridgePieceOnTarget?.BridgePieceDirection == BridgePieceDirection.Horizontal) && (direction == ObjectDirection.Left || direction == ObjectDirection.Right)) { return(true); } if ((bridgePieceOnCurrentTile?.BridgePieceDirection == BridgePieceDirection.Vertical || bridgePieceOnTarget?.BridgePieceDirection == BridgePieceDirection.Vertical) && (direction == ObjectDirection.Up || direction == ObjectDirection.Down)) { return(true); } return(false); } return(false); }
/// <summary> /// Create a corridor starting at the specified wall /// </summary> /// <param name="wall"></param> /// <returns></returns> private bool createCorridor(ObjectDirection wall) { int corridorLength = Random.Range(1, corridorMaxLength + 1); if (!checkCorridor(wall, corridorLength)) { return(false); } digCorridor(wall, corridorLength); return(true); }
private bool createRoom(ObjectDirection wall) { int roomWidth = Random.Range(roomSize.minimum, roomSize.maximum + 1); int roomHeight = Random.Range(roomSize.minimum, roomSize.maximum + 1); Vector2i roomOffset = new Vector2i(Random.Range(0, roomWidth), Random.Range(0, roomHeight)); Vector2i roomOrigin = new Vector2i(0, 0); //Debug.Log("Chose the wall at " + wall.x + ","+wall.y); switch (wall.getDirection()) { case Direction.UP: roomOrigin.x = wall.x - roomWidth + 1 + roomOffset.x; roomOrigin.y = wall.y + 1; break; case Direction.RIGHT: roomOrigin.x = wall.x + 1; roomOrigin.y = wall.y - roomOffset.y; break; case Direction.LEFT: roomOrigin.x = wall.x - roomWidth; roomOrigin.y = wall.y - roomOffset.y; break; case Direction.DOWN: roomOrigin.x = wall.x - roomOffset.x; roomOrigin.y = wall.y - roomHeight; break; default: Debug.LogError("Unknown Direction found: " + wall.getDirection().ToString()); break; } // Check if the rectangle is available (filled with walls) if (!checkRect(roomOrigin.x - spaceBetweenRooms, roomOrigin.y - spaceBetweenRooms, roomWidth + spaceBetweenRooms * 2, roomHeight + spaceBetweenRooms * 2, "Wall")) { return(false); } //Debug.Log("room Origin: " + roomOrigin.ToString()); // If so, create a room fillRect(roomOrigin.x, roomOrigin.y, roomWidth, roomHeight, floorTiles); // Create the entrace fillRect(wall.x, wall.y, 1, 1, floorTiles); roomsCount++; return(true); }
public MapObject(MapPoint pBasePoint, MapPoint[] pArea, string strObjectName, eObjectType eType, MapPoint[] pPathWays, int iObjectValue, MapPoint mpAccessPoint, string strRotation, ObjectDirection objDir, bool bShouldGuarded) { PathWays = pPathWays; BasePoint = pBasePoint; Area = pArea; strName = strObjectName; ObjectSpacificProperties = new Dictionary <string, string>(); this.Type = eType; iValue = iObjectValue; AccessPoint = mpAccessPoint; Rotation = strRotation; this.objdirDirection = objDir; bShouldBeGuarded = bShouldGuarded; }
private void digCorridor(ObjectDirection wall, int corridorLength) { int x = wall.x; int y = wall.y; for (int i = 0; i < corridorLength; i++) { levelMap.createTile(x, y, floorTiles); x += wall.direction.x; y += wall.direction.y; } corridorsCount++; }
private void CheckPointerInput() { if (HasCalculatedTarget) { return; } Vector2 tempFingerPosition = Camera.main.ScreenToWorldPoint(Input.mousePosition); GridLocation closestGridLocation = GridLocation.FindClosestGridTile(tempFingerPosition); if (closestGridLocation.X == CurrentGridLocation.X && closestGridLocation.Y == CurrentGridLocation.Y) { return; } GridLocation newLocomotionTarget = CurrentGridLocation; Vector2 direction = tempFingerPosition - (Vector2)transform.position; float angle = Vector2.SignedAngle(Vector2.up, direction) * -1; new GridLocation(CurrentGridLocation.X, CurrentGridLocation.Y); ObjectDirection moveDirection = ObjectDirection.Right; if (angle <= -135) // go down { newLocomotionTarget = new GridLocation(CurrentGridLocation.X, CurrentGridLocation.Y - 1); moveDirection = ObjectDirection.Down; } else if (angle <= -45) // go left { newLocomotionTarget = new GridLocation(CurrentGridLocation.X - 1, CurrentGridLocation.Y); moveDirection = ObjectDirection.Left; } else if (angle <= 45) // go up { newLocomotionTarget = new GridLocation(CurrentGridLocation.X, CurrentGridLocation.Y + 1); moveDirection = ObjectDirection.Up; } else if (angle <= 135) // go right { newLocomotionTarget = new GridLocation(CurrentGridLocation.X + 1, CurrentGridLocation.Y); moveDirection = ObjectDirection.Right; } else // go down { newLocomotionTarget = new GridLocation(CurrentGridLocation.X, CurrentGridLocation.Y - 1); moveDirection = ObjectDirection.Down; } SetPointerLocomotionTarget(GridLocation.GridToVector(newLocomotionTarget), moveDirection); }
internal bool IsPointInDirectionCompareToPoint(MapPoint mpBasePoint, ObjectDirection objectDirection) { switch (objectDirection) { case ObjectDirection.Down: if (this.y < mpBasePoint.y) { return(true); } else { return(false); } case ObjectDirection.Right: if (this.x > mpBasePoint.x) { return(true); } else { return(false); } case ObjectDirection.Up: if (this.y > mpBasePoint.y) { return(true); } else { return(false); } case ObjectDirection.Left: if (this.x < mpBasePoint.x) { return(true); } else { return(false); } default: return(false); } }
public int GetHeight(ObjectDirection direction, int gridFactor) { float sizeScaleFactor = Editor.DEFAULT_GRID_FACTOR / (float)gridFactor; ObjectFrames frames; if (direction == ObjectDirection.DIRECTION_LEFT && LeftFrames != null) { frames = LeftFrames; } else { frames = RightFrames; } return((int)Math.Ceiling(frames.FrameGrid.Size[1] / sizeScaleFactor)); }
//dwp добавлена вероятность public MapObject(MapPoint pBasePoint, MapPoint[] pArea, string strObjectName, eObjectType eType, MapPoint[] pPathWays, int iObjectValue, MapPoint mpAccessPoint, string strRotation, ObjectDirection objDir, bool bShouldGuarded, int max_number, double probability) { PathWays = pPathWays; BasePoint = pBasePoint; Area = pArea; strName = strObjectName; ObjectSpacificProperties = new Dictionary <string, string>(); this.Type = eType; iValue = iObjectValue; AccessPoint = mpAccessPoint; Rotation = strRotation; this.objdirDirection = objDir; bShouldBeGuarded = bShouldGuarded; max_number_ = max_number; //dwp инициализация вероятности и текущего количества. probability_ = probability; current_number = 0; }
private bool createCorridorWithRoom(ObjectDirection wall) { // First, check if a corridor can be put there int corridorLength = Random.Range(1, corridorMaxLength + 1); if (!checkCorridor(wall, corridorLength)) { return(false); } // If the corridor is ok, we check if we can put a room ObjectDirection roomEntrace = new ObjectDirection(levelMap.getTile(wall.x + wall.direction.x * (corridorLength - 1), wall.y + wall.direction.y * (corridorLength - 1)), wall.direction); if (!createRoom(roomEntrace)) { return(false); } digCorridor(wall, corridorLength); return(true); }
private void createTorchs() { Transform torchHolder = new GameObject("Torches").transform; int torchPlaced = 0; float startingTime = Time.realtimeSinceStartup; while (torchPlaced < torchNumber) { if (Time.realtimeSinceStartup - startingTime > 1.0f) // Avoid infinite loops { Debug.Log("Max time elapsed for torch creation"); break; } ObjectDirection wall = levelMap.pickRandomWall(); if (levelMap.hasItemAround(wall.gameObject.transform.position, "Torch", distanceBetweenTorchs)) { continue; } Vector3 torchPosition; if (wall.direction.y != 1) { torchPosition = wall.gameObject.transform.position - wall.direction.toVector3() * 0.5f; } else { torchPosition = wall.gameObject.transform.position; } GameObject newTorch = Instantiate(torch, torchPosition, Quaternion.identity) as GameObject; if (wall.direction.x == -1) { newTorch.transform.localScale = new Vector3(-1, 1, 1); } newTorch.transform.SetParent(torchHolder); torchPlaced++; } }
/// <summary> /// Check if the corridor is feasible /// </summary> /// <param name="wall"></param> /// <param name="length"></param> /// <returns></returns> protected bool checkCorridor(ObjectDirection wall, int length) { Count xRange = new Count(1, 1); Count yRange = new Count(1, 1); switch (wall.getDirection()) { case Direction.UP: case Direction.DOWN: xRange = new Count(wall.x - spaceBetweenCorridors, wall.x + spaceBetweenCorridors); yRange = new Count(wall.y, wall.y); break; case Direction.LEFT: case Direction.RIGHT: xRange = new Count(wall.x, wall.x); yRange = new Count(wall.y - spaceBetweenCorridors, wall.y + spaceBetweenCorridors); break; } for (int startingX = xRange.minimum; startingX <= xRange.maximum; startingX++) { for (int startingY = yRange.minimum; startingY <= yRange.maximum; startingY++) { int x = startingX; int y = startingY; for (int i = 0; i < length + spaceBetweenCorridors; i++) { GameObject obj = levelMap.getTile(x, y); if (obj == null || !obj.CompareTag("Wall")) { return(false); } x += wall.direction.x; y += wall.direction.y; } } } return(true); }
public static bool DrawObject(StarboundObject obj, int x, int y, ObjectOrientation orientation, ObjectDirection direction, int gridFactor, Graphics gfx, float opacity) { if (obj.Image == null) { return(false); } Image objImage = orientation.RightImage; if (direction == ObjectDirection.DIRECTION_LEFT) { objImage = orientation.LeftImage; } int sizeX = orientation.GetWidth(direction, gridFactor); int sizeY = orientation.GetHeight(direction, gridFactor); int originX = orientation.GetOriginX(direction, gridFactor); int originY = orientation.GetOriginY(direction, gridFactor); var colourMatrix = new ColorMatrix(); colourMatrix.Matrix33 = opacity; var attributes = new ImageAttributes(); attributes.SetColorMatrix(colourMatrix); // Fix this, scaling on colour map gfx.DrawImage(objImage, new Rectangle( (x * gridFactor) + originX, (y * gridFactor) + originY, sizeX, sizeY), 0, 0, sizeX, sizeY, GraphicsUnit.Pixel, attributes); return(true); }
/// <summary> /// Check if the corridor is feasible /// </summary> /// <param name="wall"></param> /// <param name="length"></param> /// <returns></returns> protected bool checkCorridor(ObjectDirection wall, int length) { Count xRange = new Count(1, 1); Count yRange = new Count(1, 1); switch (wall.getDirection()) { case Direction.UP: case Direction.DOWN: xRange = new Count(wall.x - spaceBetweenCorridors, wall.x + spaceBetweenCorridors); yRange = new Count(wall.y, wall.y); break; case Direction.LEFT: case Direction.RIGHT: xRange = new Count(wall.x, wall.x); yRange = new Count(wall.y - spaceBetweenCorridors, wall.y + spaceBetweenCorridors); break; } for (int startingX = xRange.minimum; startingX <= xRange.maximum; startingX++) { for (int startingY = yRange.minimum; startingY <= yRange.maximum; startingY++) { int x = startingX; int y = startingY; for (int i = 0; i < length+spaceBetweenCorridors; i++) { GameObject obj = levelMap.getTile(x, y); if (obj == null || !obj.CompareTag("Wall")) { return false; } x += wall.direction.x; y += wall.direction.y; } } } return true; }
public ObjectOrientation GetCorrectOrientation(EditorMap map, int x, int y, ObjectDirection direction) { EditorMapPart part = null; if (map is EditorMapPart) { part = (EditorMapPart) map; } else if (map is EditorMapLayer) { part = ((EditorMapLayer) map).Parent; } // This is inherently flawed as it does not take into account the // anchor position of objects. TODO Fix this at some point foreach (ObjectOrientation orientation in Orientations) { List<string> anchors = orientation.Anchors; // TODO implement fgAnchor if (anchors == null) continue; if (anchors.Contains("top") && !CheckCollisionMapAtOffset(part, x, y - orientation.GetHeight(1))) continue; if (anchors.Contains("left") && !CheckCollisionMapAtOffset(part, x - 1, y)) continue; if (anchors.Contains("right") && !CheckCollisionMapAtOffset(part, x + 1, y)) continue; if (anchors.Contains("bottom") && !CheckCollisionMapAtOffset(part, x, y + orientation.GetHeight(1))) continue; if (orientation.Direction == "left" && direction != ObjectDirection.DIRECTION_LEFT) continue; if (orientation.Direction == "right" && direction != ObjectDirection.DIRECTION_RIGHT) continue; //if ( anchors.Contains("background") ) // return orientation; return orientation; } return Orientations.FirstOrDefault(); }
// Create a game object and set its starting position and speed GameObject Initialise(GameObject prefab, ObjectDirection objectDirection) { GameObject gameObject = Instantiate(prefab) as GameObject; gameObject.transform.position = objectDirection.start; switch (objectDirection.direction) { case Direction.Up: gameObject.GetComponent<Rigidbody2D>().velocity = new Vector2(0, 1) * objectDirection.speed; break; case Direction.Down: gameObject.GetComponent<Rigidbody2D>().velocity = new Vector2(0, -1) * objectDirection.speed; if (prefab == basicEnemyPrefab) { gameObject.transform.Rotate(Vector3.forward, 180); } break; case Direction.Left: gameObject.GetComponent<Rigidbody2D>().velocity = new Vector2(-1, 0) * objectDirection.speed; if (prefab == basicEnemyPrefab) { gameObject.transform.Rotate(Vector3.forward, 90); } break; case Direction.Right: gameObject.GetComponent<Rigidbody2D>().velocity = new Vector2(1, 0) * objectDirection.speed; if (prefab == basicEnemyPrefab) { gameObject.transform.Rotate(Vector3.forward, -90); } break; } return gameObject; }
public TargetLocation(GridLocation targetGridLocation, ObjectDirection targetDirection) { TargetGridLocation = targetGridLocation; TargetDirection = targetDirection; }
private bool createRoom(ObjectDirection wall) { int roomWidth = Random.Range(roomSize.minimum, roomSize.maximum+1); int roomHeight = Random.Range(roomSize.minimum, roomSize.maximum+1); Vector2i roomOffset = new Vector2i(Random.Range(0, roomWidth), Random.Range(0, roomHeight)); Vector2i roomOrigin = new Vector2i(0, 0); //Debug.Log("Chose the wall at " + wall.x + ","+wall.y); switch(wall.getDirection()) { case Direction.UP: roomOrigin.x = wall.x - roomWidth + 1 + roomOffset.x; roomOrigin.y = wall.y + 1; break; case Direction.RIGHT: roomOrigin.x = wall.x + 1; roomOrigin.y = wall.y - roomOffset.y; break; case Direction.LEFT: roomOrigin.x = wall.x - roomWidth; roomOrigin.y = wall.y - roomOffset.y; break; case Direction.DOWN: roomOrigin.x = wall.x - roomOffset.x; roomOrigin.y = wall.y - roomHeight; break; default: Debug.LogError("Unknown Direction found: " + wall.getDirection().ToString()); break; } // Check if the rectangle is available (filled with walls) if (!checkRect(roomOrigin.x-spaceBetweenRooms, roomOrigin.y-spaceBetweenRooms, roomWidth+ spaceBetweenRooms*2, roomHeight+ spaceBetweenRooms*2, "Wall")) return false; //Debug.Log("room Origin: " + roomOrigin.ToString()); // If so, create a room fillRect(roomOrigin.x, roomOrigin.y, roomWidth, roomHeight, floorTiles); // Create the entrace fillRect(wall.x, wall.y, 1, 1, floorTiles); roomsCount++; return true; }
public void TryStartCharacterMovement(ObjectDirection direction) { // check if character is in tile position, if so, start movement in direction. if (HasCalculatedTarget) { // if already in locomotion, it means that we are between tiles and we are moving. Return. return; } if (IsCalculatingPath) { return; } GridLocation currentGridLocation = GridLocation.VectorToGrid(transform.position); //Order character to go to another tile _animationHandler.SetDirection(direction); switch (direction) { case ObjectDirection.Down: TargetGridLocation = new TargetLocation(new GridLocation(currentGridLocation.X, currentGridLocation.Y - 1), direction); break; case ObjectDirection.Left: TargetGridLocation = new TargetLocation(new GridLocation(currentGridLocation.X - 1, currentGridLocation.Y), direction); break; case ObjectDirection.Right: TargetGridLocation = new TargetLocation(new GridLocation(currentGridLocation.X + 1, currentGridLocation.Y), direction); break; case ObjectDirection.Up: TargetGridLocation = new TargetLocation(new GridLocation(currentGridLocation.X, currentGridLocation.Y + 1), direction); break; default: Logger.Warning("Unhandled locomotion direction {0}", direction); return; } if (!ValidateTarget(TargetGridLocation)) { // This prevents the character from displaying locomotion animation when walking into an unwalkable tile _animationHandler.SetLocomotion(false); return; } //Logger.Warning("Start path!"); IsCalculatingPath = true; //Logger.Log($"TryStartCharacterMovement. {CurrentGridLocation.X},{CurrentGridLocation.Y} to {TargetGridLocation.TargetGridLocation.X}, {TargetGridLocation.TargetGridLocation.Y}"); PathToTarget = _pathfinding.FindNodePath(CurrentGridLocation, TargetGridLocation.TargetGridLocation); PathToTarget.RemoveAt(0); IsCalculatingPath = false; SetHasCalculatedTarget(true); if (!_animationHandler.InLocomotion) { _animationHandler.SetLocomotion(true); } }
private bool createCorridorWithRoom(ObjectDirection wall) { // First, check if a corridor can be put there int corridorLength = Random.Range(1, corridorMaxLength + 1); if (!checkCorridor(wall, corridorLength)) return false; // If the corridor is ok, we check if we can put a room ObjectDirection roomEntrace = new ObjectDirection(levelMap.getTile(wall.x + wall.direction.x * (corridorLength-1), wall.y + wall.direction.y * (corridorLength-1)), wall.direction); if (!createRoom(roomEntrace)) return false; digCorridor(wall, corridorLength); return true; }
public static bool DrawObject(StarboundObject obj, int x, int y, ObjectOrientation orientation, ObjectDirection direction, Graphics gfx) { return(DrawObject(obj, x, y, orientation, direction, Editor.DEFAULT_GRID_FACTOR, gfx)); }
public int GetOriginY(int gridFactor = Editor.Editor.DEFAULT_GRID_FACTOR, ObjectDirection direction = ObjectDirection.DIRECTION_NONE) { var sizeScaleFactor = Editor.Editor.GetSizeScaleFactor(gridFactor); int originY = -GetHeight(gridFactor, direction) + gridFactor; originY -= (int) Math.Floor(ImagePosition.y/sizeScaleFactor); return originY; }
public int GetWidth(int gridFactor = Editor.Editor.DEFAULT_GRID_FACTOR, ObjectDirection direction = ObjectDirection.DIRECTION_NONE) { var manager = GetImageManager(direction); return manager != null ? manager.Frames.FrameGrid.GetWidth(gridFactor) : 0; }
public int GetOriginX(int gridFactor = Editor.Editor.DEFAULT_GRID_FACTOR, ObjectDirection direction = ObjectDirection.DIRECTION_NONE) { var sizeScaleFactor = Editor.Editor.GetSizeScaleFactor(gridFactor); int originX = 0; originX += (int) Math.Floor(ImagePosition.x/sizeScaleFactor); return originX; }
public ObjectImageManager GetImageManager(ObjectDirection direction) { ObjectImageManager manager = null; if ((direction == ObjectDirection.DIRECTION_LEFT || direction == ObjectDirection.DIRECTION_NONE) && LeftImage != null) manager = LeftImage; else if ((direction == ObjectDirection.DIRECTION_RIGHT || direction == ObjectDirection.DIRECTION_NONE) && RightImage != null) manager = RightImage; else if (MainImage != null) manager = MainImage; return manager; }
//public static bool DrawObject(StarboundObject obj, int x, int y, ObjectOrientation orientation, // ObjectDirection direction, int gridFactor, Graphics gfx, float opacity) public bool DrawObject(Graphics gfx, int x, int y, ObjectDirection direction, int gridFactor = Editor.Editor.DEFAULT_GRID_FACTOR, float opacity = 1.0f) { var manager = GetImageManager(direction); if (manager == null) { MessageBox.Show("Manager is null"); return false; } int sizeX = GetWidth(gridFactor, direction); int sizeY = GetHeight(gridFactor, direction); int originX = GetOriginX(gridFactor, direction); int originY = GetOriginY(gridFactor, direction); return manager.DrawObject(gfx, x, y, originX, originY, sizeX, sizeY, gridFactor, opacity); }
// Create a new ObjectDirection with the enemy starting location and direction ObjectDirection RandomSpawnLocation() { ObjectDirection objectDirection = new ObjectDirection(); switch (Random.Range(1, 5)) { case 1: objectDirection.direction = Direction.Up; break; case 2: objectDirection.direction = Direction.Down; break; case 3: objectDirection.direction = Direction.Left; break; case 4: objectDirection.direction = Direction.Right; break; } objectDirection.speed = Random.Range(GameData.Get.Level.MinEnemySpeed, GameData.Get.Level.MaxEnemySpeed); switch (objectDirection.direction) { case Direction.Up: objectDirection.start = new Vector2(Random.Range(0f, 1f), 0f); break; case Direction.Down: objectDirection.start = new Vector2(Random.Range(0f, 1f), 1f); break; case Direction.Left: objectDirection.start = new Vector2(1f, Random.Range(0f, 1f)); break; case Direction.Right: objectDirection.start = new Vector2(0f, Random.Range(0f, 1f)); break; } objectDirection.start = mainCamera.ViewportToWorldPoint(objectDirection.start); return objectDirection; }
/// <summary> /// Create a corridor starting at the specified wall /// </summary> /// <param name="wall"></param> /// <returns></returns> private bool createCorridor(ObjectDirection wall) { int corridorLength = Random.Range(1, corridorMaxLength + 1); if (!checkCorridor(wall, corridorLength)) return false; digCorridor(wall, corridorLength); return true; }
private void CreateThinBlock(MapObjectType isPlaced, ObjectDirection objectDirection, int i, int j) { }
public static bool DrawObject(StarboundObject obj, int x, int y, ObjectOrientation orientation, ObjectDirection direction, int gridFactor, Graphics gfx) { return(DrawObject(obj, x, y, orientation, direction, gridFactor, gfx, 1.0f)); }