Beispiel #1
0
        // Method to update the player and all the enemies
        public void Update()
        {
            //Console.WriteLine("Stage: " + _stage);
            //Console.WriteLine("Level: " + _level);
            _player.CurrentWeapon.Update();
            _player.Update();
            UpdateList();
            UpdateLevel();
            UpdatePackage();
            OpenDoor();

            for (int i = 0; i < _count; i++)
            {
                Vector place;
                if (this._enemies[i].Effect == "Sheep")
                {
                    place = this.CreateRandomPosition();
                }
                else if (this._enemies[i].Effect == "Hypnose")
                {
                    if (this._enemies[i].Target == null)
                    {
                        float target         = 80f;
                        int   ennemiesTarget = 0;
                        for (int a = 0; a < _count; a++)
                        {
                            Vector distanceVect = new Vector();
                            if (a != i)
                            {
                                float distanceMin = distanceVect.Distance(this._enemies[i].Place, this._enemies[a].Place);
                                if (target > distanceMin)
                                {
                                    target         = distanceMin;
                                    ennemiesTarget = a;
                                }
                            }
                        }

                        this._enemies[i].Target   = this._enemies[ennemiesTarget];
                        this._enemies[i].TargetID = ennemiesTarget;
                    }
                    place = this._enemies[i].Target.Place;
                }
                else
                {
                    place = this._player.Place;
                }

                this._enemies[i].Move(place);
            }
            UpdateEffect(_enemies);

            if (_boss != null && _boss.isDead == false)
            {
                this._boss.UpdateBoss();
                this._boss.Move(this.Player.Place);
            }
            _time++;
            _timeForWeaponSpawn++;
            if (_time == 120 && this._spawn != null)
            {
                _count += _spawn.Count;
                if (_count > this._enemies.Length)
                {
                    _count = this.Enemies.Length;
                }
            }

            if (_timeForWeaponSpawn == 300)
            {
                int           factoryIndex       = _random.Next(0, _stuffFactories.Count);
                IStuffFactory randomStuffFactory = _stuffFactories[factoryIndex];
                IStuff        stuff = randomStuffFactory.Create();
                _stuffList.Add(stuff);

                _timeForWeaponSpawn = 0;
            }
        }
        public void Handle()
        {
            if (Keyboard.IsKeyPressed(Keyboard.Key.Z))
            {
                if (_roundUIContext.RoundHandlerContext.RoundObject.Player.Effect == "Reverse")
                {
                    _roundUIContext.RoundHandlerContext.RoundObject.Player.Move(new Vector(0, -1));
                }
                else
                {
                    _roundUIContext.RoundHandlerContext.RoundObject.Player.Move(new Vector(0, 1));
                }
            }
            else if (Keyboard.IsKeyPressed(Keyboard.Key.S))
            {
                if (_roundUIContext.RoundHandlerContext.RoundObject.Player.Effect == "Reverse")
                {
                    _roundUIContext.RoundHandlerContext.RoundObject.Player.Move(new Vector(0, 1));
                }
                else
                {
                    _roundUIContext.RoundHandlerContext.RoundObject.Player.Move(new Vector(0, -1));
                }
            }
            else if (Keyboard.IsKeyPressed(Keyboard.Key.Q))
            {
                if (_roundUIContext.RoundHandlerContext.RoundObject.Player.Effect == "Reverse")
                {
                    _roundUIContext.RoundHandlerContext.RoundObject.Player.Move(new Vector(1, 0));
                }
                else
                {
                    _roundUIContext.RoundHandlerContext.RoundObject.Player.Move(new Vector(-1, 0));
                }
            }
            else if (Keyboard.IsKeyPressed(Keyboard.Key.D))
            {
                if (_roundUIContext.RoundHandlerContext.RoundObject.Player.Effect == "Reverse")
                {
                    _roundUIContext.RoundHandlerContext.RoundObject.Player.Move(new Vector(-1, 0));
                }
                else
                {
                    _roundUIContext.RoundHandlerContext.RoundObject.Player.Move(new Vector(1, 0));
                }
            }

            if (Keyboard.IsKeyPressed(Keyboard.Key.E) && _roundUIContext.RoundHandlerContext.RoundObject.Player.BlockWeapon == false)
            {
                if (_timerNextWeapon == 5)
                {
                    _roundUIContext.RoundHandlerContext.RoundObject.Player.ChangeWeapon(1);
                    _timerNextWeapon = 0;
                }
                _timerNextWeapon++;
            }
            if (Keyboard.IsKeyPressed(Keyboard.Key.R) && _roundUIContext.RoundHandlerContext.RoundObject.Player.BlockWeapon == false)
            {
                if (_timerPreviousWeapon == 4)
                {
                    _roundUIContext.RoundHandlerContext.RoundObject.Player.ChangeWeapon(-1);
                    _timerPreviousWeapon = 0;
                }
                _timerPreviousWeapon++;
            }

            if (Keyboard.IsKeyPressed(Keyboard.Key.Space))
            {
                if (i >= 30 && _roundUIContext.RoundHandlerContext.RoundObject.Player.CurrentWeapon.Name == "USP")
                {
                    ChangeSound();
                    _bulletSound.Play();
                    _roundUIContext.RoundHandlerContext.RoundObject.Player.Attack(CalculMouseVector());
                    i = 0;
                }
                else if (i >= 10 && _roundUIContext.RoundHandlerContext.RoundObject.Player.CurrentWeapon.Name == "ak47")
                {
                    ChangeSound();
                    _bulletSound.Play();
                    _roundUIContext.RoundHandlerContext.RoundObject.Player.Attack(CalculMouseVector());
                    i = 0;
                }

                else if (i >= 50 && _roundUIContext.RoundHandlerContext.RoundObject.Player.CurrentWeapon.Name == "shotgun" || i >= 10 && _roundUIContext.RoundHandlerContext.RoundObject.Player.CurrentWeapon.Name == "FreezeGun")
                {
                    ChangeSound();
                    _bulletSound.Play();
                    Vector shotgun_shoot = CalculMouseVector();
                    _roundUIContext.RoundHandlerContext.RoundObject.Player.Attack(shotgun_shoot);
                    int count = 0;
                    for (int i = 0; i < 4; i++)
                    {
                        Vector new_shotgun_shoot = new Vector(shotgun_shoot.X + x, shotgun_shoot.Y + y);
                        _roundUIContext.RoundHandlerContext.RoundObject.Player.Attack(new_shotgun_shoot);
                        if (count < 2)
                        {
                            x += 0.03f;
                            y += 0.03f;
                        }
                        else
                        {
                            x -= 0.03f;
                            y -= 0.03f;
                        }

                        count++;
                        if (count == 2)
                        {
                            x = -0.01f;
                            y = -0.01f;
                        }
                    }

                    i = 0;
                    x = 0.03f;
                    y = 0.03f;
                }
                else if (_roundUIContext.RoundHandlerContext.RoundObject.Player.CurrentWeapon.Name == "soulcalibur")
                {
                    TimeSpan TimeBegin = TimeSpan.FromSeconds(5);
                    DateTime DateBegin = DateTime.UtcNow;
                    TimeSpan span      = TimeSpan.FromSeconds(0);
                    _roundUIContext.EffectMusic.Pause();
                    _roundUIContext.GameCtx.MusicMain.Pause();
                    _zawarudo.Play();
                    while (span < TimeBegin && Keyboard.IsKeyPressed(Keyboard.Key.Space))
                    {
                        span = DateTime.UtcNow - DateBegin;
                        ChangeSound();
                        _bulletSound.Play();
                        _roundUIContext.RoundHandlerContext.RoundObject.Player.Attack(CalculMouseVector());
                    }
                    //_roundUIContext.RoundHandlerContext.RoundObject.Player.CurrentWeapon.LifeSpan = TimeSpan.FromSeconds(0);
                    //_roundUIContext.RoundHandlerContext.RoundObject.Player.CurrentWeapon.CreationDate = DateTime.UtcNow;
                    _roundUIContext.RoundHandlerContext.RoundObject.Player.CurrentWeapon.Life = false;
                    _roundUIContext.GameCtx.MusicMain.Play();
                    i = 0;
                }
                else if (i >= 20 && _roundUIContext.RoundHandlerContext.RoundObject.Player.CurrentWeapon.Name == "SheepGun")
                {
                    ChangeSound();
                    _bulletSound.Play();
                    _roundUIContext.RoundHandlerContext.RoundObject.Player.Attack(CalculMouseVector());
                    i = 0;
                }
                else if (i >= 20 && _roundUIContext.RoundHandlerContext.RoundObject.Player.CurrentWeapon.Name == "HypnoseGun")
                {
                    ChangeSound();
                    _bulletSound.Play();
                    _roundUIContext.RoundHandlerContext.RoundObject.Player.Attack(CalculMouseVector());
                    i = 0;
                }
                else if (i >= 40 && _roundUIContext.RoundHandlerContext.RoundObject.Player.CurrentWeapon.Name == "TpGun" && _roundUIContext.RoundHandlerContext.RoundObject.Stage != 3)
                {
                    ChangeSound();
                    if (putPortal == 0)
                    {
                        Vector tpplace = CalculMouseVector();
                        if (tpplace.X > 0.98 || tpplace.Y > 0.98 || tpplace.X < -0.98 || tpplace.Y < -0.98)
                        {
                        }
                        else
                        {
                            _bulletSound.Play();
                            _roundUIContext.RoundHandlerContext.RoundObject.Player.CurrentWeapon.TpPlace = tpplace;
                            putPortal++;
                        }
                    }
                    else if (putPortal == 1)
                    {
                        _bulletSound.Play();
                        _roundUIContext.RoundHandlerContext.RoundObject.Player.Place = _roundUIContext.RoundHandlerContext.RoundObject.Player.CurrentWeapon.TpPlace;
                        putPortal = 0;
                    }
                    i = 0;
                }
                else if (i >= 50 && _roundUIContext.RoundHandlerContext.RoundObject.Player.CurrentWeapon.Name == "BFG" && _roundUIContext.TargetBool == false)
                {
                    ChangeSound();
                    _bulletSound.Play();
                    _roundUIContext.RoundHandlerContext.RoundObject.Player.Attack(CalculMouseVector());
                    i = 0;
                }
                else if (_roundUIContext.RoundHandlerContext.RoundObject.Player.CurrentWeapon.Name == "Infinity_Gauntlet")
                {
                    ChangeSound();
                    _bulletSound.Play();
                    _roundUIContext.EffectMusic.Pause();
                    _roundUIContext.GameCtx.MusicMain.Pause();
                    while (_bulletSound.Status == SoundStatus.Playing)
                    {
                    }
                    //int thanosKill;
                    for (int i = 0; i < _roundUIContext.RoundHandlerContext.RoundObject.CountEnnemi; i++)
                    {
                        _roundUIContext.RoundHandlerContext.RoundObject.Enemies[i].Hit(_roundUIContext.RoundHandlerContext.RoundObject.Player.CurrentWeapon.Attack);
                    }

                    if (_roundUIContext.RoundHandlerContext.RoundObject._boss != null)
                    {
                        _roundUIContext.RoundHandlerContext.RoundObject._boss.Hit(_roundUIContext.RoundHandlerContext.RoundObject.Player.CurrentWeapon.Attack);
                    }
                    _roundUIContext.RoundHandlerContext.RoundObject.Player.CurrentWeapon.Life = false;
                    _roundUIContext.GameCtx.MusicMain.Play();
                }


                i++;
            }


            if (Keyboard.IsKeyPressed(Keyboard.Key.F1))
            {
                _roundUIContext.RoundHandlerContext.RoundObject.Player.Experience += 500;
            }

            if (Keyboard.IsKeyPressed(Keyboard.Key.F2))
            {
                _roundUIContext.RoundHandlerContext.RoundObject.Player.Points += 1000000;
            }

            if (Keyboard.IsKeyPressed(Keyboard.Key.F12))
            {
                _roundUIContext.RoundHandlerContext.RoundObject.Stage = 5;
                _roundUIContext.RoundHandlerContext.RoundObject.Level = 3;
            }

            if (Keyboard.IsKeyPressed(Keyboard.Key.F5))
            {
                for (int i = 0; i < _roundUIContext.RoundHandlerContext.RoundObject.CountEnnemi; i++)
                {
                    _roundUIContext.RoundHandlerContext.RoundObject.Enemies[i].Speed  = 0f;
                    _roundUIContext.RoundHandlerContext.RoundObject.Enemies[i].Effect = "Cheat";
                }
            }


            if (Keyboard.IsKeyPressed(Keyboard.Key.F6))
            {
                for (int i = 0; i < _roundUIContext.RoundHandlerContext.RoundObject.CountEnnemi; i++)
                {
                    _roundUIContext.RoundHandlerContext.RoundObject.Enemies[i].Speed  = _roundUIContext.RoundHandlerContext.RoundObject.EnemiesSpeed;
                    _roundUIContext.RoundHandlerContext.RoundObject.Enemies[i].Effect = "Nothing";
                }
            }

            if (cheat >= 20 && Keyboard.IsKeyPressed(Keyboard.Key.F3))
            {
                stuffFactories++;
                if (stuffFactories > _roundUIContext.RoundHandlerContext.RoundObject.StuffFactories.Count - 1)
                {
                    stuffFactories = 0;
                }
                cheat = 0;
            }

            if (cheat >= 10 && Keyboard.IsKeyPressed(Keyboard.Key.F4))
            {
                IStuffFactory randomStuffFactory = _roundUIContext.RoundHandlerContext.RoundObject.StuffFactories[stuffFactories];
                IStuff        stuff = randomStuffFactory.CreateToCheat(CalculMouseVector());
                _roundUIContext.RoundHandlerContext.RoundObject.StuffList.Add(stuff);
            }

            if (Keyboard.IsKeyPressed(Keyboard.Key.F7))
            {
                if (_IsZoom == false)
                {
                    _roundUIContext.GameCtx.MyView.Zoom(4f);
                    _IsZoom = true;
                }
            }

            if (Keyboard.IsKeyPressed(Keyboard.Key.F8))
            {
                if (_IsZoom == true)
                {
                    _roundUIContext.GameCtx.MyView.Center = new Vector2f(_roundUIContext.GameCtx.MyView.Center.X / 4, _roundUIContext.GameCtx.MyView.Center.Y / 4);
                    _roundUIContext.GameCtx.MyView.Size   = new Vector2f(_roundUIContext.GameCtx.MyView.Size.X / 4, _roundUIContext.GameCtx.MyView.Size.Y / 4);
                    _IsZoom = false;
                }
            }

            Console.WriteLine(_roundUIContext.GameCtx.MyView);

            cheat++;
        }