Exemplo n.º 1
0
        public override void Update(Camera camera, GameTime gameTime)
        {
            base.Update(camera, gameTime);

            FloatingTexts.Update(camera, gameTime);
            Windmill.Update(camera, gameTime);
            PlayerCave.Update(camera, gameTime);
            EnemyCave.Update(camera,gameTime);

            ParallelToDos.Do(gameTime);

            _paused ^= Camera.KeyboardState.IsKeyPressed(Keys.P);
            _pausedEnemy ^= Camera.KeyboardState.IsKeyPressed(Keys.E);
            if (_paused)
                return;

            if (Camera.KeyboardState.IsKeyPressed(Keys.Z))
                foreach (var enemy in Enemies)
                    enemy.SerpentStatus = SerpentStatus.Ghost;

            _onceASecond += gameTime.ElapsedGameTime.TotalSeconds;
            if (_onceASecond >= 1)
            {
                _onceASecond = 0;

                if (PlayerEgg == null && (Rnd.NextDouble() < 0.03 || Camera.KeyboardState.IsKeyPressed(Keys.D3)))
                    PlayerSerpent.IsPregnant = true;

                if (Rnd.NextDouble() < 0.02 && !Enemies.Any(_ => _.IsPregnant) && Enemies.Any())
                    Enemies[Rnd.Next(Enemies.Count)].IsPregnant = true;
            }

            PlayerSerpent.Update(Camera, gameTime);
            if (PlayerEgg == null)
                PlayerEgg = PlayerSerpent.TimeToLayEgg();

            if(!_pausedEnemy)
                foreach (var enemy in Enemies)
                {
                    int eatenSegments;

                    enemy.Update(Camera, gameTime);
                    if (enemy.EatAt(PlayerSerpent, out eatenSegments))
                        PlayerSerpent.SerpentStatus = SerpentStatus.Ghost;
                    if (enemy.SerpentStatus == SerpentStatus.Alive)
                    {
                        if (PlayerSerpent.EatAt(enemy, out eatenSegments))
                        {
                            enemy.SerpentStatus = SerpentStatus.Ghost;
                            eatenSegments += 10;
                        }
                        if (eatenSegments != 0)
                            AddAndShowScore(eatenSegments*50, PlayerSerpent.Position);
                    }

                    if (enemy.EatFrogOrEgg(PlayerEgg))
                        PlayerEgg = null;

                    var egg = enemy.TimeToLayEgg();
                    if (egg != null)
                        EnemyEggs.Add(egg);
                }
            Enemies.RemoveAll(e => e.SerpentStatus == SerpentStatus.Finished);

            for (var i = EnemyEggs.Count - 1; i >= 0; i--)
            {
                EnemyEggs[i].Update(gameTime);

                if (PlayerSerpent.EatFrogOrEgg(EnemyEggs[i]))
                {
                    AddAndShowScore(100, EnemyEggs[i].Position);
                    EnemyEggs.RemoveAt(i);
                    continue;
                }

                if (!EnemyEggs[i].TimeToHatch())
                    continue;
                var newSerpent = new EnemySerpent(LContent, PlayingField, 0, 0);
                newSerpent.Restart(PlayingField, EnemyEggs[i].Whereabouts);
                EnemyEggs.RemoveAt(i);
                Enemies.Add(newSerpent);
            }

            foreach (var frog in Frogs)
            {
                frog.Update(Camera, gameTime);

                if (PlayerEgg != null && frog.DistanceSquared(PlayerEgg) < 0.4f)
                    PlayerEgg = null;
                EnemyEggs.RemoveAll(_ => frog.DistanceSquared(_) < 0.4f);

                if (PlayerSerpent.EatFrogOrEgg(frog))
                {
                    AddAndShowScore(100, frog.Position);
                    frog.Restart();
                }
                else if (Enemies.Any(enemy => enemy.EatFrogOrEgg(frog)))
                    frog.Restart();
            }
        }
Exemplo n.º 2
0
        public void Restart(int scene)
        {
            if (PlayingField != null)
                PlayingField.Dispose();
            PlayingField = new PlayingField(
                LContent,
                LContent.Content.Load<Texture2D>(@"Textures\woodfloor"),
                scene);

            PlayerCave.SetPosition(PlayingField.PlayerWhereaboutsStart, PlayingField);
            EnemyCave.SetPosition(PlayingField.EnemyWhereaboutsStart, PlayingField);

            if (Scene != scene)
                LContent.Ground.GeneratePlayingField(PlayingField);
            Scene = scene;

            PlayerSerpent = new PlayerSerpent(
                LContent,
                PlayingField);

            Enemies.Clear();
            EnemyEggs.Clear();
            Frogs.Clear();
            PlayerEgg = null;

            var enemies = (7 + scene)/2;
            for (var i = 0; i < enemies; i++)
                Enemies.Add(new EnemySerpent(
                    LContent,
                    PlayingField,
                    i*1.5f,
                    2));

            for (var i = 0; i < 3; i++)
                Frogs.Add(new Frog(
                    LContent,
                    LContent.LoadEffect(@"Effects\SimpleTextureEffect"),
                    this));
        }