/// <summary> /// Get player start position in pixels. /// </summary> /// <param name="level"></param> /// <param name="playerName">Name of object</param> /// <param name="x"></param> /// <param name="y"></param> public static void GetPlayerStartPosition(SosEngine.Level level, string playerName, out int x, out int y) { x = 0; y = 0; List <SosEngine.LevelObject> players = level.GetLevelObjects("Objects", "Player"); if (players.Exists(p => p.Name == playerName)) { SosEngine.LevelObject player = players.Find(p => p.Name == playerName); x = player.X; y = player.Y; } }
public PlayScene(Game game, string levelName, PlayerStats playerStats = null, PlayScene mainScene = null) : base(game) { this.levelName = levelName; replay = new SosEngine.Replay("C:\\Temp\\mario.rec", SosEngine.Replay.Mode.Standby); BackgroundColor = new Color(0, 128, 240); font = SosEngine.Core.GetBitmapFont("font"); // // Level // level = new SosEngine.Level(game, levelName, 0, 0); Mario.Helpers.LevelHelper.SetupTileAnimation(level); level.SetupAnimatedTiles("Block"); level.HideLayer("Items"); var backgroundImage = level.GetCustomProperty("BackgroundImage"); if (backgroundImage != "") { background = SosEngine.Core.LoadTextureWithoutCache("bg_sky"); SetBackground(background); } else { BackgroundColor = new Color(0, 0, 0); } var parallax2Objects = level.GetLevelObjects("Objects", "Parallax2"); foreach (var levelObject in parallax2Objects) { level.AddParallaxSprite(new SosEngine.Sprite(game, levelObject.Name, levelObject.X, levelObject.Y), 4); } var parallax1Objects = level.GetLevelObjects("Objects", "Parallax1"); foreach (var levelObject in parallax1Objects) { level.AddParallaxSprite(new SosEngine.Sprite(game, levelObject.Name, levelObject.X, levelObject.Y), 2); } // // Entities // entityManager = new EntityManager(game, level); // // Player // player = new Objects.Player(game, "mario_move_0", level); player.MainPlayScene = mainScene; player.CenterOnScreen(); int playerX; int playerY; Helpers.LevelHelper.GetPlayerStartPosition(level, "Player", out playerX, out playerY); player.Position = new Vector2(playerX - 8, playerY); player.EntityManager = entityManager; if (playerStats != null) { player.Stats = playerStats; } // // Hud // hud = new Hud(game); hud.ShowFps = false; hud.ShowSpecialKeys = true; hud.SetData(1, 1, 100); // // Editor // editor = new SosEngine.Editor(game, level); editor.Visible = true; gameComponents.Add(level); gameComponents.Add(hud); gameComponents.Add(entityManager); gameComponents.Add(player); gameComponents.Add(editor); var pipeIns = level.GetLevelObjects("Objects", "PipeIn"); foreach (var pipeIn in pipeIns) { var pipe = new Pipe(game, pipeIn.Bounds, level, Pipe.PipeTypes.Entrance, pipeIn.Name); AddGameComponent(pipe); player.AddPipe(pipe); } var pipeOuts = level.GetLevelObjects("Objects", "PipeOut"); foreach (var pipeOut in pipeOuts) { var pipe = new Pipe(game, pipeOut.Bounds, level, Pipe.PipeTypes.Exit, pipeOut.Name); AddGameComponent(pipe); player.AddPipe(pipe); } }