/// <summary> /// Default constructor. /// </summary> /// <param name="title"> Level title.</param> /// <param name="game"> Game.</param> public Level(string title, SuperPlatformerGame game) { CurrentTime = 0; Gravity = 550; // Create the lists. _entities = new List <Entity>(); _pendingEntities = new List <Entity>(); _decorations = new List <MonoSprite>(); _backgroundTiles = new List <Tile>(); // Time moves on. _time = new TimedEvent(OnTimeTick, 1000); _time.Enable(); // Time to respawn _respawnTimer = new TimedEvent(OnRespawnTimerElapsed, 3000); // Wait X seconds before switching to end level scene on level finished. _endTimer = new TimedEvent(() => { game.SceneActivator.ActivateScene(new EndLevelScene(game)); }, 4000); _scale = SuperPlatformerGame.SCALE; _viewport = game.GraphicsDevice.Viewport; _title = title; _collisions = new CollisionTester(); _camera = new Camera2D(_viewport); Player = new Player(game.Content.Load <Texture2D>("Images/Player/Protagonist"), Vector2.Zero, 16, 22, game.KeyboardDevice, this, game.Content); // Listen to some player events Player.OnSizeChanged += OnPlayerSizeChange; Player.OnDied += OnPlayerDeath; Score = new ScoreCollector(); TypePlayer = PlayerType.PROTAGONIST; Display = new HUD(this, _camera, game.Content); _collidables = new List <Entity>(); _camera.Follow(Player); }
/// <summary> /// Load the level. /// </summary> /// <param name="game"> The game object.</param> /// <param name="fileName"> The filename of the level file.</param> public void Load(SuperPlatformerGame game, string fileName) { _loader = new LevelLoader(_title, this, game); _loader.Parse(@"Resources/Data/" + fileName + ".json"); // Load background Texture2D texture = game.Content.Load <Texture2D>(_loader.GetBackgroundPath()); MonoSprite backgroundImageLeft = new MonoSprite(texture, new Rectangle(0, 0, 512, 432), Vector2.Zero, 512, 432); MonoSprite backgroundImageRight = new MonoSprite(texture, new Rectangle(0, 0, 512, 432), Vector2.Zero, 512, 432); _background = new ParallaxBackground(_camera, backgroundImageLeft, backgroundImageRight); // Set the current time to the given level duration CurrentTime = _loader.GetTotalTime(); // Set the given tilesize _tileSize = _loader.GetTileSize(); // Initialize the background tiles _loader.InitializeBackgroundTiles(out _backgroundTiles); // Initialize the decorations _loader.InitializeDecoration(out _decorations); // Set the player spawn point _spawn = _loader.GetSpawnPoint(); // Initialize the player's position Player.Position = _spawn; // Load entities LoadEntities(); // Set pixel sizes PixelSizeX = (_loader.TilesX * _tileSize) * (int)_scale; PixelSizeY = (_loader.TilesY * _tileSize) * (int)_scale; // Set camera bounds _camera.SetBounds(PixelSizeX, PixelSizeY); }
/// <summary> /// Constructor /// </summary> /// <param name="game">The game this scene belongs to</param> public IntroScene(SuperPlatformerGame game) : base(game) { _introPhaseDuration = 2000; }
/// <summary> /// Default constructor. /// </summary> /// <param name="game"> The game.</param> /// <param name="levelTag"> The level tag.</param> public LevelScene(SuperPlatformerGame game, string levelTag) : base(game) { _levelTag = levelTag; BackgroundColor = Color.Bisque; }
/// <summary> /// Default constructor. /// </summary> /// <param name="game">The game this scene belongs to</param> public MainMenuScene(SuperPlatformerGame game) : base(game) { // }
/// <summary> /// Constructor. /// </summary> /// <param name="levelTag"> Level tag.</param> /// <param name="level"> Level object.</param> /// <param name="game"> Game object.</param> public LevelLoader(string levelTag, Level level, SuperPlatformerGame game) { _levelTag = levelTag; _level = level; _game = game; }
/// <summary> /// Constructor /// </summary> /// <param name="game"> The game this scene belongs to.</param> public GameOverScene(SuperPlatformerGame game) : base(game) { _duration = 5000; }
/// <summary> /// Constructor /// </summary> /// <param name="game"> The game this scene belongs to.</param> public EndLevelScene(SuperPlatformerGame game) : base(game) { _endDuration = 3500; }
/// <summary> /// Constructor. /// </summary> public MonoScene(SuperPlatformerGame game) { Game = game; Children = new List <MonoObject>(); BackgroundColor = Color.Black; }
/// <summary> /// Constructor /// </summary> /// <param name="game"> The game this scene belongs to.</param> public TimeUpScene(SuperPlatformerGame game) : base(game) { _duration = 5000; }