public override void RegisterSpawnpoint() { GridLocation = GridLocation.VectorToGrid(transform.position); if (EditorManager.InEditor) { return; } int registeredSpawnpoints = GameManager.Instance.CurrentGameLevel.PlayerCharacterSpawnpoints.Count; if (registeredSpawnpoints == 0) { GameManager.Instance.CurrentGameLevel.PlayerCharacterSpawnpoints.Add(PlayerNumber.Player1, this); } else if (registeredSpawnpoints == 1) { GameManager.Instance.CurrentGameLevel.PlayerCharacterSpawnpoints.Add(PlayerNumber.Player2, this); } else { Logger.Error($"Found {registeredSpawnpoints} registered spawnpoints, but there can be only a maximum of 2"); } Logger.Log(Logger.Initialisation, "Registered spawnpoint"); }
public override void RegisterSpawnpoint() { GridLocation = GridLocation.VectorToGrid(transform.position); if (EditorManager.InEditor) { return; } CharacterBlueprint = new CharacterBlueprint(EnemyType); MazeLevelGameplayManager.Instance.Level.EnemyCharacterSpawnpoints.Add(this); }
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); } }