예제 #1
0
        /// <summary>
        /// Funkce nainicializuje jednotlive podsystemy a spusti herni smycku
        /// </summary>
        public void InitCore()
        {
            VideoManager video = new VideoManager(this, false);

            video.LoadVideo(@"Resources/Videos/logo2.avi", true);

            Logger.InitLogger();
            Logger.bWriteToOutput = true;
            Logger.AddInfo("Inicializace");

            graphic           = new WRG.GraphicCore(this, true);
            multimediaManager = new SoundManager(this);

            if (Properties.Settings.Default.EnableMusic)
            {
                multimediaManager.AddToPlayList(@"Resources/Music/");
            }


            multimediaManager.PlayMusic();
            video.PlayVideo();

            input = Input.GetInputInstance(this);
            input.SetCooperative(Microsoft.DirectX.DirectInput.CooperativeLevelFlags.Background | Microsoft.DirectX.DirectInput.CooperativeLevelFlags.NonExclusive);
            menu = new MenuManager(WRG.GraphicCore.GetInitializator().GetDevice());

            #region Init Tests
            if (graphic == null)
            {
                Logger.AddError(global::WiccanRede.Properties.Resources.Graphic_Core_Init_Error);
                return;
            }

            if (input == null)
            {
                Logger.AddError(global::WiccanRede.Properties.Resources.Input_Core_Init_Error);
                return;
            }
            #endregion

            this.Show();

            resourceLoadThread = new Thread(graphic.ResourcesLoad);
            resourceLoadThread.Start();

            List <Input.Action> actions = null;
            startTime = Environment.TickCount;
            input.Start();
            int lastTime = 0;

            while (resourceLoadThread.ThreadState != ThreadState.Stopped)
            {
                graphic.ResourceProgressRender();
                Application.DoEvents();
                Thread.Sleep(200);
            }

            video.StopVideo();
            video.Dispose();


            this.windowRect = new System.Drawing.Rectangle(this.Location, this.Size);
            Cursor.Position = PointToScreen(new System.Drawing.Point(0, 0));
            Cursor.Clip     = windowRect;
            Cursor.Hide();

            SetCore();

            WRG.Initializator init = WRG.GraphicCore.GetInitializator();

            while (!exit && this.Created)
            {
                milisecondsElapsed = (Environment.TickCount - startTime);
                int frametime = milisecondsElapsed - lastTime;

                WRG.CameraDriver.SetTime(frametime);
                actions = input.Update(true);

                if (game != null)
                {
                    List <WiccanRede.AI.NpcInfo> npcs = game.GetAllNpcInfo();

                    //je hrac mrtvy?
                    if (npcs[npcs.Count - 1].Status.hp <= 0 && this.menu.MenuState != MenuResult.Restart)
                    {
                        this.menu.UpdateState("Gameover");
                        this.drawMenu = true;
                    }
                    else if (this.menu.MenuState == MenuResult.Restart)
                    {
                        this.menu.UpdateState("MainMenu");
                        this.menu.MenuState = MenuResult.New;
                        Restart();
                    }

                    //je konec hry?
                    if (game.GetCurrentGameState().Name == "Final")
                    {
                        this.menu.UpdateState("ToBeContinued");
                        this.drawMenu = true;
                    }
                }

                if (this.Focused)
                {
                    Cursor.Clip = this.windowRect;

                    if (init.IsFullscreen())
                    {
                        Cursor.Clip = System.Drawing.Rectangle.Empty;
                    }
                }
                else
                {
                    Cursor.Clip = System.Drawing.Rectangle.Empty;
                }



                if (this.drawMenu)
                {
                    Cursor.Show();
                    init.GetDevice().BeginScene();
                    MenuResult result = this.menu.Update(this.PointToClient(MousePosition), (actions.Contains(Input.Action.Action1)));
                    init.GetDevice().EndScene();
                    init.GetDevice().Present();

                    if (result == MenuResult.Pub)
                    {
                        this.drawMenu = false;
                        this.menu.UpdateState("MainMenu");
                        this.menu.CurrentMenuResult = MenuResult.None;
                    }
                    else if (result == MenuResult.New)
                    {
                        this.drawMenu = false;
                        this.menu.UpdateState("MainMenu");
                        this.menu.CurrentMenuResult = MenuResult.New;
                    }
                    else if (result == MenuResult.Exit || actions.Contains(Input.Action.Exit))
                    {
                        this.exit = true;
                    }
                    System.Threading.Thread.Sleep(20);
                    Cursor.Hide();
                }
                else
                {
                    action1Stoper -= frametime;
                    action2Stoper -= frametime;

                    ProcessActions(actions);
                    graphic.Render(milisecondsElapsed);

                    if (game == null)
                    {
                        game = WiccanRede.Game.GameManager.GetInstance();
                        graphic.FirstTimeRender();
                    }

                    try
                    {
                        game.Update((float)(frametime) / 1000f);
                    }
                    catch (Exception ex)
                    {
                        Logger.AddError(ex.Message);
                    }
                }

                Application.DoEvents();

                lastTime = milisecondsElapsed;
            }
            Logging.Logger.Save();
            graphic.Dispose();
            multimediaManager.Dispose();
        }