private static void PlayModeStarted() { var state = StatePreference.Value; if (state.LoadWorld) { var hasScene = !string.IsNullOrEmpty(state.MainScene); var hasZone = !string.IsNullOrEmpty(state.StartZone); var hasSpawn = !string.IsNullOrEmpty(state.StartSpawn); if (!hasScene && hasZone) { PlayModeFailed(_mainSceneNotSetError); } else if (hasScene && !hasZone) { PlayModeFailed(_noZonesError); } else { var game = hasScene && hasZone ? new GameSaveData { MainScene = state.MainScene, StartingZone = state.StartZone, PlayerSpawn = hasSpawn ? new SpawnPoint { Name = state.StartSpawn } : SpawnPoint.Default } : null; var result = WorldLoader.Load(game, FilePreference.Value); result.OnError = PlayModeFailed; } } }
private static void Main(string[] args) { var worldLoader = new WorldLoader(); var world = worldLoader.Load <World.World>("resources/world.json"); System.Console.WriteLine(world); }
/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. Universal.SpriteBatch = new SpriteBatch(GraphicsDevice); Universal.Content = this.Content; Textures.Load(); Sounds.Load(); Fonts.Load(); ScreenManager = new ScreenManager(); WorldLoader.Load(); //Add screens here ScreenManager.AddScreen(new MainScreen()); ScreenManager.AddScreen(new LevelSelectScreen()); ScreenManager.AddScreen(new GameScreen()); ScreenManager.AddScreen(new CreditsScreen()); }
public static void LoadLevel() { var path = EditorUtility.OpenFilePanel ( title: "Load level", directory: Kharynic.Engine.BuildInfo.LocalProjectPath + "/resources/levels", extension: "json" ); if (string.IsNullOrEmpty(path)) { return; } if (!path.StartsWith(Kharynic.Engine.BuildInfo.LocalProjectPath)) { throw new ArgumentException($"file access is limited to {Kharynic.Engine.BuildInfo.LocalProjectPath}"); } WorldLoader.Load(path.Substring(Kharynic.Engine.BuildInfo.LocalProjectPath.Length)); }
private static World LoadWorld(List <string> mazeLines) { var world = new World(); var loader = new WorldLoader(); for (char ch = 'A'; ch <= 'Z'; ch++) { var teleportSymbol = ch; loader.AddRule(ch, location => new Teleport(location, teleportSymbol)); } loader .AddRule('#', loc => new Wall(loc)) .AddRule('!', loc => new Gelu(loc)) .AddRule('$', loc => new Catherine(loc)) .AddRule('*', loc => new Sandro(loc)) .AddBorder('#'); loader.Load(mazeLines, world); return(world); }
/// <summary> /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// </summary> protected override void Initialize() { // TODO: Add your initialization logic here _renderHelper = new RenderHelper(); _renderHelper.Init(GraphicsDevice); _renderHelper.ActiveCamera.SetWorldConstrains(Vector2.Zero); _boxes = BoxLoader.LoadFromFile("Content/test_world.boxes"); _background = new BackgroundImage(); _background.Init(_renderHelper, _screenSize); _world = WorldLoader.Load("Content/level3.map", Content); _world.Init(_renderHelper, _screenSize); _renderHelper.ActiveCamera.WorldBotRight = new Vector2() { X = _world.Cols * _world.TileSize.X + 1, Y = _world.Rows * _world.TileSize.Y + 1 }; _boxes = WorldLoader.GenerateHitboxes(_world); var player1 = new Player(PlayerIndex.One); var player2 = new Player(PlayerIndex.Two); //var player3 = new Player(PlayerIndex.Three); _players.Add(player1); _players.Add(player2); //_players.Add(player3); _fonter = new Fonter(); _fonter.Init(_renderHelper, _screenSize); _fonter.Messages.Add(new Message(() => player1.PhysicsComponent.Position, () => "P1:\n" + player1.PhysicsComponent.Position)); _fonter.Messages.Add(new Message(() => player2.PhysicsComponent.Position, () => "P2:\n" + player2.PhysicsComponent.Position)); base.Initialize(); }
private static object DoLoad(string file, string ext) { if (ext == "grf") { return(File.OpenRead(file)); } else { using (var br = ReadSync(file)) { if (br == null) { throw new Exception($"Could not load file: {file}"); } switch (ext) { // Images case "jpg": case "jpeg": case "png": return(new RawImage() { data = br.ToArray() }); case "bmp": return(loader.LoadBMP(br)); case "tga": return(TGALoader.LoadTGA(br)); // Text case "txt": case "xml": case "lua": return(Encoding.UTF8.GetString(br.ToArray())); case "spr": SPR spr = SpriteLoader.Load(br); spr.SwitchToRGBA(); spr.Compile(); spr.filename = file; return(spr); case "str": return(EffectLoader.Load(br, Path.GetDirectoryName(file).Replace("\\", "/"))); case "act": return(ActionLoader.Load(br)); // Binary case "gat": return(AltitudeLoader.Load(br)); case "rsw": return(WorldLoader.Load(br)); case "gnd": return(GroundLoader.Load(br)); case "rsm": return(ModelLoader.Load(br)); // Audio case "wav": WAVLoader.WAVFile wav = WAVLoader.OpenWAV(br.ToArray()); AudioClip clip = AudioClip.Create(file, wav.samples, wav.channels, wav.sampleRate, false); clip.SetData(wav.leftChannel, 0); return(clip); case "mp3": case "ogg": break; case "json": return(JObject.Parse(Encoding.UTF8.GetString(br.ToArray()))); default: throw new Exception($"Unsuported file format: {ext} for file {file}"); } } } return(null); }
/* * public AtomIterator IterAtoms() { return new AtomIterator(this); } * public TileIterator IterTiles() { return new TileIterator(this); } * public LocIterator IterLocs() { return new LocIterator(this); } */ public void Load(string filename, WorldLoader wf) { wf.Load(this, filename); }
internal void Initialize() { World = worldLoader.Load(worldLoader.Maps.FirstOrDefault()); WorldDescriptor = new WorldDescriptor(World); }
private static object DoLoad(string file, string ext) { //string fileWOExt = file.Replace("." + ext, ""); switch (ext) { case "grf": return(File.OpenRead(file)); // Regular images files case "jpg": case "jpeg": case "png": using (var br = ReadSync(file)) { return(new RawImage() { data = br.ToArray() }); } case "bmp": using (var br = ReadSync(file)) return(loader.LoadBMP(br)); case "tga": using (var br = ReadSync(file)) return(TGALoader.LoadTGA(br)); // Texts case "txt": case "xml": case "lua": using (var br = ReadSync(file)) { if (br != null) { return(Encoding.UTF8.GetString(br.ToArray())); } else { return(null); } } case "spr": using (var br = ReadSync(file)) { if (br != null) { SPR spr = SpriteLoader.Load(br); spr.SwitchToRGBA(); spr.Compile(); spr.filename = file; return(spr); } else { return(null); } } case "str": using (var br = ReadSync(file)) { if (br != null) { STR str = EffectLoader.Load(br); return(str); } else { return(null); } } // Binary case "gat": using (var br = ReadSync(file)) return(new Altitude(br)); case "rsw": using (var br = ReadSync(file)) return(WorldLoader.Load(br)); case "gnd": using (var br = ReadSync(file)) return(GroundLoader.Load(br)); case "rsm": using (var br = ReadSync(file)) return(ModelLoader.Load(br)); // Audio case "wav": using (var br = ReadSync(file)) { WAVLoader.WAVFile wav = WAVLoader.OpenWAV(br.ToArray()); AudioClip clip = AudioClip.Create(file, wav.samples, wav.channels, wav.sampleRate, false); clip.SetData(wav.leftChannel, 0); return(clip); } case "mp3": case "ogg": case "act": //return new Action(ReadSync(file)).compile(); Debug.LogWarning("Can't read " + file + "\nLoader for " + ext + " is not implemented"); break; default: throw new System.Exception("Unknown file format: " + file); } return(null); }