Exemple #1
0
        /// <summary>
        /// Initialize scene.
        /// </summary>
        public override void Init()
        {
            // Call base init.
            base.Init();

            // Set texture of the scene.
            Texture2D texture = Game.Content.Load <Texture2D>("Images/Screens/GameOver");

            // Load the nintendo logo.
            MonoSprite logo = new MonoSprite(texture, new Rectangle(0, 0, SuperPlatformerGame.RESOLUTION_X, SuperPlatformerGame.RESOLUTION_Y), Vector2.Zero, SuperPlatformerGame.RESOLUTION_X, SuperPlatformerGame.RESOLUTION_Y);

            // Add the logo to the drawlist.
            Children.Add(logo);

            _sound = Game.Content.Load <SoundEffect>("Audio/smw_gameover");

            if (_sound != null)
            {
                _sound.Play();
            }

            // Set and start the timer.
            _durationTimer = new TimedEvent(OnTimerElapsed, _duration);
            _durationTimer.Enable();
        }
Exemple #2
0
 /// <summary>
 /// Activated when player finished the level.
 /// </summary>
 /// <param name="sender"> The sender.</param>
 /// <param name="e"> The event arguments.</param>
 private void OnFinished(object sender, EventArgs e)
 {
     MediaPlayer.Stop();
     Player.OnPeace();
     _endTimer.Enable();
     _time.Disable();
 }
Exemple #3
0
        /// <summary>
        /// Set direction in opisite direction.
        /// </summary>
        private void Turn()
        {
            // Switch direction.
            _direction = (Direction)(((int)_direction + 1) % 2);

            // Restart timer.
            _turnTimer.Enable();
        }
Exemple #4
0
 /// <summary>
 /// Starts the enemey death timer.
 /// </summary>
 protected void EnableDeathTimer()
 {
     // Enable death timer if it is not running.
     if (!_deathTimer.Running)
     {
         _deathTimer.Enable();
     }
 }
Exemple #5
0
        /// <summary>
        /// This method makes the player go to the big state.
        /// </summary>
        public void Grow()
        {
            PowerState = SizeState.BIG;

            Width  = _bigWidth;
            Height = _bigHeight;

            Vector2 position = Position;

            position.Y -= _bigHeight - _smallHeight;
            Position    = position;

            JumpImpulse = _bigJumpImpulse;

            OnSizeChanged?.Invoke(this, new SizeChangeEventArgs(PowerState));

            PlaySound("grow");

            _flickerTimer.Enable();
        }
Exemple #6
0
        /// <summary>
        /// Default constructor.
        /// </summary>
        /// <param name="position"> Position in the level.</param>
        /// <param name="width"> Width of the PlungerEnemy.</param>
        /// <param name="height"> Height of the PlungerEnemy.</param>
        /// <param name="content"> Content manager of the game.</param>
        /// <param name="level"> The level the PlungerEnemy is in.</param>
        public PlungerEnemy(Vector2 position, int width, int height, ContentManager content, Level level) : base(position, width, height, level)
        {
            Sprite = new MonoSprite(content.Load <Texture2D>("Images/Enemy/PlungerEnemy"), new Rectangle(0, 0, width, height), position, width, height);

            // Remove gravity.
            Gravity = 0;

            // PlungerEnemy is not solid.
            Solid = false;

            // PlungerEnemy shouldn't check for collisions.
            CheckCollisions = false;

            // Set default direction.
            _direction = Direction.Down;

            // Enemy doesnt walk.
            AllowMovement = false;

            // Set spawn position.
            _spawnPosition = position;

            // Set default height.
            _startHeight = height;

            // Set some padding
            Padding = new Vector2(3, 3);

            // This enemy is invunreble.
            Invulnerable = true;

            // Add biting animation.
            Animations.Add(new Animation(
                               id: (int)PlungerEnemyAnimation.BITING,
                               baseFrame: Vector2.Zero,
                               frameSize: new Vector2(width, height),
                               rows: 1,
                               columns: 2,
                               msPerFrame: 150
                               ));

            // Start biting animation.
            Animations.Play((int)PlungerEnemyAnimation.BITING);

            // Create timer.
            _turnTimer = new TimedEvent(Turn, 2250);

            // Start timer.
            _turnTimer.Enable();
        }
Exemple #7
0
        /// <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);
        }
Exemple #8
0
        /// <summary>
        /// Initialize scene.
        /// </summary>
        public override void Init()
        {
            // Call base init.
            base.Init();

            // Set texture of the scene.
            Texture2D texture = Game.Content.Load <Texture2D>("Images/Screens/Nintendo");

            // Load the nintendo logo.
            MonoSprite logo = new MonoSprite(texture, new Rectangle(0, 0, SuperPlatformerGame.RESOLUTION_X, SuperPlatformerGame.RESOLUTION_Y), Vector2.Zero, SuperPlatformerGame.RESOLUTION_X, SuperPlatformerGame.RESOLUTION_Y);

            // Add the logo to the drawlist.
            Children.Add(logo);

            // Set and start the timer.
            _introPhaseTimer = new TimedEvent(OnIntroPhaseTimerElapsed, _introPhaseDuration);
            _introPhaseTimer.Enable();
        }
Exemple #9
0
 /// <summary>
 /// Event when player died.
 /// </summary>
 /// <param name="sender"> The sender.</param>
 /// <param name="e"> The event arguments.</param>
 private void OnPlayerDeath(object sender, EventArgs e)
 {
     _respawnTimer.Reset();
     _respawnTimer.Enable();
 }
Exemple #10
0
 /// <summary>
 /// Callback every second.
 /// </summary>
 private void OnTimeTick()
 {
     CurrentTime--;
     _time.Enable();
 }