Ejemplo n.º 1
0
 public void AddObserver(ILevelObserver observer)
 {
     if (observers.Contains(observer))
     {
         return;
     }
     observers.Add(observer);
 }
Ejemplo n.º 2
0
 public void RemoveObserver(ILevelObserver o)
 {
     levelObservers.Remove(o);
 }
Ejemplo n.º 3
0
 public void AddObserver(ILevelObserver o)
 {
     levelObservers.Add(o);
 }
        //TAR HAND OM SPELAREN KOLLISIONE
        private Vector2 Collide(Vector2 a_oldPos, Vector2 a_newPos, Vector2 a_size, ref Vector2 a_velocity, out bool a_outCollideGround, float a_elapsedTime, ILevelObserver a_observer)
        {
            a_outCollideGround = false;
            // m_hasCollidedWithGround = false;
            if (m_levels.IsCollidingAt(a_newPos, a_size))
            {
            //if not try only the X movement, indicates that a collision with ground or roof has occured
            Vector2 xMove = new Vector2(a_newPos.X, a_oldPos.Y);

            if (a_velocity.Y > 0 && a_oldPos.Y - (int)a_oldPos.Y > 0.9f)
            {
                xMove.Y = (int)a_oldPos.Y + 0.99f;
            }
            if (m_levels.IsCollidingAt(xMove, a_size) == false)
            {
                //did we collide with ground?
                if (a_velocity.Y > 0.0f)
                {
                    a_outCollideGround = true;
                    a_velocity.Y = 0; //no bounce
                }
                else
                {
                    //collide with roof
                    a_velocity.Y *= 0.0f; //reverse the y velocity and some speed lost in the collision
                }
                a_velocity.X *= 0.10f;// friction should be time-dependant
                return xMove;
            }
            else
            {
                //try Y movement, indicates that a collision with wall has occured
                Vector2 yMove = new Vector2(a_oldPos.X, a_newPos.Y);
                if (m_levels.IsCollidingAt(yMove, a_size) == false)
                {
                    a_velocity.X *= 0.5f;
                    return yMove;
                }

                if (a_velocity.Y > 0)
                {
                    a_outCollideGround = true;
                }
                a_velocity.X = 0; //no bounce
                a_velocity.Y = 0; //no bounce

            }
            //remain at the same position
            return a_oldPos;
            }
            return a_newPos;
        }
 internal void DoDeath(ILevelObserver a_observer)
 {
     a_observer.Death();
 }
        //EN UPPDATE SOM HÅLLER REDA PÅ SPELAREN
        public void UpdatePlayer(float a_elapsedTime, SoundObserver a_sound, ILevelObserver a_observer, int difficulty)
        {
            Vector2 oldPos = m_player.GetPosition();
            //get a new position for the player
            m_player.Update(a_elapsedTime);
            Vector2 newPos = m_player.GetPosition();
            m_hasCollidedWithGround = false;
            Vector2 speed = m_player.GetSpeed();
            Vector2 afterCollidedPos = Collide(oldPos, newPos, m_player.m_sizes, ref speed, out m_hasCollidedWithGround, a_elapsedTime, a_observer);
            //set the new speed and position after collision
            m_player.SetPosition(afterCollidedPos.X, afterCollidedPos.Y);
            m_player.SetPosition(afterCollidedPos.X, afterCollidedPos.Y);
            m_player.SetSpeed(speed.X, speed.Y);

            //KOLLAR OM MAN HAR KOLLIDERAT MED EN TEDDY
            if (m_levels.IsCollidingAtTeddy(newPos, m_player.m_sizes, a_sound))
            {

            m_player.SetSpeed(-2, 0);
            a_sound.ScreamSound();

            }
            /*if(m_levels.IsCollidingAtEnemy(newPos, m_player.m_sizes, m_player))
            {
            if(!hasBeenHit)
            {
                m_player.SetLifeChange(m_modelEnemy.GetEnemyDamage(), true);
                hasBeenHit = true;
            }
            }*/
            //KOLLAR OM MAN HAR KOLLIDERAT MED FÄLLORA
            if (m_levels.IsCollidingAtTrap(newPos, m_player.m_sizes))
            {
            DoDeath(a_observer);
            }
            /* if (m_levels.IsCollidingAtBoltEnemy(newPos, m_player.m_sizes))
            {
            m_player.SetPosition(5, 15);
            m_player.SetSpeed(0, 0);
            }*/

            //KOLLAR OM MAN KILLIDERAT MED HJÄRTAT; INTE IMPLEMENTERAT MEN FUNKTIONEN FINNS
            if (m_levels.IsCollidingAtHeart(newPos, m_player.m_sizes, a_sound))
            {
            // m_playerHp += 50;
            }

            //KOLLAR KOLLISIONEN MED RUSHINGENEMY
            if(CollideWithRushingEnemy(newPos))
            {
            //  m_levels.Restart(a_observer);
            if (!hasBeenHit)
            {
                m_player.SetLifeChange(m_modelEnemy.GetEnemyDamage(), true);
                hasBeenHit = true;
            }
            if (!m_player.IsAlive())
            {
                DoDeath(a_observer);
            }
            }

            //KOLLAR KOLLISIONEN MED BOLT ENEMY
            if (CollideWithBoltEnemy(newPos))
            {
            if (!hasBeenHit)
            {
                m_player.SetLifeChange(m_modelEnemyBolt.GetEnemyDamage(), true);
                hasBeenHit = true;
            }
            if (!m_player.IsAlive())
            {
                DoDeath(a_observer);
            }
            }

            //KOLLAR OM MAN HAR KOLLIDERAT MED SLUTET AV BANAN.
            if (afterCollidedPos.X > Levels.g_levelWidth - 3)
            {
            speed = new Vector2(0.0f, 0.0f);
            afterCollidedPos = new Vector2(5.0f, 0.0f);
            hasReachedEnd = true;

            }
        }
 public void Update(float a_elapsedTime ,SoundObserver a_sound, ILevelObserver a_observer, int difficulty)
 {
     m_levels.GetLevelState(m_stateHandler.GetLevelState());
     UpdatePlayer(a_elapsedTime, a_sound, a_observer, difficulty);
     UpdateEnemy(a_elapsedTime, a_sound);
     UpdateBoltEnemy(a_elapsedTime);
     DamageTimer(a_elapsedTime);
 }
Ejemplo n.º 8
0
 public void RemoveObserver(ILevelObserver observer)
 {
     observers.Remove(observer);
 }