Ejemplo n.º 1
0
    static void Main(string[] args)
    {
        // make observer
        AchievementObserver achievementObserver = new AchievementObserver();
        SoundObserver       soundObserver       = new SoundObserver();

        // make subject to observe
        Subject subject = new Subject();

        // make subject become observed
        subject.RegisterObserver(achievementObserver.CheckForAchievements);
        subject.RegisterObserver(soundObserver.CheckForJumpSound);

        // make player
        Player player = new Player(subject);

        ICommand command = null;

        while (GameShouldRun)
        {
            command = InputHandler.HandleInput();

            if (command != null)
            {
                command.Execute(player);
            }
        }

        subject.DeregisterObserver(achievementObserver.CheckForAchievements);
        subject.DeregisterObserver(soundObserver.CheckForJumpSound);
    }
Ejemplo n.º 2
0
    static void Main(string[] args)
    {
        // make observer
        AchievementObserver achievementObserver = new AchievementObserver();
        SoundObserver soundObserver = new SoundObserver();

        // make subject to observe
        Subject subject = new Subject();

        // make subject become observed
        subject.RegisterObserver(achievementObserver.CheckForAchievements);
        subject.RegisterObserver(soundObserver.CheckForJumpSound);

        // make player
        Player player = new Player(subject);

        ICommand command = null;

        while (GameShouldRun)
        {
            command = InputHandler.HandleInput();

            if (command != null)
                command.Execute(player);
        }

        subject.DeregisterObserver(achievementObserver.CheckForAchievements);
        subject.DeregisterObserver(soundObserver.CheckForJumpSound);
    }
Ejemplo n.º 3
0
 internal LegacyFilters(StaminaFilter staminaFilter, LightObserver lightObserver, WeatherObserver weatherObserver, SoundObserver soundObserver, ShapeshiftingFilter shapeShifter)
 {
     Stamina      = staminaFilter;
     Light        = lightObserver;
     Weather      = weatherObserver;
     Sound        = soundObserver;
     ShapeShifter = shapeShifter;
 }
Ejemplo n.º 4
0
        internal Legacy(Configuration configuration, CommandHandler commandHandler,
                        UltimaServer ultimaServer, UltimaClient ultimaClient, ILogger logger)
        {
            Trace = new GlobalTrace(logger);

            cancellation       = new Cancellation(() => CancellationToken);
            eventJournalSource = new EventJournalSource();
            Me = new Player(() => GameObjects.OfType <Item>().OnLayer(Layer.Mount).FirstOrDefault() != null,
                            ultimaServer, this, eventJournalSource);
            gumpObservers       = new GumpObservers(ultimaServer, ultimaClient, eventJournalSource, cancellation);
            GameObjects         = new GameObjectCollection(Me);
            Items               = new ItemCollection(GameObjects);
            Mobiles             = new MobileCollection(GameObjects);
            Corpses             = new CorpseCollection(GameObjects);
            itemsObserver       = new ItemsObservers(GameObjects, ultimaServer, ultimaClient, this, eventJournalSource);
            Me.LocationChanged += itemsObserver.OnPlayerPositionChanged;
            journalSource       = new SpeechJournalSource();
            journalSource.NewMessageReceived +=
                (sender, entry) => eventJournalSource.Publish(new SpeechReceivedEvent(entry));
            Journal          = new SpeechJournal(journalSource, cancellation, () => DefaultTimeout, Trace.JournalTrace);
            journalObservers = new JournalObservers(journalSource, ultimaServer);
            targeting        = new Targeting(ultimaServer, ultimaClient, cancellation, eventJournalSource);

            blockedPacketsFilters = new BlockedClientPacketsFilters(ultimaClient);
            lightObserver         = new LightObserver(ultimaServer, ultimaClient, Me, this);
            weatherObserver       = new WeatherObserver(ultimaServer, ultimaClient, this);
            soundObserver         = new SoundObserver(ultimaServer, eventJournalSource);
            questArrowObserver    = new QuestArrowObserver(ultimaServer, eventJournalSource);
            shapeShifter          = new ShapeshiftingFilter(ultimaServer, ultimaClient);
            var speechRequestObserver = new SpeechRequestObserver(ultimaClient, commandHandler, eventJournalSource, logger);
            var staminaFilter         = new StaminaFilter(ultimaServer, ultimaClient);

            dialogBoxObervers = new DialogBoxObservers(ultimaServer, eventJournalSource);

            playerObservers = new PlayerObservers(Me, ultimaClient, ultimaServer, logger, this, GameObjects, eventJournalSource);
            playerObservers.WalkRequestDequeued += Me.OnWalkRequestDequeued;

            this.logger = logger;
            Server      = ultimaServer;
            Client      = ultimaClient;

            CommandHandler = commandHandler;
            CommandHandler.CancellationTokenCreated += (sender, token) => CancellationToken = token;

            Configuration      = configuration;
            legacyEventJournal = CreateEventJournal();

            ClientFilters = new LegacyFilters(staminaFilter, lightObserver, weatherObserver, soundObserver, shapeShifter);
            RegisterDefaultCommands();
        }
        //KOLLAR OM MAN HAR KOLLIDERAT MED TEDDY; OCH PÅ VILKA BANOR DET I SÅ FALL HÄNDER. SÄTTER HUR MAN KOLLIDERAR.
        //HAR MAN KOLLIDERAT MED TEDDY SÅ RITAS FLICKAN UT: KOLLIDERAR MAN SEN MED EMPTY TILE SÅ FÖRSVINNER FLICKAN
        public bool IsCollidingAtTeddy(Vector2 a_newPos, Vector2 a_size, SoundObserver a_soundobserver)
        {
            Vector2 topLeft = new Vector2(a_newPos.X, a_newPos.Y - a_size.Y);
            Vector2 bottomRight = new Vector2(a_newPos.X, a_newPos.Y);

            for (int x = 0; x < g_levelWidth; x++)
            {
                for (int y = 0; y < g_levelHeight; y++)
                {

                    if (bottomRight.X < (float)x - 0.4)
                        continue;
                    if (bottomRight.Y < (float)y)
                        continue;
                    if (topLeft.X > (float)x + 1.0f)
                        continue;
                    if (topLeft.Y > (float)y + 0.7f)
                        continue;

                    if (m_tiles[x, y] == Tile.T_TEDDY)
                    {
                        m_tiles[25, g_levelHeight - 3] = Tile.T_EMPTY;
                        m_tiles[29, g_levelHeight - 3] = Tile.T_GIRL;

                        a_soundobserver.ScreamSound();
                        return true;
                    }
                    else if (m_tiles[x, y] == Tile.T_VANISH)
                    {
                       m_tiles[29, g_levelHeight - 3] = Tile.T_EMPTY;
                    }
                }
            }
            return false;
        }
        //KOLLAR OM MAN HAR KOLLIDERAT MED HJÄRTAT; OCH PÅ VILKA BANOR DET I SÅ FALL HÄNDER. SÄTTER HUR MAN KOLLIDERAR.
        //OM MAN KOLLIDERAR MED HJÄRTAT SÅ BYTER DEN TILL EN EMPTY TILE FÖR ATT DEN SKA FÖRSVINNA
        public bool IsCollidingAtHeart(Vector2 a_newPos, Vector2 a_size, SoundObserver a_soundobserver)
        {
            Vector2 topLeft = new Vector2(a_newPos.X, a_newPos.Y - a_size.Y);
            Vector2 bottomRight = new Vector2(a_newPos.X, a_newPos.Y);

            for (int x = 0; x < g_levelWidth; x++)
            {
                for (int y = 0; y < g_levelHeight; y++)
                {

                    if (bottomRight.X < (float)x - 0.4)
                        continue;
                    if (bottomRight.Y < (float)y)
                        continue;
                    if (topLeft.X > (float)x + 1.0f)
                        continue;
                    if (topLeft.Y > (float)y + 0.7f)
                        continue;

                    if (m_tiles[x, y] == Tile.T_HEART)
                    {
                        m_tiles[x, y] = Tile.T_EMPTY;
                        return true;
                    }

                }
            }
            return false;
        }
        //EN UPPDATE SOM HÅLLER REDA PÅ NÄR CHASE ENEMY SKA JAGA FIENDEN OCH VILKEN HASTIGHET: HHÄR SÄTTS ÄVEN FUNCTIONEN SÅ DEM HAN HOPPA ÖVER TILES.
        internal void UpdateEnemy(float a_elapsedTime, SoundObserver a_soundobserver)
        {
            for (int i = 0; i < m_enemy.Count; i++)
            {
            float distanceFromPlayer = Vector2.Distance(m_enemy[i].GetPosition(), m_player.GetPosition());
            //if (m_player.GetPosition > chaseThershold)
            { //}
                Vector2 a_playerPosition = m_player.GetPosition();
                Vector2 lastPosition = m_enemy[i].GetPosition();
                m_enemy[i].Update(a_elapsedTime);
                Vector2 enemyPosition = m_enemy[i].GetPosition();
                Vector2 speed = m_enemy[i].GetSpeed();
                Vector2 afterCollidedPos = EnemyCollide(lastPosition, enemyPosition, m_enemy[i].m_size, ref speed, out m_enemyCollidedWithGround, i, a_elapsedTime);

                    //m_enemy[i].m_CurrentState();
                    /*if (distanceFromPlayer < 10)
                    {
                        speed.X = -10;

                    }*/

                    if (enemyPosition.X - m_player.GetPosition().X < 0.2f && enemyPosition.X - m_player.GetPosition().X > -0.2f)
                    {
                        speed.X = 0;
                    }

                    else if (enemyPosition.X - m_player.GetPosition().X <= 7 && enemyPosition.X - m_player.GetPosition().X >= -7 && enemyPosition.Y - m_player.GetPosition().Y <= 4 && enemyPosition.Y - m_player.GetPosition().Y >= -4)
                    {

                            m_modelEnemy.SetState(2);
                            if (enemyPosition.X > m_player.GetPosition().X)
                            {
                                speed.X = -4;
                            }

                            else if (enemyPosition.X < m_player.GetPosition().X)
                            {

                                speed.X = 3.5f;
                            }

                        }

                    else
                    {
                            m_modelEnemy.SetState(1);
                            speed.X = 0;
                    }

                m_enemyCollidedWithGround = false;
                m_enemy[i].SetPosition(afterCollidedPos.X, afterCollidedPos.Y);
                m_enemy[i].SetSpeed(speed.X, speed.Y);
            }
            }
        }
        //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);
 }