// Start is called before the first frame update void Start() { BlockComponent = GetComponent <DataBlockComponent>(); Rotation = BlockComponent.DataBlock.Rotation; transform.eulerAngles = new Vector3(); TileScript = GetComponent <TileMovingObjectScript>(); TileScript.JumpToTile(BlockComponent.WorldTileX, BlockComponent.WorldTileY); if (BaseMotionSpeed == default) { if (BlockComponent.DataBlock.GetParameterByName <float>("MotionSpeed", out var param)) { BaseMotionSpeed = param.Value; } else { BaseMotionSpeed = 5; } } ChasingSpeed = BaseMotionSpeed * 2; if (BlockComponent.DataBlock.GetParameterByName <float>("Enemy_ChaseSpeed", out var data)) { ChasingSpeed = data.Value; } TileScript.MotionSpeed = BaseMotionSpeed; TileScript.CanMoveOverWorldReservedTiles = false; Rotator = GetComponentInChildren <AngleRotator>(); var loopSource = GetComponent <SoundLoader>().LoopStart("sb-bullyx", out _, true); // walking sound looped if (loopSource != null) { loopSource.volume = .25f; } }
void Patrol() { TileScript.MotionSpeed = BaseMotionSpeed; if (!TileScript.IsMoving) { bool[] attemptedRotations = new bool[] { false, false, false, false }; SRotation startingRotation = Rotation; for (int i = 0; i < 3; i++) // three tries to try walking { attemptedRotations[(int)Rotation] = true; if (MoveForward()) // try moving forward { break; } if (i != 2) { Rotation = GetRightLeft(startingRotation, i == 0); // check right, then left } else // else look behind { Rotation = GetBehind(startingRotation); if (!MoveForward()) // try to go backwards, if not, then freeze he's stuck { CurrentMode = EnemyMode.IDLE; break; } } } } }
public void StartProjectile(Vector2Int Position, SRotation Direction) { MovementScript = GetComponent <TileMovingObjectScript>(); MovementScript.MotionSpeed = 12f; MovementScript.SpecialObjectIgnore = true; MovementScript.JumpToTile(Position.x, Position.y); this.Direction = Direction; CanMove = true; particleSystem = GetComponentInChildren <ParticleSystem>(); if (particleSystem != default) { ParticleLoader.SetBurst(particleSystem, 4); } }
private void OnPushing(object sender, MoveEventArgs e) { if (Player.CurrentPlayer == Assets.Scripts.Game.PlayerEnum.SPONGEBOB) { if (!PushableScript.MovementAllowed) { return; } MoveScript.MoveInDirection(e.Direction); Direction = e.Direction; bouncing = true; } else { Destroy(); } }
private void TileMovingObjectScript_MoveableMoving(object sender, MoveEventArgs e) { if (e.ToTile != MoveScript.TilePosition) { return; } if ((sender as TileMovingObjectScript).gameObject != gameObject && (sender as TileMovingObjectScript).TryGetComponent <BeachBallBehavior>(out var ball)) { if (!PushableScript.MovementAllowed) { return; } MoveScript.MoveInDirection(e.Direction); Direction = e.Direction; bouncing = true; } }
bool StartChase() { var player = Player.Current; if (player == null) { return(false); } if (ShouldChase && LOSCheck(playerDirection, TileX, TileY, player.TileX, player.TileY)) { CurrentMode = EnemyMode.CHASE; Rotation = playerDirection; GetComponent <SoundLoader>().Play("sb-bully"); return(true); } return(false); }
public Vector2Int GetTileFromDirection(SRotation Direction, int Tiles = 1) { switch (Direction) { case StinkyFile.SRotation.NORTH: return(new Vector2Int(TileX, TileY - Tiles)); case StinkyFile.SRotation.SOUTH: return(new Vector2Int(TileX, TileY + Tiles)); case StinkyFile.SRotation.EAST: return(new Vector2Int(TileX + Tiles, TileY)); case StinkyFile.SRotation.WEST: return(new Vector2Int(TileX - Tiles, TileY)); } return(default);
void UpdatePlayerLocation() { shouldChasePlayer = false; Player player = Player.Current; if (player == null) { return; } bool isLeft, isRight, isUp, isDown; isLeft = player.TileX < TileX; isRight = player.TileX > TileX; isUp = player.TileY < TileY; isDown = player.TileY > TileY; if ((isLeft || isRight) && (!isUp & !isDown)) // Player is lined up in the X direction { if (isLeft) { playerDirection = SRotation.WEST; } if (isRight) { playerDirection = SRotation.EAST; } shouldChasePlayer = true; } if ((isUp || isDown) && (!isLeft & !isRight)) // Player is lined up in the Y direction { if (isUp) { playerDirection = SRotation.NORTH; } if (isDown) { playerDirection = SRotation.SOUTH; } shouldChasePlayer = true; } if (playerDirection == GetBehind(Rotation)) // if the player is behind them, they wont notice { shouldChasePlayer = false; } }
/// <summary> /// Looks left or right of the character depending on what mode it's in /// </summary> /// <param name="lookLeft"></param> static SRotation GetRightLeft(SRotation Rotation, bool lookRight = true) { bool Mode = lookRight; switch (Rotation) { case SRotation.NORTH: return(Mode ? SRotation.EAST : SRotation.WEST); case SRotation.EAST: return(Mode ? SRotation.SOUTH : SRotation.NORTH); case SRotation.SOUTH: return(Mode ? SRotation.WEST : SRotation.EAST); case SRotation.WEST: return(Mode ? SRotation.NORTH : SRotation.SOUTH); } return(SRotation.EAST); }
public void Rotate(SRotation rotation) { isRotating = true; yRotationStart = transform.localEulerAngles.y; percentage = 0f; switch (rotation) { case SRotation.SOUTH: if (yRotationStart > 180) { yRotationEnd = 360; } else { yRotationEnd = 0f; } break; case SRotation.NORTH: yRotationEnd = 180f; break; case SRotation.EAST: if (yRotationStart < 90) { yRotationStart = 360; } yRotationEnd = 270f; break; case SRotation.WEST: yRotationEnd = 90f; break; } yRotationEnd += RotationOffset; }
private static SRotation GetBehind(SRotation rotation) => TileMovingObjectScript.GetBehindDirection(rotation);
/// <summary> /// Line of sight checking in a certain direction until a certain point /// </summary> /// <returns></returns> bool LOSCheck(SRotation Direction, int FromX, int FromY, int ToX, int ToY) { int directionFrom = FromX, directionTo = ToX; switch (Direction) { case SRotation.NORTH: case SRotation.SOUTH: // set the endpoint to Y direction directionFrom = FromY; directionTo = ToY; break; case SRotation.WEST: case SRotation.EAST: // set the endpoint to X direction directionFrom = FromX; directionTo = ToX; break; } int currentPosX = FromX, currentPosY = FromY; World current = World.Current; if (current == null) { return(false); } int amountOfTimes = Math.Abs(directionTo - directionFrom); for (int i = 0; i < amountOfTimes; i++) { int change = Direction == SRotation.NORTH || Direction == SRotation.WEST ? -1 : 1; // the change per loop, -1 for left and up if (!current.TryGetBlockAt(BlockLayers.Integral, currentPosX, currentPosY, out var blockData)) { return(false); } bool isPassable = false; if (blockData.GetParameterByName("AllowMotion", out var blockParameter) && blockParameter.Value.ToLower() == "true") { isPassable = true; } if (blockData.GetParameterByName("FLOOR", out blockParameter) && blockParameter.Value.ToLower() == "true") // ran into a non-passable object { isPassable = true; } if (blockData.GetParameterByName("ServiceObject", out blockParameter) && blockParameter.Value.ToLower() == "true") // ran into a non-passable object { isPassable = true; } if (blockData.GetParameterByName("Bully_Ignore", out blockParameter) && blockParameter.Value.ToLower() == "true") { isPassable = true; } if (i > 0 && i < amountOfTimes) { if (isPassable && !current.IsTileReserved(currentPosX, currentPosY)) { isPassable = true; } else { isPassable = false; } } if (!isPassable) { return(false); } switch (Direction) { case SRotation.NORTH: case SRotation.SOUTH: // apply change in Y direction currentPosY += change; if (currentPosY == ToY) { return(true); } break; case SRotation.WEST: case SRotation.EAST: // apply change in X direction currentPosX += change; if (currentPosX == ToX) { return(true); } break; } } return(true); }
void FaceDirection(SRotation Direction) => Rotator.Rotate(Direction);