Пример #1
0
        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()));
            }
        }
Пример #3
0
        private void moveCharacter(GameTime time)
        {
            Rectangle rectangle = new Rectangle(this.pathToEndPoint.Peek().X *Game1.tileSize, this.pathToEndPoint.Peek().Y *Game1.tileSize, Game1.tileSize, Game1.tileSize);

            rectangle.Inflate(-2, 0);
            Rectangle boundingBox = this.character.GetBoundingBox();

            if ((rectangle.Contains(boundingBox) || boundingBox.Width > rectangle.Width && rectangle.Contains(boundingBox.Center)) && rectangle.Bottom - boundingBox.Bottom >= 2)
            {
                this.timerSinceLastCheckPoint = 0;
                this.pathToEndPoint.Pop();
                this.character.stopWithoutChangingFrame();
                if (this.pathToEndPoint.Count != 0)
                {
                    return;
                }
                this.character.Halt();
                if (this.finalFacingDirection != -1)
                {
                    this.character.faceDirection(this.finalFacingDirection);
                }
                if (this.NPCSchedule)
                {
                    (this.character as NPC).DirectionsToNewLocation = (SchedulePathDescription)null;
                    (this.character as NPC).endOfRouteMessage       = (this.character as NPC).nextEndOfRouteMessage;
                }
                if (this.endBehaviorFunction == null)
                {
                    return;
                }
                this.endBehaviorFunction(this.character, this.location);
            }
            else
            {
                if (this.character is Farmer)
                {
                    (this.character as Farmer).movementDirections.Clear();
                }
                else
                {
                    foreach (NPC character in this.location.characters)
                    {
                        if (!character.Equals((object)this.character) && (character.GetBoundingBox().Intersects(boundingBox) && character.isMoving() && string.Compare(character.name, this.character.name) < 0))
                        {
                            this.character.Halt();
                            return;
                        }
                    }
                }
                if (boundingBox.Left < rectangle.Left && boundingBox.Right < rectangle.Right)
                {
                    this.character.SetMovingRight(true);
                }
                else if (boundingBox.Right > rectangle.Right && boundingBox.Left > rectangle.Left)
                {
                    this.character.SetMovingLeft(true);
                }
                else if (boundingBox.Top <= rectangle.Top)
                {
                    this.character.SetMovingDown(true);
                }
                else if (boundingBox.Bottom >= rectangle.Bottom - 2)
                {
                    this.character.SetMovingUp(true);
                }
                this.character.MovePosition(time, Game1.viewport, this.location);
                if (!this.NPCSchedule)
                {
                    return;
                }
                Warp warp = this.location.isCollidingWithWarpOrDoor(this.character.nextPosition(this.character.getDirection()));
                if (warp == null)
                {
                    return;
                }
                if (this.character is NPC && (this.character as NPC).isMarried() && (this.character as NPC).followSchedule)
                {
                    NPC character = this.character as NPC;
                    if (this.location is FarmHouse)
                    {
                        warp = new Warp(warp.X, warp.Y, "BusStop", 0, 23, false);
                    }
                    if (this.location is BusStop && warp.X <= 0)
                    {
                        warp = new Warp(warp.X, warp.Y, character.getHome().name, (character.getHome() as FarmHouse).getEntryLocation().X, (character.getHome() as FarmHouse).getEntryLocation().Y, false);
                    }
                    if (character.temporaryController != null && character.controller != null)
                    {
                        character.controller.location = Game1.getLocationFromName(warp.TargetName);
                    }
                }
                Game1.warpCharacter(this.character as NPC, warp.TargetName, new Vector2((float)warp.TargetX, (float)warp.TargetY), false, this.location.isOutdoors);
                this.location.characters.Remove(this.character as NPC);
                if (this.location.Equals((object)Game1.currentLocation) && Utility.isOnScreen(new Vector2((float)(warp.X * Game1.tileSize), (float)(warp.Y * Game1.tileSize)), Game1.tileSize * 6) && this.location.doors.ContainsKey(new Point(warp.X, warp.Y)))
                {
                    Game1.playSound("doorClose");
                }
                this.location = Game1.getLocationFromName(warp.TargetName);
                if (this.location.Equals((object)Game1.currentLocation) && Utility.isOnScreen(new Vector2((float)(warp.TargetX * Game1.tileSize), (float)(warp.TargetY * Game1.tileSize)), Game1.tileSize * 6) && this.location.doors.ContainsKey(new Point(warp.TargetX, warp.TargetY - 1)))
                {
                    Game1.playSound("doorClose");
                }
                if (this.pathToEndPoint.Count > 0)
                {
                    this.pathToEndPoint.Pop();
                }
                while (this.pathToEndPoint.Count > 0 && (Math.Abs(this.pathToEndPoint.Peek().X - this.character.getTileX()) > 1 || Math.Abs(this.pathToEndPoint.Peek().Y - this.character.getTileY()) > 1))
                {
                    this.pathToEndPoint.Pop();
                }
            }
        }