public void LoadOpenWorld(string levelName) { var possibleMovements = StaticServiceLocator.GetService <IPossibleMovements>(); _possibleMovements = new PossibleMovementWrapper(possibleMovements); ClickEvent = (sender, args) => { Action action = Show <MainMenuScreen>; action.Invoke(); }; OpenWorldGameMode = new OpenWorldGameMode(_viewPort, _possibleMovements, levelName, _entityManager, _storyEngine, ClickEvent); var map = OpenWorldGameMode.Map; var player = PlayerEntity.Instance; var grassLayer = map.GetLayer <TiledTileLayer>("Grass-Layer"); if (grassLayer != null) { var grassCollisionSystem = new TiledCollisionSystem(_possibleMovements, map, "Grass-Layer"); PlayerEntity.Instance.OnMoveEvent += (sender, args) => { var point = player.Position.ToPoint(); var grassCollision = grassCollisionSystem.CheckCollision(point); if (grassCollision) { player.SpeedContext.Terrain = new SpeedGrass(); } else if (player.SpeedContext.Terrain != null) { player.SpeedContext.Terrain = null; } }; } var teleportlayer = map.GetObjectGroup("Teleport-Layer"); if (teleportlayer != null) { var tileSize = new Point(map.TileWidth, map.TileHeight); var teleporters = new TiledObjectCollisionSystem(_possibleMovements, map, tileSize, "Teleport-Layer"); PlayerEntity.Instance.OnMoveEvent += (sender, args) => { var point = player.Position.ToPoint(); if (teleporters.CheckCollision(point)) { var teleporter = teleporters.GetObjectAt(point); var position = StringToVector.ConvertString(teleporter.Type); PlayerEntity.Instance = new PlayerEntity(position); GameModeStack.Unload(); LoadOpenWorld(teleporter.Name); } }; } GameModes.Push(OpenWorldGameMode); }
public TopDownRpgScene(ViewportAdapter viewPort, SpriteBatch spriteBatch) { _viewPort = viewPort; _spriteBatch = spriteBatch; BattleProbability = 12; Move moveDelegate = (entity, point) => OpenWorldGameMode.BeginMoveTo(entity, point); _entityManager = new EntityManager(moveDelegate); var gameModeController = new GameModeController { PushGameModeDelegate = mode => GameModes.Push(mode), PopGameModeDelegate = () => GameModes.Pop() }; Say say = story => OpenWorldGameMode.DialogBox.StartStory(story); _storyEngine = new StoryEngine(gameModeController, moveDelegate, LoadOpenWorld, say); }