public override bool OnUserCreate()
 {
     // Dette skjer EN gang
     senter = new vi2d(ScreenWidth() / 2, ScreenHeight() / 2);
     delta  = (MathF.PI * 2) / total;
     return(true);
 }
예제 #2
0
 public void DCircle(vi2d pos, float radius)
 {
     for (int i = 0; i < total; i++)
     {
         var res = i * factor;
         DrawLine(getpos(i) + pos, getpos(res) + pos, new Pixel((byte)i, (byte)(255 - i), (byte)i));
     }
 }
예제 #3
0
 private void InitializeGame()
 {
     SnakeHead = new vi2d(ScreenWidth() / 2, ScreenHeight() / 2);
     SnakeTail = new List <vi2d>();
     for (int i = 0; i < 5; i++)
     {
         SnakeTail.Add(SnakeHead);
     }
     SnakeVel = new vi2d(1, 0);
     Food     = new vi2d(ScreenWidth() / 2 + 10, ScreenHeight() / 2);
     time     = 0;
 }
예제 #4
0
 public override rcode CreateGraphics(bool bFullScreen, bool bEnableVSYNC, vi2d vViewPos, vi2d vViewSize)
 {
     renderer.SetWindowObject(olc_hWnd);
     if (renderer.CreateDevice(null, bFullScreen, bEnableVSYNC) == rcode.OK)
     {
         renderer.UpdateViewport(vViewPos, vViewSize);
         return(rcode.OK);
     }
     else
     {
         return(rcode.FAIL);
     };
 }
예제 #5
0
        //WndProc del;

        public override rcode CreateWindowPane(vi2d vWindowPos, vi2d vWindowSize, bool bFullScreen)
        {
            //Console.WriteLine("CreateWindowPane-start");
            //WNDCLASS wc = new WNDCLASS();
            //wc.hIcon = LoadIcon(IntPtr.Zero, IDI_APPLICATION); // IDI_APPLICATION (Default icon)
            //wc.hCursor = LoadCursor(IntPtr.Zero, IDC_ARROW); // IDC_ARROW (Standard arrow)
            //wc.style = ClassStyles.HorizontalRedraw | ClassStyles.VerticalRedraw | ClassStyles.OwnDC;
            //wc.hInstance = GetModuleHandle(null);
            //wc.lpfnWndProc = del;
            //wc.cbClsExtra = 0;
            //wc.cbWndExtra = 0;
            //wc.lpszMenuName = null;
            //wc.hbrBackground = IntPtr.Zero;
            //wc.lpszClassName = "OLC_PIXEL_GAME_ENGINE";
            //RegisterClass(ref wc);

            // Define window furniture
            //var dwExStyle =  WindowStylesEx.WS_EX_APPWINDOW | WindowStylesEx.WS_EX_WINDOWEDGE;
            //var dwStyle = WindowStyles.WS_CAPTION | WindowStyles.WS_SYSMENU | WindowStyles.WS_VISIBLE | WindowStyles.WS_THICKFRAME;

            vi2d vTopLeft = vWindowPos;

            // Handle Fullscreen
            //if (bFullScreen)
            //{
            //    dwExStyle = WindowStylesEx.WS_EX_LEFT;
            //    dwStyle = WindowStyles.WS_VISIBLE | WindowStyles.WS_POPUP;
            //    IntPtr hmon = MonitorFromWindow(olc_hWnd, MONITOR_DEFAULTTONEAREST);
            //    MonitorInfoEx mi = new MonitorInfoEx(); /*= { sizeof(mi) };*/
            //    if (!GetMonitorInfo(hmon, ref mi)) return rcode.FAIL;
            //    vWindowSize = new vi2d( mi.Monitor.Right, mi.Monitor.Bottom);
            //    vTopLeft.x = 0;
            //    vTopLeft.y = 0;
            //}

            // Keep client size as requested
            //RECT rWndRect = new RECT ( 0, 0, vWindowSize.x, vWindowSize.y );
            //AdjustWindowRectEx(ref rWndRect, (uint)dwStyle, false, (uint)dwExStyle);
            int width  = vWindowSize.x; //rWndRect.Right - rWndRect.Left;
            int height = vWindowSize.y; //rWndRect.Bottom - rWndRect.Top;


            //olc_hWnd = CreateWindowEx(dwExStyle, "OLC_PIXEL_GAME_ENGINE", "", dwStyle,  // fix dwExStyle
            //    vTopLeft.x, vTopLeft.y, width, height, IntPtr.Zero, IntPtr.Zero, GetModuleHandle(null), IntPtr.Zero); //  lpParam should have been set to "this" ?
            GLFW.Init();
            GLFW.WindowHint(WindowHintInt.ContextVersionMajor, 3);
            GLFW.WindowHint(WindowHintInt.ContextVersionMinor, 3);
            GLFW.WindowHint(WindowHintOpenGlProfile.OpenGlProfile, OpenGlProfile.Core);
            GLFW.WindowHint(WindowHintBool.DoubleBuffer, true);
            olc_hWnd = GLFW.CreateWindow(width, height, "OLC_PIXEL_GAME_ENGINE", null, null);

            GLFW.SetFramebufferSizeCallback(olc_hWnd, framebufferCallback);
            GLFW.SetErrorCallback(errorCallback);
            GLFW.SetMouseButtonCallback(olc_hWnd, mousebuttonCallback);
            GLFW.SetScrollCallback(olc_hWnd, scrollCallback);
            GLFW.SetCursorPosCallback(olc_hWnd, cursorposCallback);
            keyCallback = key_Callback;
            GLFW.SetKeyCallback(olc_hWnd, keyCallback);
            //GLFW.MakeContextCurrent((Window*)olc_hWnd);

            //GLFW.MakeContextCurrent(olc_hWnd);

            //if (olc_hWnd == null)
            //{
            //    Console.WriteLine($"LastError : [{Marshal.GetLastWin32Error()}]");
            //}
            Console.WriteLine("Window Created");
            Console.WriteLine("CreateWindowPane-end");
            return(rcode.OK);
        }
예제 #6
0
 public abstract rcode CreateWindowPane(vi2d vWindowPos, vi2d vWindowSize, bool bFullScreen);
예제 #7
0
 public abstract rcode CreateGraphics(bool bFullScreen, bool bEnableVSYNC, vi2d vViewPos, vi2d vViewSize);
 public override void UpdateViewport(vi2d pos, vi2d size)
 {
     GL.Viewport(pos.x, pos.y, size.x, size.y);
 }
예제 #9
0
 public abstract void UpdateViewport(vi2d pos, vi2d size);
예제 #10
0
        public override bool OnUserUpdate(float fElapsedTime)
        {
            Clear(new Pixel(50, 50, 50));
            if (gameOver)
            {
                DrawString(10, 5, "Press", Pixel.WHITE);
                DrawString(10, 15, "SPACE", Pixel.WHITE);
                DrawString(10, 25, "to Play", Pixel.WHITE);
                InitializeGame();
                if (GetKey(Key.SPACE).bPressed)
                {
                    gameOver = false;
                }
            }
            else
            {
                DisplayUI();
                time += fElapsedTime;

                if (GetKey(Key.RIGHT).bPressed&& LastVel.x == 0)
                {
                    SnakeVel = new vi2d(1, 0);
                }
                else if (GetKey(Key.LEFT).bPressed&& LastVel.x == 0)
                {
                    SnakeVel = new vi2d(-1, 0);
                }
                else if (GetKey(Key.UP).bPressed&& LastVel.y == 0)
                {
                    SnakeVel = new vi2d(0, -1);
                }
                else if (GetKey(Key.DOWN).bPressed&& LastVel.y == 0)
                {
                    SnakeVel = new vi2d(0, 1);
                }


                Draw(Food, Pixel.RED);

                if (time > 0.05)
                {
                    time = 0;
                    SnakeTail.Insert(0, SnakeHead);
                    SnakeHead += (SnakeVel);
                    LastVel    = SnakeVel;
                    if (SnakeHead.x > ScreenWidth() - 1)
                    {
                        SnakeHead.x = 0;
                    }
                    else if (SnakeHead.x < 0)
                    {
                        SnakeHead.x = ScreenWidth() - 1;
                    }
                    else if (SnakeHead.y > ScreenHeight() - 1)
                    {
                        SnakeHead.y = uiHeight + 1;
                    }
                    else if (SnakeHead.y < uiHeight + 1)
                    {
                        SnakeHead.y = ScreenHeight() - 1;
                    }

                    SnakeTail.RemoveAt(SnakeTail.Count - 1);
                    foreach (var tail in SnakeTail)
                    {
                        if (SnakeHead.x == tail.x && SnakeHead.y == tail.y)
                        {
                            gameOver = true;
                            //InitializeGame();
                        }
                    }

                    if (SnakeHead.x == Food.x && SnakeHead.y == Food.y)
                    {
                        for (int i = 0; i < 5; i++)
                        {
                            SnakeTail.Add(SnakeHead);
                        }
                        Food = RandomPosition();
                    }

                    if (SnakeTail.Count - 5 > highScore)
                    {
                        highScore = SnakeTail.Count - 5;
                    }
                }
                Draw(SnakeHead, Pixel.GREEN);
                foreach (var tail in SnakeTail)
                {
                    Draw(tail, Pixel.WHITE);
                }
            }
            return(true);
        }
예제 #11
0
 public Node(PixelGameEngine pge, int x, int y)
 {
     Position = new vi2d(x, y);
     this.pge = pge;
 }