Exemple #1
0
        public void PathsFinderTestManhattanDistance()
        {
            var entity   = new BaseMovable();
            var endPoint = new Point();

            var collisionSystem = new CompositeAbstractCollisionSystem(new EightWayPossibleMovement(new ManhattanDistance()));
            var tileSize        = new Point();
            var searchParams    = new SearchParameters(entity.Position.ToPoint(), endPoint, collisionSystem, new Rectangle(new Point(), tileSize));
            var path            = new AStarPathFinder(searchParams, new EightWayPossibleMovement(new ManhattanDistance()));

            Assert.AreNotSame(path.ClosedNodes, path.MapNodes);
        }
        public OpenWorldGameMode(ViewportAdapter viewPort, IPossibleMovements possibleMovements, string worldName, EntityManager entityManager, StoryEngine storyEngine, EventHandler clickEvent) : base(clickEvent)
        {
            _entityManager      = entityManager;
            EntityRenderersDict = new Dictionary <Entity, AbstractEntityRenderer>();
            _possibleMovements  = possibleMovements;
            _content            = ContentManagerFactory.RequestContentManager();
            RenderList          = new List <IRenderable>();
            Map = _content.Load <TiledMap>($"TopDownRpg/{worldName}");
            var graphics = StaticServiceLocator.GetService <GraphicsDevice>();

            _mapRenderer = new FullMapRenderer(graphics);
            _mapRenderer.SwapMap(Map);
            _tileSize     = new Vector2(Map.TileWidth, Map.TileHeight);
            _moverManager = new MoverManager();
            var collisionSystem = new CompositeAbstractCollisionSystem(_possibleMovements);

            _expiringSpatialHash = new ExpiringSpatialHashCollisionSystem <Entity>(_possibleMovements);
            _spatialHashMover    = new SpatialHashMoverManager <Entity>(collisionSystem, _expiringSpatialHash);
            AddPlayer();
            var entityController = EntityControllerFactory.AddEntityController(PlayerEntity.Instance, _possibleMovements, _moverManager);
            var texture          = _content.Load <Texture2D>("TopDownRpg/Path");
            var endTexture       = _content.Load <Texture2D>("TopDownRpg/BluePathEnd");

            collisionSystem.AddCollisionSystem(new TiledCollisionSystem(_possibleMovements, Map, "Collision-Layer"));
            collisionSystem.AddCollisionSystem(_expiringSpatialHash);
            CollisionSystem = collisionSystem;
            AddClickController(PlayerEntity.Instance);
            PathRenderer = new PathRenderer(_moverManager, PlayerEntity.Instance, texture, endTexture, _tileSize.ToPoint(), Map.Width, Map.Height);
            UpdateList.Add(_expiringSpatialHash);
            UpdateList.Add(entityController);
            UpdateList.Add(_spatialHashMover);
            UpdateList.Add(_moverManager);
            CameraTracker = CameraTrackerFactory.CreateTracker(viewPort, EntityRenderersDict[PlayerEntity.Instance], Map);
            UpdateList.Add(CameraTracker);
            LoadEntities();
            var dialogFont = _content.Load <SpriteFont>("dialog");
            var settings   = StaticServiceLocator.GetService <IControllerSettings>();

            DialogBox = new EntityStoryBoxDialog(ScreenSize.Size, dialogFont, settings.GamePadEnabled);
            GuiManager.AddGuiLayer(DialogBox);
            storyEngine.LoadWorld(AddEntity, RemoveEntity, CollisionSystem.CheckMovementCollision, worldName);
            InteractEvent += (sender, args) =>
            {
                var facingDirection = PlayerEntity.Instance.FacingDirection;
                var interactTarget  = (PlayerEntity.Instance.Position + facingDirection).ToPoint();
                Interact(interactTarget);
            };
            AddInteractionController();
            CameraController.AddCameraZoomController(CameraTracker, ClickController);
            CameraController.AddCameraMovementController(CameraTracker, ClickController);
        }