コード例 #1
0
ファイル: GameModel.cs プロジェクト: tn222eb/1DV437-Projekt
 /// <summary>
 /// Check if player have collided with bomb
 /// </summary>
 /// <param name="soundObserver"></param>
 private void CheckIfCollideWithBomb(ISoundObserver soundObserver)
 {
     foreach (Bomb bomb in m_bombsList)
     {
         if (CollisionHandler.IsCollidingWithBomb(m_player, bomb))
         {
             m_player.RemoveLife();
             soundObserver.BombExplode();
         }
     }
 }
コード例 #2
0
ファイル: GameModel.cs プロジェクト: tn222eb/1DV437-Projekt
 /// <summary>
 /// Check if player have collided with coin
 /// </summary>
 /// <param name="soundObserver"></param>
 private void CheckIfPlayerPickedUpCoin(ISoundObserver soundObserver, IPickUpObserver pickUpObserver)
 {
     for (int i = 0; i < m_coinList.Count; i++)
     {
         if (CollisionHandler.IsCollidingWithCoin(m_player, m_coinList[i]))
         {
             pickUpObserver.PlayerPickUpCoinAt(m_coinList[i].Position);
             m_coinList.Remove(m_coinList[i]);
             soundObserver.PlayerPickUpCoin();
         }
     }
 }
コード例 #3
0
ファイル: GameModel.cs プロジェクト: tn222eb/1DV437-Projekt
        private void UpdatePlayer(float totalElapsedSeconds)
        {
            Vector2 oldPosition = m_player.Position;

            m_player.Update(totalElapsedSeconds);
            Vector2 newPosition = m_player.Position;

            m_hasCollidedWithGround = false;
            Vector2 velocity = m_player.Velocity;

            if (CollisionHandler.didCollide(newPosition, m_player.Size, m_level))
            {
                CollisionDetails details = CollisionHandler.getCollisionDetails(oldPosition, newPosition, m_player.Size, velocity, m_level);
                m_hasCollidedWithGround = details.m_hasCollidedWithGround;

                m_player.Position = details.m_positionAfterCollision;
                m_player.Velocity = details.m_speedAfterCollision;
            }
        }