public GameHandler(RenderContext rc, RenderCanvas rCanvas)
 {
     RCanvas = rCanvas;
     this.Rc = rc;
     this.gui = new Gui(Rc, RCanvas, this);
     this.GameState = new GameState(ref gui, this);
       //  DbConnection =new DbConnection(this);
 }
        private void CloseCurrentApp()
        {
            richTextBox1.Text = "";

            // Clean up
            _currentApp = null;

            if (_currentControl != null)
            {
                _currentControl.HandleCreated -= renderControl_HandleCreated;
                splitContainer1.Panel2.Controls.Remove(_currentControl);
                _currentControl.Dispose();
                _currentControl = null;
            }
            if (_currentHost != null)
            {
                _currentHost.Dispose();
                _currentHost = null;
            }

            // Just in case...
            GC.Collect();
            GC.WaitForFullGCComplete();
        }
        /// <summary>
        /// Traverses the scene's entities with their corresponding components in order to construct an 3D world. This function is called every frame.
        /// </summary>
        /// <param name="renderCanvas">The render canvas that presents the final render image.</param>
        public void Traverse(RenderCanvas renderCanvas)
        {
            RC.Clear(ClearFlags.Color | ClearFlags.Depth);
            int length = SceneMembers.Count;
            for (int i=0;i<length; i++)
            {
                SceneMembers[i].Accept(_sceneVisitorRendering);
                //sceneMember.Accept();
            }

            // Order: Matrix, Mesh, Renderer
            length = RenderJobs.Length;
            for (int i = 1; i < length; i++ )
            {

                int innerlength = RenderJobs[i].Count;
                for (int k = 0; k < innerlength;k++)
                {

                    RenderJobs[i][k].SubmitWork(RC);

                }

            }
            renderCanvas.Present();
            length = RenderJobs.Length;
            //Debug.WriteLine("Drawn "+RenderJobs[2].Count/3+" Objects at "+Time.Instance.FramePerSecondSmooth+" FPS!");
            for (int j = 0; j < length;j++ )
            {
                RenderJobs[j].Clear();
            }
        }
Exemplo n.º 4
0
        //da initialisieren wir alles für den GuiHandler
        public Gui(RenderContext RC, RenderCanvas rCanvas, GameHandler gameHandler)
        {
            #region Variablen
            _rCanvas = rCanvas;
            var height = _rCanvas.Height;
            var width = _rCanvas.Width;

            _gameHandler = gameHandler;
            _guiHandler = new GUIHandler(RC);
            _mainmenuHandler = new GUIHandler(RC);
            _inGameHandler = new GUIHandler(RC);
            _highScoreHandler = new GUIHandler(RC);

            _guiDiffs = new GUIButton[4];
            _guiImageTomato = new GUIImage[10];
            _guiImages = new GUIImage[9];
            _highscoreBretter = new GUIImage[5];

            float textwidth;
            float texthight;
            _highscore = false;
            _neustart = true;
            _pause = true;
            _level = 1;

              #endregion

            #region Bilder
            //Hintergrund Startscreen
            _guiImages[(int)_btnimages.Startbild] = new GUIImage("Assets/startbild.png", 0, 0,-3, width, height);

            //Hintergrund Endscreen
            _guiImages[(int)_btnimages.Endbild] = new GUIImage("Assets/endbild.png", 0, 0, -3, width, height);

            //Maus-Nutzerinfo in Mainmenü einblenden
            _guiImages[(int)_btnimages.btniMouse] = new GUIImage("Assets/Mouse.png", width / 4, 0, -1, (int)(height / 1.322), height);

            //Fadenkreuz flexibel (Falls es zwecks Schwierigkeitsstufe kleiner werden soll)
            _aimimage = 80;
            _guiImages[(int)_btnimages.btniFadenkreuz] = new GUIImage("Assets/Fadenkreuz.png", width / 2 - _aimimage / 2, height / 2 - _aimimage / 2, -2, _aimimage, _aimimage);

            // Credits Klohaus
            _guiImages[(int)_btnimages.btniCreditsA] = new GUIImage("Assets/kloClosed.png", width - height, 0, -1, height, height);
            _guiImages[(int)_btnimages.btniCreditsB] = new GUIImage("Assets/kloOpen.png", width - height, 0, -1, height, height);

            #endregion

            #region Beschriftungen
            //Schriften
            _guiFontCabin12 = RC.LoadFont("Assets/Cabin.ttf", 12);
            _guiFontCabin14 = RC.LoadFont("Assets/Cabin.ttf", 14);
            _guiFontCabin18 = RC.LoadFont("Assets/Cabin.ttf", 18);
            _guiFontCabin100 = RC.LoadFont("Assets/Cabin.ttf", 100);
            _guiFontWESTERN30 = RC.LoadFont("Assets/WESTERN.ttf", 30);

            //Credits
            texthight = GUIText.GetTextHeight("So hoch.", _guiFontCabin18);
            textwidth = GUIText.GetTextWidth("Sooooooooo laaaaaang", _guiFontCabin14);
            _guiTextCredits1 = new GUIText("Ramazan Gündogdu", _guiFontCabin14, (width) - (int)(textwidth), (height / 3)+ (int)(texthight/2), new float4(1, 1, 1, 1));
            _guiTextCredits2 = new GUIText("Kathleen Hübel", _guiFontCabin14, (width) - (int)(textwidth), (int)(_guiTextCredits1.PosY + texthight), new float4(1, 1, 1, 1));
            _guiTextCredits3 = new GUIText("Linda Schey", _guiFontCabin14, (width) - (int)(textwidth), (int)(_guiTextCredits2.PosY + texthight), new float4(1, 1, 1, 1));
            _guiTextCredits4 = new GUIText("Susanne Schmidt", _guiFontCabin14, (width) - (int)(textwidth), (int)(_guiTextCredits3.PosY + texthight), new float4(1, 1, 1, 1));
            _guiTextCredits5 = new GUIText("Tobias Winterhalder ", _guiFontCabin14, (width) - (int)(textwidth), (int)(_guiTextCredits4.PosY + texthight), new float4(1, 1, 1, 1));

            //Eingabetext Name für Highscore
            texthight = GUIText.GetTextHeight("Lorem ipsum", _guiFontCabin18);
            textwidth = GUIText.GetTextWidth("Write name: ", _guiFontCabin18);
            _name = new GUIText("Write name: ", _guiFontCabin18, (width / 2) - (int)(textwidth), (height / 2), new float4(0, 0, 0, 1));
            nameInput = new GUIText("", _guiFontCabin18, (width / 2), (height / 2), new float4(1, 1, 1, 1));

            //Text Mainmenü: Scha(r)fschießen
            textwidth = GUIText.GetTextWidth("Scha(r)fschießen", _guiFontWESTERN30);
            _guiTextTitel = new GUIText("Scha(r)fschießen", _guiFontWESTERN30, (width/2) - (int) (textwidth/2), (height/3));
            _guiTextTitel.TextColor = new float4(0, 0, 0, 1);

            // Text InGame
            textwidth = GUIText.GetTextWidth("Time: ", _guiFontCabin18);
            texthight = GUIText.GetTextHeight("Time: ", _guiFontCabin18);
            _guiText1 = new GUIText("Time: " + _countdown, _guiFontCabin18, (int)textwidth, (int)(texthight*2));
            _guiText1.TextColor = new float4(0, 0, 0, 1);
            textwidth = GUIText.GetTextWidth("Time: ", _guiFontCabin18);
            _guiText2 = new GUIText("Points: " + _points, _guiFontCabin18, width - (int)(textwidth * 3), (int)(texthight*2));
            _guiText2.TextColor = new float4(0, 0, 0, 1);

            //Text LevelUp
            textwidth = GUIText.GetTextWidth("Level Up!", _guiFontCabin100);
            _guiText7 = new GUIText("Level Up!", _guiFontCabin100, (width / 2) - (int)(textwidth/2), (height / 2));
            _guiText7.TextColor = new float4(1, 0, 0, 0.5f);

            #endregion

            #region Buttons
            // Button MainMenü: Starten
            textwidth = GUIText.GetTextWidth("Start", _guiFontWESTERN30);
            texthight = GUIText.GetTextHeight("Start", _guiFontWESTERN30);
            _guiText3 = new GUIText("Start", _guiFontWESTERN30, width / 2 - (int)(textwidth / 2), (int)(height / 1.5));
            _guiText3.TextColor = new float4(1, 1, 1, 1);
            _guiDiffs[(int)_buttons.btnStart] = new GUIButton(_guiText3.PosX - (int)(texthight / 2), _guiText3.PosY - (int)texthight, -2,
                (int)(textwidth * 1.5), (int)(texthight * 1.5));
            _guiImages[(int)_btnimages.btniStart] = new GUIImage("Assets/holz.png", _guiText3.PosX - (int)textwidth / 2,
                _guiText3.PosY - (int)(texthight * 1.5), -1, (int)textwidth * 2, (int)texthight * 2);

            // Button HighscoreMenü: Nochmal spielen
            textwidth = GUIText.GetTextWidth("Play again", _guiFontCabin18);
            _guiText5 = new GUIText("Play again", _guiFontCabin18, (width / 2) - (int)(textwidth * 1.5),
                (height / 2 + height / 3));
            _guiText5.TextColor = new float4(1, 1, 1, 1);
            texthight = GUIText.GetTextHeight("Play again", _guiFontCabin18);
            _guiDiffs[(int) _buttons.btnNochmal] = new GUIButton(_guiText5.PosX, _guiText5.PosY - (int) texthight, -2,
                (int) textwidth, (int) texthight);
            _guiImages[(int) _btnimages.btniNochmal] = new GUIImage("Assets/holz.png",
                _guiText5.PosX - (int) textwidth/2, _guiText5.PosY - (int) (texthight*1.5), -1, (int) textwidth*2,
                (int) texthight*2);

            // Button HighscoreMenü: Highscore
            textwidth = GUIText.GetTextWidth("Enter in Highscore", _guiFontCabin18);
            _guiText6 = new GUIText("Enter in Highscore", _guiFontCabin18, (width / 2) + (int)(textwidth / 5), (height / 2 + height / 3));
            _guiText6.TextColor = new float4(1, 1, 1, 1);
            texthight = GUIText.GetTextHeight("Enter in Highscore", _guiFontCabin18);
            _guiDiffs[(int) _buttons.btnHighscore] = new GUIButton(_guiText6.PosX, _guiText6.PosY - (int) texthight, -2, (int) textwidth, (int) texthight);
            _guiImages[(int) _btnimages.btniHighscore] = new GUIImage("Assets/holz.png",_guiText6.PosX - (int)textwidth / 8, _guiText6.PosY - (int)(texthight * 1.5), -1, (int)(textwidth * 1.2), (int) texthight*2);

            //Button Credits
            textwidth = GUIText.GetTextWidth("Credits", _guiFontCabin18);
            texthight = GUIText.GetTextWidth("Credits", _guiFontCabin18);
            _guiCredits = new GUIText("Credits", _guiFontCabin18, width - (int)(textwidth*1.5), (height / 2), new float4(1, 1, 1, 1));
            _guiDiffs[(int)_buttons.btnCredits] = new GUIButton(_guiCredits.PosX, _guiCredits.PosY - (int)texthight, -2,
               (int)textwidth, (int)texthight);
            #endregion
        }
        private void renderControl_HandleCreated(object sender, EventArgs e)
        {
            //
            //  STEP TWO - Now the underlying Windows Window was created - we can hook OpenGL on it.
            //

            // Take this as an example how to hook up any FUSEE application on a given Winforms form:

            // First create a WinformsHost around the control
            _currentHost = new WinformsHost(_currentControl, this);

            // Then instantiate your app (could be as well _currentApp = new MyOwnRenderCanvasDerivedClass(); )
            _currentApp = _appFinder.Instantiate(_currentInx);

            // Now use the host as the canvas AND the input implementation of your App
            _currentApp.CanvasImplementor = _currentHost;
            _currentApp.InputImplementor = _currentHost;

            // Then you can run the app
            _currentApp.Run();

            // If not already done, show the window.
            _currentControl.Show();
        }