// Update is called once per frame void Update() { //if (Input.GetMouseButtonDown(0)) //{ // Vector2[] path_v2 = AINavMeshGenerator.pathfinder.FindPath(transform.position, Camera.main.ScreenToWorldPoint(Input.mousePosition)); // List<Vector3> Poss = new List<Vector3>(); // foreach(Vector3 n in path_v2) // { // Poss.Add(n); // } // GetComponent<LineRenderer>().positionCount = Poss.Count; // GetComponent<LineRenderer>().SetPositions(Poss.ToArray()); //} Vector2[] TempPath_v2 = AINavMeshGenerator.pathfinder.FindPath(transform.position, target.transform.position); if (TempPath_v2 != null) { Path_v2 = TempPath_v2; List <Vector3> Poss = new List <Vector3>(); foreach (Vector3 n in TempPath_v2) { Poss.Add(n); } GetComponent <LineRenderer>().positionCount = Poss.Count; GetComponent <LineRenderer>().SetPositions(Poss.ToArray()); //rb.MovePosition(TempPath_v2[1]); move = true; } else { move = false; rb.velocity = Vector2.zero; } if (move) { Vector2 moveInput = Path_v2[1] - (Vector2)transform.position; Vector2 MoveVelocity = moveInput.normalized * Speed; rb.MovePosition((Vector2)transform.position + MoveVelocity * Time.fixedDeltaTime); if (Mathf.Abs(MoveVelocity.x) > Mathf.Abs(MoveVelocity.y)) { LastFacing = (MoveVelocity.x > 0) ? Facing.Right : Facing.Left; } else if (Mathf.Abs(MoveVelocity.x) < Mathf.Abs(MoveVelocity.y)) { LastFacing = (MoveVelocity.y > 0) ? Facing.Up : Facing.Down; } if (MoveVelocity == Vector2.zero) { animator.Play("Idle" + LastFacing.ToString()); } else { animator.Play("Walk" + LastFacing.ToString()); } } }
void FixedUpdate() { if (CharManager.Instance.MainChar.Hp <= 0) { animator.Play("Dead"); return; } if (Input.GetMouseButtonDown(0) && CanBite) { AttackFSM.SendEvent("Bite"); BiteTween = rb.DOMove(FollowPoint.position, 0.5f).OnPlay(BiteStart).OnComplete(BiteEnd).SetEase(Ease.OutCubic); MusicSystem.Instance.PlaySound(eSound.ZonbieHit); } if (!biting) { rb.MovePosition(rb.position + MoveVelocity * Time.fixedDeltaTime); if (MoveVelocity == Vector2.zero) { animator.Play("Idle" + LastFacing.ToString()); } else { animator.Play("Walk" + LastFacing.ToString()); } PlayerFacing(); } else { animator.Play("Attack" + LastFacing.ToString()); PlayerFacing(FollowPoint); } if (Input.GetKeyDown(KeyCode.L)) { transform.position += new Vector3(1, 0, 0); } if (Input.GetKeyDown(KeyCode.J)) { transform.position += new Vector3(-1, 0, 0); } if (Input.GetKeyDown(KeyCode.I)) { transform.position += new Vector3(0, 1, 0); } if (Input.GetKeyDown(KeyCode.K)) { transform.position += new Vector3(0, -1, 0); } }
/// <summary> /// Gets INI code for map building object. /// </summary> /// <returns>INI code for map object.</returns> public override string GetINICode() { List <string> values = new List <string> { Owner, ID, Health.ToString(), X.ToString(), Y.ToString(), Facing.ToString(), Tag, AISellable ? "1" : "0", AIRebuildable ? "1" : "0", Powered ? "1" : "0", UpgradeCount.ToString(), SpotlightMode.ToString(), Upgrades[0], Upgrades[1], Upgrades[2], AIRepairable ? "1" : "0", Nominal ? "1" : "0" }; return(string.Join(",", values)); }
public Tuple <int, int> Rotate() { Tuple <int, int> cellInFront = null; var initialDirection = Facing.ToString(); if (Facing == Direction.North) { Facing = Direction.East; cellInFront = new Tuple <int, int>(Position.Row + 1, Position.Column); } else if (Facing == Direction.East) { Facing = Direction.South; cellInFront = new Tuple <int, int>(Position.Row, Position.Column - 1); } else if (Facing == Direction.South) { Facing = Direction.West; cellInFront = new Tuple <int, int>(Position.Row - 1, Position.Column); } else if (Facing == Direction.West) { Facing = Direction.North; cellInFront = new Tuple <int, int>(Position.Row, Position.Column + 1); } Console.WriteLine("Rotated from {0} to {1}", initialDirection, Facing.ToString()); // return the cell which the player is facing after rotating 90 degrees return(cellInFront); }
public string Report() { // _logger.Info("In Report Command "); return(MandateIsPlaced("report it's position") ? $"{_x.Value},{_y.Value},{_facing.ToString().ToUpper()}" : "Robot's position cannot be reported until it has been placed on the table."); }
public string Report() { if (PacmanIsPlaced("report the position")) // placeover index = {0} { return(String.Format("Output: {0},{1},{2}", _x.Value, _y.Value, _facing.ToString().ToUpper())); // placeover index for X, Y, Facing } return(""); }
public string Report() { if (MandateIsPlaced("report it's position")) { return(String.Format("{0},{1},{2}", _x.Value, _y.Value, _facing.ToString().ToUpper())); } return(""); }
void Update() { if (m_Targets.Count == 0) { return; } fireT += Time.deltaTime; if (fireT >= m_Ticks[currentTickIndex] * m_TickDelay) { GameObject newBullet = Instantiate(bulletPrefab, shootAnchor.position, Quaternion.identity) as GameObject; Vector3Int worldTarget = myGrid.WorldToCell(transform.position) + m_Targets[currentTickIndex]; newBullet.GetComponent <Bullet>().SetTarget(myGrid.GetCellCenterWorld(worldTarget)); currentTickIndex++; if (audioSource != null) { audioSource.PlayOneShot(fireAudioClips[Random.Range(0, fireAudioClips.Count)]); } if (currentTickIndex >= m_Targets.Count) { currentTickIndex = 0; fireT = 0f; } } Vector2 delta = ((Vector2)(myGrid.GetCellCenterWorld(m_Targets[currentTickIndex]) - transform.position)).normalized; Facing newFacing = Facing.Left; if (Mathf.Abs(delta.x) > Mathf.Abs(delta.y)) { if (delta.x < 0) { newFacing = Facing.Left; } else { newFacing = Facing.Right; } } else { if (delta.y < 0) { newFacing = Facing.Down; } else { newFacing = Facing.Up; } } if (newFacing != facing) { facing = newFacing; animator.SetTrigger("turn_" + facing.ToString().ToLower()); } }
public override string ToString() { var minX = Map.Keys.Select(p => p.X).Min(); var minY = Map.Keys.Select(p => p.Y).Min(); var maxX = Map.Keys.Select(p => p.X).Max(); var maxY = Map.Keys.Select(p => p.Y).Max(); var map = new List <string>(); for (var y = minY; y <= maxY; y++) { var newLine = string.Empty; for (var x = minX; x <= maxX; x++) { var point = new Point(x, y); var isCurrent = false; if (point.Equals(Current)) { isCurrent = true; } if (Map.ContainsKey(point)) { if (isCurrent) { newLine += Map[point] ? "[#]" : "[.]"; } else { newLine += Map[point] ? " # " : " . "; } } else { newLine += " . "; } } map.Add(newLine); } var output = string.Empty; foreach (var line in map) { output += line; output += '\n';//"/"; } output = output.TrimEnd('/'); return($"Facing: {Facing.ToString()} Current:{Current} Map:\n{output}"); }
private List <string> GenerateGameData(bool FullPackageData) { List <string> ReturnList; if (FullPackageData) { ReturnList = new List <string> { GameMode, isGameJoltPlayer.Tobool().ToString(), isGameJoltPlayer ? GameJoltID.ToString() : "", DecimalSeparator, Name, LevelFile, Position.ConvertStringCulture(this), Facing.ToString(), Moving.Tobool().ToString(), Skin, BusyType.ToString(), PokemonVisible.Tobool().ToString(), PokemonPosition.ConvertStringCulture(this), PokemonSkin, PokemonFacing.ToString() }; } else { ReturnList = new List <string> { "", "", "", "", "", LastValidGameData[0] == LevelFile ? "" : LevelFile, LastValidGameData[1] == Position ? "" : Position.ConvertStringCulture(this), LastValidGameData[2] == Facing.ToString() ? "" : Facing.ToString(), LastValidGameData[3] == Moving.Tobool().ToString() ? "" : Moving.Tobool().ToString(), LastValidGameData[4] == Skin ? "" : Skin, LastValidGameData[5] == BusyType.ToString() ? "" : BusyType.ToString(), LastValidGameData[6] == PokemonVisible.Tobool().ToString() ? "" : PokemonVisible.Tobool().ToString(), LastValidGameData[7] == PokemonPosition ? "" : PokemonPosition.ConvertStringCulture(this), LastValidGameData[8] == PokemonSkin ? "" : PokemonSkin, LastValidGameData[9] == PokemonFacing.ToString() ? "" : PokemonFacing.ToString() }; } return(ReturnList); }
private DataItems GenerateDataItems() { return(new DataItems( GameMode, IsGameJoltPlayer ? "1" : "0", GameJoltID.ToString(CultureInfo), DecimalSeparator.ToString(), Name, LevelFile, Position.ToP3DString(DecimalSeparator, CultureInfo), Facing.ToString(CultureInfo), Moving ? "1" : "0", Skin, BusyType, PokemonVisible ? "1" : "0", PokemonPosition.ToP3DString(DecimalSeparator, CultureInfo), PokemonSkin, PokemonFacing.ToString(CultureInfo))); }
/// <summary> /// Gets INI code for map aircraft object. /// </summary> /// <returns>INI code for map object.</returns> public override string GetINICode() { List <string> values = new List <string> { Owner, ID, Health.ToString(), X.ToString(), Y.ToString(), Facing.ToString(), Mission.ToString().Replace("_", " "), Tag, Veterancy.ToString(), Group.ToString(), AutocreateNoRecruitable ? "1" : "0", AutocreateYesRecruitable ? "1" : "0" }; return(string.Join(",", values)); }
public IReadOnlyList <string> GenerateGameData() { return(new List <string> { GameMode, IsGameJoltPlayer ? "1" : "0", GameJoltId, DecimalSeparator, Name, LevelFile, Position.ToString(), Facing.ToString(), Moving ? "1" : "0", Skin, ((int)BusyType).ToString(), PokemonVisible ? "1" : "0", PokemonPosition.ToString(), PokemonSkin, PokemonFacing.ToString() }); }
public void MoveCharacterToLocation(GameObject targetLocation) { ui.HideMoveHolder(); flow.currentUnit.battleLocation = targetLocation.name; Facing f = flow.currentUnit.facing; flow.currentUnit.battleAnimator.transform.SetParent(targetLocation.transform); flow.currentUnit.battleAnimator.transform.localPosition = new Vector3(0.0f, flow.currentUnit.battleAnimator.transform.position.y, 0.0f); if (targetLocation.name.Contains(f.ToString())) { if (f == Facing.Right) { flow.currentUnit.facing = Facing.Left; flow.currentUnit.battleAnimator.GetComponent <SpriteRenderer>().flipX = false; } else if (f == Facing.Left) { flow.currentUnit.facing = Facing.Right; flow.currentUnit.battleAnimator.GetComponent <SpriteRenderer>().flipX = true; } } flow.SetUpNextTurn(2); }
private void Update() { if (_nav == NavType.Stop) { return; } else if (_nav == NavType.FarwayEnemy) { Vector2 farNoraml = transform.position - CharManager.Instance.MainChar.transform.position; Vector2 mDelta = Speed * farNoraml.normalized * Time.deltaTime; transform.position += new Vector3(mDelta.x, mDelta.y, 0f); //TODO Use Nav } else if (_nav == NavType.FollowEnemy) { //Vector2 farNoraml = transform.position - CharManager.Instance.MainChar.transform.position; //Vector2 mDelta = Speed * farNoraml.normalized * Time.deltaTime; //transform.position -= new Vector3(mDelta.x, mDelta.y, 0f); if (AINavMeshGenerator.pathfinder == null) { //Debug.LogError("Not Found AINavMeshGenerator"); return; } _index++; if (_index % 5 == 0) { Vector2 toPos = CharManager.Instance.MainChar.transform.position; TempPath_v2 = AINavMeshGenerator.pathfinder.FindPath(transform.position, toPos); } if (TempPath_v2 == null) { return; } if (TempPath_v2.Length < 1) { return; } List <Vector3> Poss = new List <Vector3>(); foreach (Vector3 n in TempPath_v2) { Poss.Add(n); } if (lineRender != null) { lineRender.positionCount = Poss.Count; lineRender.SetPositions(Poss.ToArray()); } Vector2 moveInput = TempPath_v2[1] - (Vector2)transform.position; Vector2 MoveVelocity = moveInput.normalized * Speed * Time.deltaTime; transform.position += new Vector3(MoveVelocity.x, MoveVelocity.y, 0); if (Mathf.Abs(MoveVelocity.x) > Mathf.Abs(MoveVelocity.y)) { LastFacing = (MoveVelocity.x > 0) ? Facing.Right : Facing.Left; } else if (Mathf.Abs(MoveVelocity.x) < Mathf.Abs(MoveVelocity.y)) { LastFacing = (MoveVelocity.y > 0) ? Facing.Up : Facing.Down; } if (MoveVelocity == Vector2.zero) { animator.Play("Idle" + LastFacing.ToString()); } else { animator.Play("Walk" + LastFacing.ToString()); } //TOOD Use Nav } else if (_nav == NavType.Rand) { //TODO } }
public BaseCellItem MoveForward(Game game, bool random, int gameSpeed) { int times = 1; if (random) { times = Randomizer.RandomizeNumber(1, game.Size); } Console.WriteLine(string.Format("The player will move to the {0} for {1} time(s)!", Facing.ToString(), times)); BaseCellItem cell = null; for (int i = 0; i < times; i++) { Thread.Sleep(gameSpeed); cell = ScanForward(game); //scanCount += 1; if (cell.CellItemType == CellItemType.Wall) { Console.WriteLine("The player ran into a thick wall and cannot move forward. Aborting the remaining moves, if any."); break; } // remove the player from its current cell game.ClearCell(Position.Row, Position.Column); // assign new coordinates to the player Position.Row = cell.Position.Row; Position.Column = cell.Position.Column; game.AssignPlayerToCell(this); var newCoordinates = new Tuple <int, int>(Position.Row, Position.Column); Console.WriteLine(string.Format("Player moved to coordinates [{0},{1}]", Position.Row, Position.Column)); if (PositionHistory.Contains(newCoordinates)) { Metrics.backtrackCount++; } PositionHistory.Add(newCoordinates); //moveCount += 1; Metrics.moveCount++; if (cell.CellItemType == CellItemType.Pit) { // die Console.WriteLine("The player died a horrible death."); break; } else if (cell.CellItemType == CellItemType.GoldenSquare) { // win Console.WriteLine("The player has struck gold."); break; } else if (cell.CellItemType == CellItemType.Beacon) { // clue Console.WriteLine("The player has found a beacon."); break; } } return(cell); }
/// <summary> /// Place the robot on the board /// </summary> /// <param name="pos">Position object containing the x and y coordinates of the position of the robot</param> /// <param name="face">The facing of the robot when placed</param> public void Place(IPosition pos, Facing face) { _robotOnBoard = true; _currentPosition = (Position)pos; _currentFacing = face; _logger.Info($"Robot as been placed at position: {pos.GetX()}, {pos.GetY()}, facing: {face.ToString()}"); }
/// <summary> /// Overrides the ToString() method to output a custom string of the object data. /// </summary> /// <returns>X,Y,Facing</returns> public override string ToString() { return($"{Coords.X},{Coords.Y},{Facing.ToString()}"); }
public override string ToString() { return(string.Format("{0},{1},{2}", Position.Item1, Position.Item2, Facing.ToString().Substring(0, 1))); }
public override string ToString() { return(point.X + "." + point.Y + "." + facing.ToString().Remove(1)); }
/// <summary> /// Update Player Objects /// </summary> /// <param name="p">Package Data</param> /// <param name="SentToServer">Sent data to server?</param> public void Update(Package p, bool SentToServer) { if (Network != null) { Network.LastValidMovement = DateTime.Now; } if (p.IsFullPackageData()) { GameMode = p.DataItems[0]; isGameJoltPlayer = p.DataItems[1].ToInt().Tobool(); GameJoltID = isGameJoltPlayer ? p.DataItems[2].ToInt() : -1; DecimalSeparator = p.DataItems[3]; Name = p.DataItems[4]; LevelFile = p.DataItems[5]; Position = p.DataItems[6]; Facing = p.DataItems[7].ToInt(); Moving = p.DataItems[8].ToInt().Tobool(); Skin = p.DataItems[9]; BusyType = p.DataItems[10].ToInt(); PokemonVisible = p.DataItems[11].ToInt().Tobool(); PokemonPosition = p.DataItems[12]; PokemonSkin = p.DataItems[13]; PokemonFacing = p.DataItems[14].ToInt(); LastValidGameData = new List <string> { LevelFile, Position, Facing.ToString(), Moving.ToString(), Skin, BusyType.ToString(), PokemonVisible.ToString(), PokemonPosition, PokemonSkin, PokemonFacing.ToString() }; } else { LastValidGameData = new List <string> { LevelFile, Position, Facing.ToString(), Moving.ToString(), Skin, BusyType.ToString(), PokemonVisible.ToString(), PokemonPosition, PokemonSkin, PokemonFacing.ToString() }; if (!string.IsNullOrWhiteSpace(p.DataItems[5]) && p.DataItems[5].SplitCount() == 1) { LevelFile = p.DataItems[5]; } if (!string.IsNullOrWhiteSpace(p.DataItems[6]) && p.DataItems[6].SplitCount() == 3) { Position = p.DataItems[6]; } if (!string.IsNullOrWhiteSpace(p.DataItems[7]) && p.DataItems[7].SplitCount() == 1) { Facing = p.DataItems[7].ToInt(); } if (!string.IsNullOrWhiteSpace(p.DataItems[8]) && p.DataItems[8].SplitCount() == 1) { Moving = p.DataItems[8].ToInt().Tobool(); } if (!string.IsNullOrWhiteSpace(p.DataItems[9]) && p.DataItems[9].SplitCount() <= 2) { Skin = p.DataItems[9]; } if (!string.IsNullOrWhiteSpace(p.DataItems[10]) && p.DataItems[10].SplitCount() == 1) { BusyType = p.DataItems[10].ToInt(); } if (!string.IsNullOrWhiteSpace(p.DataItems[11]) && p.DataItems[11].SplitCount() == 1) { PokemonVisible = p.DataItems[11].ToInt().Tobool(); } if (!string.IsNullOrWhiteSpace(p.DataItems[12]) && p.DataItems[12].SplitCount() == 3) { PokemonPosition = p.DataItems[12]; } if (!string.IsNullOrWhiteSpace(p.DataItems[13]) && p.DataItems[13].SplitCount() <= 2) { PokemonSkin = p.DataItems[13]; } if (!string.IsNullOrWhiteSpace(p.DataItems[14]) && p.DataItems[14].SplitCount() == 1) { PokemonFacing = p.DataItems[14].ToInt(); } } // Sent To Server if (SentToServer) { Core.RCONPlayer.SendToAllPlayer(new RCON_Client_Listener.Packages.Package(RCON_Client_Listener.Packages.Package.PackageTypes.UpdatePlayer, $"{ID},{ToString()}", null)); PlayerEvent.Invoke(PlayerEvent.Types.Update, $"{ID},{ToString()}"); if (p.IsFullPackageData()) { Core.Player.SendToAllPlayer(new Package(Package.PackageTypes.GameData, ID, GenerateGameData(true), null)); } else { Core.Player.SendToAllPlayer(new Package(Package.PackageTypes.GameData, ID, GenerateGameData(false), null)); } } }
private void ShootingLogic() { if (target == null) { switch (fireTarget) { case FireTarget.Player: var hero = FindObjectOfType <Hero>(); if (hero != null) { target = hero.transform; } break; } } if (target == null) { return; } fireT += Time.deltaTime; if (fireT >= fireInterval) { fireT -= fireInterval; GameObject newBullet = Instantiate(bulletPrefab, new Vector3(shootAnchor.position.x, shootAnchor.position.y, 0), Quaternion.identity) as GameObject; newBullet.GetComponent <Bullet>().SetTarget(target); if (audioSource != null) { audioSource.PlayOneShot(fireAudioClips[Random.Range(0, fireAudioClips.Count)]); } } Vector2 delta = (target.position - transform.position).normalized; Facing newFacing = Facing.Left; if (Mathf.Abs(delta.x) > Mathf.Abs(delta.y)) { if (delta.x < 0) { newFacing = Facing.Left; } else { newFacing = Facing.Right; } } else { if (delta.y < 0) { newFacing = Facing.Down; } else { newFacing = Facing.Up; } } if (newFacing != facing) { facing = newFacing; animator.SetTrigger("turn_" + facing.ToString().ToLower()); } }
public void Update(Package.Package package, bool sentToAllPlayer) { LastValidMovement = DateTime.Now; if (package.IsFullPackageData()) { GameMode = package.DataItems[0]; IsGameJoltPlayer = package.DataItems[1].ToInt().ToBool(); GameJoltID = IsGameJoltPlayer ? package.DataItems[2] : "-1"; DecimalSeparator = package.DataItems[3]; Name = package.DataItems[4]; LevelFile = package.DataItems[5]; Position = package.DataItems[6]; Facing = package.DataItems[7].ToInt(); Moving = package.DataItems[8].ToBool(); Skin = package.DataItems[9]; BusyType = package.DataItems[10].ToInt(); PokemonVisible = package.DataItems[11].ToBool(); PokemonPosition = package.DataItems[12]; PokemonSkin = package.DataItems[13]; PokemonFacing = package.DataItems[14].ToInt(); LastValidGameData = new List <string> { LevelFile, Position, Facing.ToString(), Moving.ToString(), Skin, BusyType.ToString(), PokemonVisible.ToString(), PokemonPosition, PokemonSkin, PokemonFacing.ToString() }; } else { LastValidGameData = new List <string> { LevelFile, Position, Facing.ToString(), Moving.ToString(), Skin, BusyType.ToString(), PokemonVisible.ToString(), PokemonPosition, PokemonSkin, PokemonFacing.ToString() }; if (!string.IsNullOrWhiteSpace(package.DataItems[5]) && package.DataItems[5].SplitCount() == 1) { LevelFile = package.DataItems[5]; } if (!string.IsNullOrWhiteSpace(package.DataItems[6]) && package.DataItems[6].SplitCount() == 3) { Position = package.DataItems[6]; } if (!string.IsNullOrWhiteSpace(package.DataItems[7]) && package.DataItems[7].SplitCount() == 1) { Facing = package.DataItems[7].ToInt(); } if (!string.IsNullOrWhiteSpace(package.DataItems[8]) && package.DataItems[8].SplitCount() == 1) { Moving = package.DataItems[8].ToBool(); } if (!string.IsNullOrWhiteSpace(package.DataItems[9]) && package.DataItems[9].SplitCount() <= 2) { Skin = package.DataItems[9]; } if (!string.IsNullOrWhiteSpace(package.DataItems[10]) && package.DataItems[10].SplitCount() == 1) { BusyType = package.DataItems[10].ToInt(); } if (!string.IsNullOrWhiteSpace(package.DataItems[11]) && package.DataItems[11].SplitCount() == 1) { PokemonVisible = package.DataItems[11].ToBool(); } if (!string.IsNullOrWhiteSpace(package.DataItems[12]) && package.DataItems[12].SplitCount() == 3) { PokemonPosition = package.DataItems[12]; } if (!string.IsNullOrWhiteSpace(package.DataItems[13]) && package.DataItems[13].SplitCount() <= 2) { PokemonSkin = package.DataItems[13]; } if (!string.IsNullOrWhiteSpace(package.DataItems[14]) && package.DataItems[14].SplitCount() == 1) { PokemonFacing = package.DataItems[14].ToInt(); } } if (sentToAllPlayer) { Core.TcpClientCollection.SendToAllPlayer(new Package.Package(Core, PackageTypes.GameData, ID, GenerateGameData(package.IsFullPackageData()), Network)); } }