private void moveCharacter(GameTime time) { Point peek = pathToEndPoint.Peek(); Rectangle targetTile = new Rectangle(peek.X * 64, peek.Y * 64, 64, 64); targetTile.Inflate(-2, 0); Rectangle bbox = character.GetBoundingBox(); if ((targetTile.Contains(bbox) || (bbox.Width > targetTile.Width && targetTile.Contains(bbox.Center))) && targetTile.Bottom - bbox.Bottom >= 2) { timerSinceLastCheckPoint = 0; pathToEndPoint.Pop(); character.stopWithoutChangingFrame(); if (pathToEndPoint.Count == 0) { character.Halt(); if (finalFacingDirection != -1) { character.faceDirection(finalFacingDirection); } if (NPCSchedule) { NPC npc = character as NPC; npc.DirectionsToNewLocation = null; npc.endOfRouteMessage.Value = npc.nextEndOfRouteMessage; } if (endBehaviorFunction != null) { endBehaviorFunction(character, location); } } return; } Farmer farmer = character as Farmer; if (farmer != null) { farmer.movementDirections.Clear(); } else if (!(location is MovieTheater)) { string name = character.Name; foreach (NPC c in location.characters) { if (!c.Equals(character) && c.GetBoundingBox().Intersects(bbox) && c.isMoving() && string.Compare(c.Name, name, StringComparison.Ordinal) < 0) { character.Halt(); return; } } } if (bbox.Left < targetTile.Left && bbox.Right < targetTile.Right) { character.SetMovingRight(b: true); } else if (bbox.Right > targetTile.Right && bbox.Left > targetTile.Left) { character.SetMovingLeft(b: true); } else if (bbox.Top <= targetTile.Top) { character.SetMovingDown(b: true); } else if (bbox.Bottom >= targetTile.Bottom - 2) { character.SetMovingUp(b: true); } character.MovePosition(time, Game1.viewport, location); if (nonDestructivePathing) { if (targetTile.Intersects(character.nextPosition(character.facingDirection))) { Vector2 next_position = character.nextPositionVector2(); Object next_tile_object = location.getObjectAt((int)next_position.X, (int)next_position.Y); if (next_tile_object != null) { Fence fence; if ((fence = (next_tile_object as Fence)) != null && (bool)fence.isGate) { fence.toggleGate(location, open: true); } else if (!next_tile_object.isPassable()) { character.Halt(); character.controller = null; return; } } } handleWarps(character.nextPosition(character.getDirection())); } else if (NPCSchedule) { handleWarps(character.nextPosition(character.getDirection())); } }
private void moveCharacter(GameTime time) { Rectangle targetTile = new Rectangle(pathToEndPoint.Peek().X * 64, pathToEndPoint.Peek().Y * 64, 64, 64); targetTile.Inflate(-2, 0); Rectangle bbox = character.GetBoundingBox(); if ((targetTile.Contains(bbox) || (bbox.Width > targetTile.Width && targetTile.Contains(bbox.Center))) && targetTile.Bottom - bbox.Bottom >= 2) { timerSinceLastCheckPoint = 0; pathToEndPoint.Pop(); character.stopWithoutChangingFrame(); if (pathToEndPoint.Count == 0) { character.Halt(); if (finalFacingDirection != -1) { character.faceDirection(finalFacingDirection); } if (NPCSchedule) { (character as NPC).DirectionsToNewLocation = null; (character as NPC).endOfRouteMessage.Value = (character as NPC).nextEndOfRouteMessage; } if (endBehaviorFunction != null) { endBehaviorFunction(character, location); } } return; } if (character is Farmer) { (character as Farmer).movementDirections.Clear(); } else if (!(location is MovieTheater)) { foreach (NPC c in location.characters) { if (!c.Equals(character) && c.GetBoundingBox().Intersects(bbox) && c.isMoving() && string.Compare(c.Name, character.Name) < 0) { character.Halt(); return; } } } if (bbox.Left < targetTile.Left && bbox.Right < targetTile.Right) { character.SetMovingRight(b: true); } else if (bbox.Right > targetTile.Right && bbox.Left > targetTile.Left) { character.SetMovingLeft(b: true); } else if (bbox.Top <= targetTile.Top) { character.SetMovingDown(b: true); } else if (bbox.Bottom >= targetTile.Bottom - 2) { character.SetMovingUp(b: true); } character.MovePosition(time, Game1.viewport, location); if (NPCSchedule) { handleWarps(character.nextPosition(character.getDirection())); } }
public bool update(GameTime time, GameLocation location, List <NPCController> allControllers) { puppet.speed = speed; bool reachedMeYet = false; foreach (NPCController i in allControllers) { if (i.puppet != null) { if (i.puppet.Equals(puppet)) { reachedMeYet = true; } if (i.puppet.FacingDirection == puppet.FacingDirection && !i.puppet.Equals(puppet) && i.puppet.GetBoundingBox().Intersects(puppet.nextPosition(puppet.FacingDirection))) { if (reachedMeYet) { break; } return(false); } } } if (puppet is Farmer) { (puppet as Farmer).setRunning(isRunning: false, force: true); puppet.speed = 2; (puppet as Farmer).ignoreCollisions = true; } if (puppet is Farmer && Game1.CurrentEvent != null && Game1.CurrentEvent.farmer != puppet) { (puppet as Farmer).updateMovementAnimation(time); } puppet.MovePosition(time, Game1.viewport, location); if (pauseTime < 0 && !puppet.isMoving()) { setMoving(newTarget: false); } if (pauseTime < 0 && Math.Abs(Vector2.Distance(puppet.Position, target)) <= (float)puppet.Speed) { pathIndex++; if (destroyAtNextTurn) { return(true); } if (!setMoving(newTarget: true)) { if (loop) { pathIndex = 0; setMoving(newTarget: true); } else if (Game1.currentMinigame == null) { if (behaviorAtEnd != null) { behaviorAtEnd(); } return(true); } } } else if (pauseTime >= 0) { pauseTime -= time.ElapsedGameTime.Milliseconds; if (pauseTime < 0) { pathIndex++; if (destroyAtNextTurn) { return(true); } if (!setMoving(newTarget: true)) { if (loop) { pathIndex = 0; setMoving(newTarget: true); } else if (Game1.currentMinigame == null) { if (behaviorAtEnd != null) { behaviorAtEnd(); } return(true); } } } } return(false); }