Exemple #1
0
        public void Launch(BLaunchWindow launcher, BState startState)
        {
            Launcher     = launcher;
            CurrentState = startState;

            // Setup window
            GameWindow       = new GameWindow(AppSettings.SETTING_WIDTH, AppSettings.SETTING_HEIGHT);
            GameWindow.Title = AppInfo.APP_TITLE;

            if (AppSettings.SETTING_FULLSCREEN)
            {
                GameWindow.WindowState = WindowState.Fullscreen;

                if (AppSettings.SETTING_VSYNC)
                {
                    GameWindow.VSync = VSyncMode.Adaptive;
                }
                else
                {
                    GameWindow.VSync = VSyncMode.Off;
                }
            }
            else
            {
                GameWindow.WindowState = WindowState.Normal;
            }

            // Graphics Stuff
            GL.Enable(EnableCap.Texture2D);
            GL.Enable(EnableCap.Blend);
            GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha);

            // Frames
            GameWindow.Load        += (object obj, EventArgs e) => { OnLoad(); };
            GameWindow.UpdateFrame += (object obj, FrameEventArgs args) => { Tick(args.Time); };
            GameWindow.RenderFrame += (object obj, FrameEventArgs args) => { Render(); };

            // Input
            BKeyboardListener.Initialize();
            BMouseListener.Initialize();
            GameWindow.KeyDown    += (object sender, KeyboardKeyEventArgs e) => BKeyboardListener.UpdateKey((BKey)e.Key, true);
            GameWindow.KeyUp      += (object sender, KeyboardKeyEventArgs e) => BKeyboardListener.UpdateKey((BKey)e.Key, false);
            GameWindow.MouseDown  += (object sender, MouseButtonEventArgs e) => BMouseListener.UpdateButton((BMouseButton)e.Button, new System.Numerics.Vector2(e.X, e.Y), true);
            GameWindow.MouseUp    += (object sender, MouseButtonEventArgs e) => BMouseListener.UpdateButton((BMouseButton)e.Button, new System.Numerics.Vector2(e.X, e.Y), false);
            GameWindow.MouseMove  += (object sender, MouseMoveEventArgs e) => BMouseListener.UpdateLocation(e.Position);
            GameWindow.MouseWheel += (object sender, MouseWheelEventArgs e) => { BMouseListener.UpdateScrollWheel(e.Delta); };

            // Run the window
            GameWindow.Run(AppSettings.SETTING_UPS, AppSettings.SETTING_FPS);
        }
Exemple #2
0
        public void MenuPress()
        {
            var LeftClick = BMouseListener.GetButtonStateNow(BMouseButton.Left);

            if (LeftClick.IsPressed)
            {
                for (int i = 0; i < buttons.Length; i++)
                {
                    if (LeftClick.Location.X <= buttons[i].X && LeftClick.Location.X >= buttons[i].X1)
                    {
                        if (LeftClick.Location.Y <= buttons[i].Y && LeftClick.Location.Y >= buttons[i].Y1)
                        {
                            buttons[i].Pressed(Window);
                        }
                    }
                }
            }
        }
Exemple #3
0
        public override void Tick(double delta)
        {
            base.Tick(delta);

            // Handle our player and camera movement
            var LeftClick = BMouseListener.GetButtonStateNow(BMouseButton.Left);

            if (LeftClick.IsPressed)
            {
                Vector2 pos = new Vector2(LeftClick.Location.X, LeftClick.Location.Y);
                pos -= new Vector2(AppSettings.SETTING_WIDTH, AppSettings.SETTING_HEIGHT) / 2f;
                pos  = Camera.ToWorld(pos);

                Camera.SetPosition(pos, BTweenType.QuadraticInOut, 30);

                //Player.MoveToPosition(pos);
                NavMesh.FindPathTo(Player.position, pos);
                Player.FollowPath(NavMesh);
            }

            var RightClick = BMouseListener.GetButtonStateNow(BMouseButton.Right);

            if (RightClick.IsPressed)
            {
                Vector2 pos = new Vector2(RightClick.Location.X, RightClick.Location.Y);
                pos -= new Vector2(AppSettings.SETTING_WIDTH, AppSettings.SETTING_HEIGHT) / 2f;
                pos  = Camera.ToWorld(pos);

                while (Level.GetEntity(pos, 32f) != null)
                {
                    Level.DisposeEntity(Level.GetEntity(pos));
                }

                float treeSize  = (float)new Random().Next(86, 128);
                Tree  newEntity = new Tree(pos, Textures[1], new Vector2(treeSize, treeSize), new RectangleF(0, 0, 256f, 256f));
                Level.CreateEntity(newEntity);
                NavMesh.Update(Level);
            }

            int ScrollWheel = BMouseListener.GetScrollWheelNow();

            if (ScrollWheel != 0)
            {
                if (ScrollWheel < 0)
                {
                    Camera.Zoom = Camera.Zoom - 0.075f;
                }
                else if (ScrollWheel > 0)
                {
                    Camera.Zoom = Camera.Zoom + 0.075f;
                }

                if (Camera.Zoom > 1.25f)
                {
                    Camera.Zoom = 1.25f;
                }
                else if (Camera.Zoom < 0.75f)
                {
                    Camera.Zoom = 0.75f;
                }
            }

            if (BKeyboardListener.IsKeyJustPressed(BKey.F8))
            {
                AppSettings.SETTING_COLLISION_DEBUG = !AppSettings.SETTING_COLLISION_DEBUG;
            }
            if (BKeyboardListener.IsKeyJustPressed(BKey.F7))
            {
                NavMesh.Update(Level);
                AppSettings.SETTING_NAVIGATION_DEBUG = !AppSettings.SETTING_NAVIGATION_DEBUG;
            }
            if (BKeyboardListener.IsKeyJustPressed(BKey.F6))
            {
                AppSettings.SETTING_PATHFINDING_DEBUG = !AppSettings.SETTING_PATHFINDING_DEBUG;
            }
        }