Beispiel #1
0
        /// <summary>
        /// Creates a new player for a specific level
        /// </summary>
        /// <param name="level">The Level that the player should play in</param>
        /// <param name="location">The starting location of the player</param>
        /// <param name="score">The initial score of the player. Default is 0.</param>
        public PlayerGameObject(Level level, Point location, int score = 0) : base(level.Tiles, level.TimeBetweenActions, "player@4x4", 0, "")
        {
            player = new DummyPlayer(level.Tiles, location, score);
            Level  = level;
            Teleport(location);
            TileField.RevealArea(location);
            soundFootsteps = GameEnvironment.AssetManager.Content.Load <SoundEffect>("footsteps").CreateInstance();

            player.OnPlayerAction += delegate(DummyPlayer player) { OnPlayerAction?.Invoke(this); };
            player.OnPlayerWin    += delegate(DummyPlayer player) { OnPlayerWin?.Invoke(this); };
            player.OnPlayerLose   += delegate(DummyPlayer player)
            {
                OnPlayerLose?.Invoke(this);
                GameEnvironment.AssetManager.PlaySound("scream");
            };
            player.OnMoveSmoothly += delegate(DummyPlayer player, Direction direction)
            {
                MoveSmoothly(direction);
                soundFootsteps.Play();
            };
            player.OnTeleport += delegate(DummyPlayer player)
            {
                Teleport(player.Location);
                GameEnvironment.AssetManager.PlaySound("climbing_sound");
            };
            StoppedMoving += delegate(GameObject obj)
            {
                player.EndMoveSmoothly();
                soundFootsteps.Stop();
            };
        }
        private void HandleEnemyReachedEnd(EnemyData enemyData)
        {
            health = Mathf.Max(health - enemyData.Damage);

            OnHealthChanged?.Invoke(health);

            if (health != 0)
            {
                return;
            }

            OnPlayerLose?.Invoke();
        }
 public void PlayerLoseGame()
 {
     if (IsGameOver)
     {
         return;
     }
     if (GameState != GameStates.Playing)
     {
         return;
     }
     GameState = GameStates.Finish;
     OnPlayerLose?.Invoke();
     GameOver();
 }
Beispiel #4
0
        /// <summary>
        /// Kill player and decrement 1 life.
        /// Player will be automatically moved to his origin.
        /// </summary>
        public void Die()
        {
            // Player can't die if is invincible
            if (_invincibleTimer > 0.0f)
            {
                return;
            }

            _lives--;

            _position        = _targetPosition = _origin;
            _invincibleTimer = _invincibleTimeAfterDie;

            if (_lives == 0)
            {
                OnPlayerLose?.Invoke();
            }
        }
Beispiel #5
0
 private void OnDisable()
 {
     OnPlayerLose?.Invoke();
 }
Beispiel #6
0
 /// <summary>
 /// Makes the player lose the game
 /// </summary>
 public void Lose()
 {
     OnPlayerLose?.Invoke(this);
 }