public void Update(PlayerButton input, Facing facing, Boolean paused) { m_inputbuffer.Add(input, facing); if (paused == false) { foreach (BufferCount count in m_commandcount.Values) count.Tick(); } foreach (Command command in Commands) { if (command.IsValid == false) continue; if (CommandChecker.Check(command, m_inputbuffer) == true) { Int32 time = command.BufferTime; if (paused == true) ++time; m_commandcount[command.Name].Set(time); } } m_activecommands.Clear(); foreach (var data in m_commandcount) if (data.Value.IsActive == true) m_activecommands.Add(data.Key); }
public Sprite(Vector2 position, float maxSpeed, Facing facing) { this.position = position; this.maxSpeed = maxSpeed; this.facing = facing; this.movement = Vector2.Zero; }
protected bool FacingChanged(Facing f) { if (f != pFaceDirection) return true; else return false; }
public AddStructure(Position position, StructureType structureType, Facing frontFace) : this() { Position = position; StructureType = structureType; FrontFace = frontFace; }
public void Add(PlayerButton input, Facing facing) { if (facing == Facing.Left) { if (((input & PlayerButton.Left) == PlayerButton.Left) != ((input & PlayerButton.Right) == PlayerButton.Right)) { input ^= PlayerButton.Left; input ^= PlayerButton.Right; } } if (((input & PlayerButton.Up) == PlayerButton.Up) && ((input & PlayerButton.Down) == PlayerButton.Down)) { input &= ~PlayerButton.Up; input &= ~PlayerButton.Down; } if (((input & PlayerButton.Left) == PlayerButton.Left) && ((input & PlayerButton.Right) == PlayerButton.Right)) { input &= ~PlayerButton.Left; input &= ~PlayerButton.Right; } m_buffer.Add(input); m_size = m_buffer.Size; }
// Update is called once per frame void Update() { if (!Manager.DialogOpen) { if (Input.GetKey(KeyCode.D) && tr.position == position) { if(CanMove(Vector3.right)) position += Vector3.right * 0.32f; direction = Facing.Right; } else if (Input.GetKey(KeyCode.A) && tr.position == position) { if (CanMove(Vector3.left)) position += Vector3.left * 0.32f; direction = Facing.Left; } else if (Input.GetKey(KeyCode.W) && tr.position == position) { if (CanMove(Vector3.up)) position += Vector3.up * 0.32f; direction = Facing.Up; } else if (Input.GetKey(KeyCode.S) && tr.position == position) { if (CanMove(Vector3.down)) position += Vector3.down * 0.32f; direction = Facing.Down; } transform.position = Vector3.MoveTowards(transform.position, position, Time.deltaTime * moveSpeed); } }
public virtual void CacheMovement(Facing direction, MovementSpeed speed) { if (this.CacheMovements) { this.Queue.Enqueue(new Movement(direction, speed)); } else { this.Entity.TryMove(direction, speed); } }
public static void SetupRobotFixture(this Mock<IRobot> mockRobot, int x, int y, Facing f, bool placed) { mockRobot.SetupProperty(r => r.X, x); mockRobot.SetupProperty(r => r.Y, y); mockRobot.SetupProperty(r => r.F, f); mockRobot.SetupProperty(r => r.Placed, placed); }
// Update is called once per frame void FixedUpdate() { rigidbody.AddForce(gravityBoost * down); if (Input.touchCount > 0) { if (Input.GetTouch(0).position.x > Screen.width/2) { rigidbody.AddForce(jumpForceBoost * jumpRightVector); if (facing == Facing.Left) { transform.localScale = new Vector3( transform.localScale.x * -1, transform.localScale.y, transform.localScale.z ) ; facing = Facing.Right; } } else { rigidbody.AddForce(jumpForceBoost * jumpLeftVector); if (facing == Facing.Right) { transform.localScale = new Vector3( transform.localScale.x * -1, transform.localScale.y, transform.localScale.z ) ; facing = Facing.Left; } } gameObject.GetComponent<SpriteRenderer>().sprite = pig_wings_down; } else { gameObject.GetComponent<SpriteRenderer>().sprite = pig_wings_up; } if (Input.GetKeyDown(KeyCode.Escape)) { Debug.Log("Escape key in pig behaviour"); Application.LoadLevel(0); } }
public virtual void Update() { Facing f = CalculateFacing(); if (FacingChanged(f)) { FaceDirection = f; } }
private TimeSpan timer; // Contador de tempo. #endregion Fields #region Constructors protected Animation(Facing facing, State state) { timer = TimeSpan.Zero; this.color = Color.White; this.state = state; this.facing = facing; this.loopList = new List<Point>(); }
void Application_Place_ValidPlacementParams_Allowed(string command, int xInput, int yInput, Facing fInput, [Frozen] Mock<IRobotService> mockRobotService, Application sut) { sut.ProcessCommand(command); mockRobotService.Verify(rs => rs.Place(It.Is<int>(x => x == xInput), It.Is<int>(y => y == yInput), It.Is<Facing>(f => f == fInput)), Times.Once()); }
void ChangeWallInDirection(Facing direction, WallType newType) { GrabTilesFromSelection(); string prefabPath = ""; Wall newWall = null; switch(newType) { case WallType.Basic: prefabPath = "Assets/Prefabs/Walls/Basic Wall.prefab"; break; case WallType.Laser: prefabPath = "Assets/Prefabs/Walls/Laser Wall.prefab"; break; default: Debug.Log("No path for replacement prefab!"); break; } var prefab = Resources.LoadAssetAtPath(prefabPath, typeof(Wall)); if (null == prefab) { Debug.Log("Replacement prefab not found!"); return; } foreach (Tile tile in selectedTiles) { Wall wallToChange = tile.adjacentWalls[(int)direction]; if (null == wallToChange) { Debug.Log("Wall doesn't exist in that direction!"); continue; } if (wallToChange.wallType == newType) { Debug.Log("Existing wall is already this type."); continue; } newWall = (Wall)GameObject.Instantiate(prefab, wallToChange.transform.position, wallToChange.transform.rotation); newWall.transform.parent = wallToChange.transform.parent; newWall.facing = wallToChange.facing; newWall.adjacentTiles = wallToChange.adjacentTiles; newWall.Setup(); TileVisualizer.instance.SetVisualizationForWall(newWall); foreach (Tile adjTile in wallToChange.adjacentTiles) { if (adjTile.adjacentWalls[(int)direction] == wallToChange) { adjTile.adjacentWalls[(int)direction] = newWall; } if (adjTile.adjacentWalls[(int)Utils.UTurnFacing(direction)] == wallToChange) { adjTile.adjacentWalls[(int)Utils.UTurnFacing(direction)] = newWall; } } DestroyImmediate(wallToChange.gameObject); } }
/// <summary> /// Listen onLeftWall, onRightWall and start moving /// </summary> override public void Start() { base.Start(); pc2d.onLeftWall += OnLeftWall; pc2d.onRightWall += OnRightWall; facing = initialFacing; input.SetX((float) facing); }
void RobotService_Left_NotPlaced_Ignored(Facing start, Facing expected, [Frozen]Mock<IRobot> mockRobot, RobotService sut) { mockRobot.SetupProperty(x => x.Placed, false); mockRobot.SetupProperty(x => x.F, start); sut.Left(); mockRobot.VerifySet(r => r.F = expected, Times.Never()); }
void RobotService_Left_Placed_Allowed(Facing start, Facing expected, [Frozen]Mock<IRobot> mockRobot, RobotService sut) { mockRobot.SetupProperty(x => x.Placed, true); mockRobot.SetupProperty(x => x.F, start); sut.Left(); mockRobot.VerifySet(r => r.F = expected, Times.Once()); }
// Used in the game ending to force the player to begin moving against its will public void BeginWalkingRight() { playerState = PlayerState.Walk; ObjectState = ObjectState.Grounded; facing = Facing.Right; sprite.PlayAnimation("Walk"); SetHorizontalSpeed(180f); }
public void Fire(Vector2 centerPosition, Facing facing) { _facing = facing; Sprite.TextureAtlas.Frame = _facing == Facing.Right ? 0 : 1; MovementVector = _facing == Facing.Right ? new Vector2(12.0f, 0.0f) : new Vector2(-12.0f, 0.0f); IsAlive = true; CenterPosition = centerPosition; }
private static bool FacesThisWay(Vector3 v, Vector3 dir, Facing p, ref float maxDot, ref Facing ret) { float t = Vector3.Dot(v, dir); if (t > maxDot) { ret = p; maxDot = t; return true; } return false; }
public bool Place(int x, int y, Facing facing) { if (MandateIsOnTable(x, y, "placed")) { _x = x; _y = y; _facing = facing; return true; } return false; }
public void Fire(Vector2 position, Facing facing, Character user) { if (this.FireRate < this.WeaponType.FireRate) return; Bullet bullet = this.WeaponType.BulletType.Pool.New(); bullet.Fire(position, facing, user); GameManager.BulletLayer.AddChild(bullet); this.FireRate = 0; }
public Baddie(Vector2 position, float maxSpeed, Facing facing, Map map, TileSet tileSet) : base(position, maxSpeed, facing,map,tileSet) { this.map = map; this.tileSet = tileSet; direction = Direction.Stand; enemy = new Enemy(Position, Game.GetInstance().GetSprite("Wall")); Game.GetInstance().EManager.Add(enemy); nextChange = 0f; rand = new Random(); blind = false; }
int GetNormal(Facing detectorFacing) { if ((player.IsFacingRight() && detectorFacing == Facing.FRONT) || ((!player.IsFacingRight()) && detectorFacing == Facing.BACK)) { return -1; } else { return 1; } }
protected Character(int ID, Type type, Vector2 position, Facing facing, State state) : base(position, facing, state) { this.ID = ID; System.Random random = new System.Random(); if (ID == 0) base.position = new Vector2(0, 300 + random.Next(0, 250)); else base.position = new Vector2(800, 300 + random.Next(0, 250)); }
public Zombie(Vector2 position, Vector2 direction) { this.Position = position; this.direction = direction; this.Falling = true; this.CanBite = true; this.Visible = true; this.Collide = false; this.Scale = 0.667f; this.Hitpoints = initialHitpoints; if (direction.X < 0) currentFacing = Facing.Left; else currentFacing = Facing.Right; }
internal void SetNewFacing(Facing newDirection) { if (sprite == null) { afterLoadFacing = newDirection; return; } if (direction == newDirection) return; direction = newDirection; sprite.transform.Rotate(Vector3.up, 180, Space.Self); }
public List<IWeaponSystem> AvailableWeapons(Facing toTarget, double distance) { List<IWeaponSystem> available = new List<IWeaponSystem>(); foreach(var weapon in m_Weapons) { //todo check if weapon has been fired recently here if(weapon.FireArc.HasFlag( toTarget) && weapon.Range > distance) { available.Add(weapon); } } return available; }
public static Vector3 UnitOffsetForDirection(Facing direction) { switch (direction) { case Facing.North: return Vector3.forward; case Facing.East: return Vector3.right; case Facing.South: return Vector3.back; case Facing.West: return Vector3.left; } return Vector3.zero; }
public override void Update(World World, float ElapsedSeconds) { base.Update(World, ElapsedSeconds); AnimationTimer.Update(ElapsedSeconds); if (MotionDelta.X > 0) FacingDirection = Facing.Right; else if (MotionDelta.X < 0) FacingDirection = Facing.Left; if (CurrentAnimation != null && AnimationTimer.GetFrame() < CurrentAnimation.Frames.Count) MeshNode.UVTransform = SpriteSheet.GetFrameTransform(CurrentAnimation.Frames[AnimationTimer.GetFrame()], FacingDirection == Facing.Left); }
/// <summary> /// The KeyInput method handles all keyboard input for the character. /// </summary> public void KeyInput() { KeyboardState keyState = Keyboard.GetState(); //If we're not jumping handle things normally if (direction != Direction.UP) { if (keyState.IsKeyDown(Keys.D)) { direction = Direction.RIGHT; facing = Facing.RIGHT; } if (keyState.IsKeyDown(Keys.A)) { direction = Direction.LEFT; facing = Facing.LEFT; } if (keyState.IsKeyDown(Keys.W)) { direction = Direction.UP; } if (keyState.IsKeyUp(Keys.D) && direction == Direction.RIGHT) { direction = Direction.STANDING; facing = Facing.RIGHT; } if (keyState.IsKeyUp(Keys.A) && direction == Direction.LEFT) { direction = Direction.STANDING; facing = Facing.LEFT; } } //Otherwise, speed is greatly reduced to allow *some* manouvering else { if (keyState.IsKeyDown(Keys.D)) { if (speed < maxspeed) speed += .2f; facing = Facing.RIGHT; } if (keyState.IsKeyDown(Keys.A)) { if (speed > -maxspeed) speed -= .2f; facing = Facing.LEFT; } } }
Facing GetTurnDirection(Direction dir) { Facing f = currentFacing; switch (currentFacing) { case Facing.north: f = (dir == Direction.left ? Facing.west : Facing.east); break; case Facing.south: f = (dir == Direction.left ? Facing.east : Facing.west); break; case Facing.west: f = (dir == Direction.left ? Facing.south : Facing.north); break; case Facing.east: f = (dir == Direction.left ? Facing.north : Facing.south); break; } return(f); }
private void Awake() { if (m_facing == null) { m_facing = GetComponent <Facing>(); } if (m_facing == null) { Debug.LogErrorFormat("Ai Shooter in {0} requires Facing to be attached or set. Deactivating.", name); this.enabled = false; return; } if (m_shooter == null) { m_shooter = GetComponent <Shooter>(); } if (m_shooter == null) { Debug.LogErrorFormat("Ai Shooter in {0} requires Shooter to be attached or set. Deactivating.", name); this.enabled = false; return; } }
public static Pos Offset(Pos pos, Facing dir, int scale) { switch (dir) { case Facing.NORTH: return(new Pos(pos.x, pos.y, pos.z + scale)); case Facing.SOUTH: return(new Pos(pos.x, pos.y, pos.z - scale)); case Facing.EAST: return(new Pos(pos.x + scale, pos.y, pos.z)); case Facing.WEST: return(new Pos(pos.x - scale, pos.y, pos.z)); case Facing.UP: return(new Pos(pos.x, pos.y + scale, pos.z)); case Facing.DOWN: return(new Pos(pos.x, pos.y - scale, pos.z)); } return(ERROR); }
public void TurnLeftTest() { Robot robot = new Robot(); TableTop table = new TableTop(5, 6); IRobotMovingService movingService = new ToyRobotMovingService(); IRobotReportingService reportingService = new ToyRobotReportingService(); IRobotTurningService turningService = new ToyRobotTurningService(); RobotSimulator simulator = new RobotSimulator(robot, table, movingService, turningService, reportingService); Facing defaultFacing = robot.Facing; simulator.TurnLeft(); Assert.AreEqual(defaultFacing, robot.Facing); Assert.IsNull(robot.Position); simulator.Place(new Position(3, 3), Facing.EAST); simulator.TurnLeft(); Assert.AreEqual(3, robot.Position.X); Assert.AreEqual(3, robot.Position.Y); Assert.AreEqual(Facing.NORTH, robot.Facing); }
private void OnCollisionEnter2D(Collision2D collision) { if ((collision.gameObject.tag == "Terrain") | (collision.gameObject.tag == "PhaseBarrier") | (collision.gameObject.tag == "Enemy")) { switch (Facing) { case Facing.LEFT: Facing = Facing.RIGHT; break; case Facing.RIGHT: Facing = Facing.LEFT; break; case Facing.UP: Facing = Facing.DOWN; break; case Facing.DOWN: Facing = Facing.UP; break; } } }
public void Spawn(int level) { this.level = level % levels.Length; LevelInfo l = levels[this.level]; this.initialPosition = l.spawn; this.initialFacing = l.spawnFacing; this.NextInstruction = 0; this.DeathCounter = 0; this.StepCounter = 0; this.isAlive = false; this.CurrentTimer = 0; this.nextTransitionPoint = l.nextLevelPath[0].transform.position; this.clock.SetActive(true); vcam.Follow = l.center.transform; int counter = 0; this.instructions.Clear(); this.ui.Clear(); this.inventory.Clear(); foreach (EInstruction instruction in l.instructions) { this.AddInstruction(instruction, counter++); } foreach (GameObject pickup in GameObject.FindGameObjectsWithTag("Pickup")) { pickup.transform.GetChild(0).gameObject.SetActive(true); pickup.GetComponent <BoxCollider2D>().enabled = true; } this.isTransitioning = false; this.currentPathIndex = 0; this.ResetPlayer(); }
private Vector2 getDirectionFromFacing(Facing facing) { Vector2 direction = new Vector2(0); switch (facing) { case Facing.North: direction.Y = -1; break; case Facing.East: direction.X = 1; break; case Facing.South: direction.Y = 1; break; case Facing.West: direction.X = -1; break; } return(direction); }
private void Rotate() { float rotation_delta = ROTATION_SPEED * Time.deltaTime; if (rotation_delta > Mathf.Abs(target_angle)) { rotation_delta = Mathf.Abs(target_angle); } //Debug.Log("Rotating! ROTATION_SPEED ("+ ROTATION_SPEED + ") * Time.deltaTime ("+ Time.deltaTime + ") = " + rotation_delta+", target angle: "+target_angle); if (target_angle > 0) { RotateStep(-rotation_delta); } else if (target_angle < 0) { RotateStep(rotation_delta); } if (Mathf.Abs(target_angle) < EPSILON) { facing = next_facing; } }
// ==== mesh creator ==== public static Vector2 GetTextureOffset(ushort voxel, Facing facing) { Voxel voxelType = Engine.GetVoxelType(voxel); Vector2[] textureArray = voxelType.VTexture; if (textureArray.Length == 0) { // in case there are no textures defined, return a default texture Debug.LogWarning("Uniblocks: Block " + voxel.ToString() + " has no defined textures! Using default texture."); return(new Vector2(0, 0)); } else if (voxelType.VCustomSides == false) { // if this voxel isn't using custom side textures, return the Up texture. return(textureArray[0]); } else if ((int)facing > textureArray.Length - 1) { // if we're asking for a texture that's not defined, grab the last defined texture instead return(textureArray[textureArray.Length - 1]); } else { return(textureArray[(int)facing]); } }
public void ControllerUpdate(float leftTrigger, float rightTrigger, Vector2 leftStickDirection, Vector2 rightStickDirection) { if (Stunned || !IsAlive) { return; } if (Math.Abs(leftStickDirection.Length()) > CodingConstants.JoystickTolerance) { Facing = leftStickDirection; } if (leftTrigger > CodingConstants.TriggerPress && Velocity.Length() > 0) { Facing = Facing.Rotate(180); } if (InputService.InputDevices[Player.PlayerIndex] is Keyboard) { if (rightStickDirection != Vector2.Zero) { Facing = rightStickDirection; } } Velocity = leftStickDirection; }
private void SetShotVelocity(GameObject shot) { Facing dir = gameObject.GetComponent <PlayerControl>().direction; if (dir == Facing.Left) { shot.transform.Rotate(new Vector3(0, 0, 180)); shot.GetComponent <Rigidbody2D>().velocity = new Vector2(-10, 0); } else if (dir == Facing.Up) { shot.transform.Rotate(new Vector3(0, 0, 90)); shot.GetComponent <Rigidbody2D>().velocity = new Vector2(0, 10); } else if (dir == Facing.Down) { shot.transform.Rotate(new Vector3(0, 0, 270)); shot.GetComponent <Rigidbody2D>().velocity = new Vector2(0, -10); } else { shot.GetComponent <Rigidbody2D>().velocity = new Vector2(10, 0); } }
void Update() { if (severable.Severed && !Dead) { Kill(); } if (Input.GetButton("Fire3")) { Berserk = true; } else { Berserk = false; } if (Input.GetAxis("Horizontal") > 0) { Facing = Facing.Right; } else if (Input.GetAxis("Horizontal") < 0) { Facing = Facing.Left; } /* * if (Input.GetButtonDown("Fire1")) * if (CanBerserk()) * StartCoroutine(GoBerserk()); */ if (Input.GetKey(KeyCode.Escape)) { Application.Quit(); } }
/// <summary> /// 根据x轴y轴设定朝向 /// </summary> public void GetAndSetDiection() { inputMovement.x = Input.GetAxisRaw("Horizontal"); inputMovement.y = Input.GetAxisRaw("Vertical"); animator.SetFloat("xDir", inputMovement.x); animator.SetFloat("yDir", inputMovement.y); inputMovement = inputMovement.normalized; /* 通过角度判断 */ Vector2 offset = new Vector2(0.000001f, 0.000001f); //本来想用Vector.zero的,但是输出的angle只会是0,所以就只能取一个接近于0的点 heroFacingAngle = Vector2.SignedAngle(offset, inputMovement.normalized); //Debug.Log(heroFacingAngle); if (heroFacingAngle == 135) { facingDir = Facing.left; } else if (heroFacingAngle == -45) { facingDir = Facing.right; } else if (heroFacingAngle == 45) { facingDir = Facing.up; } else if (heroFacingAngle == -135) { facingDir = Facing.down; } else { //Debug.LogError("wrong facing"); } //Mapping animator.SetFloat("facingDir", Mathf.InverseLerp(0, 3, (float)facingDir)); }
private Vector3 RotationVector(Facing facing) { //enum Facing { NORTH, NORTHEAST, EAST, SOUTHEAST, SOUTH, SOUTHWEST, WEST, NORTHWEST }; int steps; // do not allow facing up or down (when moving up or down have to face east or west) if (my_facing == Facing.NORTH || my_facing == Facing.SOUTH) { if (my_oldFacing > Facing.NORTH && my_oldFacing < Facing.SOUTH) { my_facing = Facing.EAST; } else { my_facing = Facing.WEST; } } steps = my_oldFacing - my_facing; //Debug.Log(steps); return(new Vector3(0, 0, steps * 45)); }
private void TakeInput() { direction = Vector2.zero; if (Input.GetKey(KeyCode.W)) { direction += Vector2.up; facingDir = Facing.UP; } if (Input.GetKey(KeyCode.S)) { direction += Vector2.down; facingDir = Facing.DOWN; } if (Input.GetKey(KeyCode.A)) { // Flips player sprite on the X axis mySpriteRenderer.flipX = true; facingDir = Facing.LEFT; direction += Vector2.left; } if (Input.GetKey(KeyCode.D)) { // Flips player sprite on the X axis mySpriteRenderer.flipX = false; facingDir = Facing.RIGHT; direction += Vector2.right; } if (Input.GetKeyDown(KeyCode.Space)) { PlayerDash(); } }
void PlaceEnemy(EnemyGroup enemy, Vector2Int position, Facing facing) { EnemyGroup new_enemy = Instantiate(enemy); new_enemy.position = position; new_enemy.facing = facing; new_enemy.transform.position = (position.ToVector3Int(Vector3Axis.y) - new Vector3Int(new_enemy.anchor.x, 0, new_enemy.anchor.y)) * block_size; new_enemy.transform.rotation = Quaternion.Euler(Vector3.up * (int)facing); if (InBounds(position)) { inventory_tracker.NoteGroupPlacement(enemy.id); } for (int x = 0; x < new_enemy.size.x; x++) { for (int y = 0; y < new_enemy.size.y; y++) { point_to_enemy_group.Add(GetRotatedPosition(enemy.anchor, new Vector2Int(x, y), facing) + position, new_enemy); } } enemy_group_to_anchor.Add(new_enemy, position); map_changed_event.Invoke(); }
bool SpaceAvailable(BasePiece piece, Vector2Int placement, Facing facing) { if (!InBounds(placement)) { return(false); } List <Vector2Int> to_check = new List <Vector2Int>(); for (int x = 0; x < piece.size.x; x++) { for (int y = 0; y < piece.size.y; y++) { to_check.Add(GetRotatedPosition(piece.anchor, new Vector2Int(x, y), facing) + placement); } } foreach (Vector2Int check in to_check) { if (point_to_piece.ContainsKey(check) || (point_to_enemy_group.ContainsKey(check) && piece.blocks_path)) { return(false); } } return(true); }
/** * Set the direction the character is facing * @param __facing One of four cardinal directions specified in CharController */ public void setFacing(Facing __facing) { _facing = __facing; }
/// <summary> /// Character hit a wall, move in the other direction /// </summary> void OnLeftWall() { facing = Facing.Right; aiInput.SetX((float)facing); }
public void Place(int x, int y, Facing direction) { Position = new Point(x, y); Direction = direction; RobotPlaced = true; }
private void Update_DoMovement(float deltaTime) { if (CurrTile == DestTile) { // We're already were we want to be. pathAStar = null; IsWalking = false; VisualPath.Instance.RemoveVisualPoints(name); return; } if (nextTile == null || nextTile == CurrTile) { // Get the next tile from the pathfinder. if (pathAStar == null || pathAStar.Length() == 0) { // Generate a path to our destination. // This will calculate a path from curr to dest. pathAStar = new Path_AStar(World.Current, CurrTile, DestTile); if (pathAStar.Length() == 0) { Debug.ULogErrorChannel("Character", "Path_AStar returned no path to destination!"); AbandonJob(false); return; } // Let's ignore the first tile, because that's the tile we're currently in. nextTile = pathAStar.Dequeue(); } if (IsSelected) { VisualPath.Instance.SetVisualPoints(name, pathAStar.GetList()); } IsWalking = true; // Grab the next waypoint from the pathing system! nextTile = pathAStar.Dequeue(); if (nextTile == CurrTile) { IsWalking = false; } } // Find character facing if (nextTile.X > CurrTile.X) { CharFacing = Facing.EAST; } else if (nextTile.X < CurrTile.X) { CharFacing = Facing.WEST; } else if (nextTile.Y > CurrTile.Y) { CharFacing = Facing.NORTH; } else { CharFacing = Facing.SOUTH; } // At this point we should have a valid nextTile to move to. // What's the total distance from point A to point B? // We are going to use Euclidean distance FOR NOW... // But when we do the pathfinding system, we'll likely // switch to something like Manhattan or Chebyshev distance float distToTravel = Mathf.Sqrt( Mathf.Pow(CurrTile.X - nextTile.X, 2) + Mathf.Pow(CurrTile.Y - nextTile.Y, 2)); if (nextTile.IsEnterable() == Enterability.Never) { //// Most likely a wall got built, so we just need to reset our pathfinding information. //// FIXME: Ideally, when a wall gets spawned, we should invalidate our path immediately, //// so that we don't waste a bunch of time walking towards a dead end. //// To save CPU, maybe we can only check every so often? //// Or maybe we should register a callback to the OnTileChanged event? //// Debug.ULogErrorChannel("FIXME", "A character was trying to enter an unwalkable tile."); nextTile = null; // our next tile is a no-go pathAStar = null; // clearly our pathfinding info is out of date. return; } else if (nextTile.IsEnterable() == Enterability.Soon) { // We can't enter the NOW, but we should be able to in the // future. This is likely a DOOR. // So we DON'T bail on our movement/path, but we do return // now and don't actually process the movement. return; } // How much distance can be travel this Update? float distThisFrame = speed / nextTile.MovementCost * deltaTime; // How much is that in terms of percentage to our destination? float percThisFrame = distThisFrame / distToTravel; // Add that to overall percentage travelled. movementPercentage += percThisFrame; if (movementPercentage >= 1) { // We have reached our destination //// TODO: Get the next tile from the pathfinding system. //// If there are no more tiles, then we have TRULY //// reached our destination. CurrTile = nextTile; movementPercentage = 0; // FIXME? Do we actually want to retain any overshot movement? } }
public Tank(GameField field, CellLocation location, Facing facing, double speed) : base(field, location, facing) { _speed = speed; }
private bool TryGetFacingDirection(string direction, out Facing facing) { return(Enum.TryParse <Facing>(direction, true, out facing)); }
// Methods public void AddClearanceArea(Facing side, float perpendicularLength) { clearanceAreaLengths.Add(side, perpendicularLength); }
public abstract BlockPart GetBlockPart(Facing facing, Block block, BlockState state);
public void TurnRight() { Facing = Facing.ClockWiseByQuarter(); }
public void TurnLeft() { Facing = Facing.CounterClockWiseByQuarter(); }
public static void Second() { Facing f = Facing.UP; string projectFolder = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName; string fileName = Path.Combine(projectFolder, @"input.txt"); string[] result = System.IO.File.ReadAllLines(fileName); char[][] m = new char[result.Length][]; for (int i = 0; i < result.Length; i++) { m[i] = result[i].ToCharArray(); } int counter = 0; int xpos, ypos; xpos = result[0].Length / 2; ypos = result.Length / 2; for (int i = 0; i < 10000000; i++) { if (m[ypos][xpos] == '#') { f = Rotate(f, false); m[ypos][xpos] = 'F'; } else if (m[ypos][xpos] == 'W') { m[ypos][xpos] = '#'; counter++; } else if (m[ypos][xpos] == 'F') { switch (f) { case Facing.UP: f = Facing.DOWN; break; case Facing.DOWN: f = Facing.UP; break; case Facing.LEFT: f = Facing.RIGHT; break; case Facing.RIGHT: f = Facing.LEFT; break; } m[ypos][xpos] = '.'; } else { f = Rotate(f, true); m[ypos][xpos] = 'W'; } switch (f) { case Facing.UP: ypos--; break; case Facing.RIGHT: xpos++; break; case Facing.DOWN: ypos++; break; case Facing.LEFT: xpos--; break; } if (ypos >= m.Length) { char[][] old = m; m = new char[old.Length * 2][]; for (int j = 0; j < old.Length; j++) { m[j] = old[j]; } for (int j = old.Length; j < m.Length; j++) { m[j] = new char[old[0].Length]; for (int x = 0; x < m[0].Length; x++) { m[j][x] = '.'; } } } else if (ypos < 0) { char[][] old = m; m = new char[old.Length + 1][]; char[] dots = new char[old[0].Length]; for (int j = 0; j < dots.Length; j++) { dots[j] = '.'; } m[0] = dots; for (int j = 1; j < m.Length; j++) { m[j] = old[j - 1]; } ypos++; } else if (xpos >= m[ypos].Length) { char[] old = m[ypos]; m[ypos] = new char[old.Length * 2]; for (int j = 0; j < m[ypos].Length; j++) { if (j < old.Length) { m[ypos][j] = old[j]; } else { m[ypos][j] = '.'; } } } else if (xpos < 0) { for (int j = 0; j < m.Length; j++) { char[] old = m[j]; m[j] = new char[old.Length + 1]; m[j][0] = '.'; for (int x = 0; x < old.Length; x++) { m[j][x + 1] = old[x]; } } xpos++; } } Console.WriteLine(counter); Console.ReadKey(); }
private static bool FacesThisWay(Vector3 v, Vector3 dir, Facing p, ref float maxDot, ref Facing ret) { float t = Vector3.Dot(v, dir); if (t > maxDot) { ret = p; maxDot = t; return(true); } return(false); }
public bool PlayerInteraction(Facing player_direction) { GlobalState.Dialogue = DialogueManager.GetDialogue("rock", "NEXUS", "five"); return(true); }