示例#1
0
        static void Main(string[] args)
        {
            // init screen related constants
            Constants.windowSizeY = (int)VideoMode.DesktopMode.Height;
            Constants.windowSizeX = Constants.windowSizeY * 4 / 3;
            Constants.windowScaleFactor = Constants.windowSizeY / 600f;
            Constants.screenRatio = (float)Constants.windowSizeY / Constants.windowSizeX;
            Constants.worldToScreenRatio = Constants.windowSizeX / Constants.worldSizeX;
            Constants.worldSizeY = Constants.worldSizeX * Constants.screenRatio;

            // initialize window and view
            win = new RenderWindow(new VideoMode((uint)Constants.windowSizeX, (uint)Constants.windowSizeY), "Shøøp");
            view = new View();
            resetView();
            gui = new GUI(win, view);

            // exit Program, when window is being closed
            //win.Closed += new EventHandler(closeWindow);
            win.Closed += (sender, e) => { (sender as Window).Close(); };

            // initialize GameState
            handleNewGameState();

            // initialize GameTime
            gameTime = new GameTime();
            float deltaTime = 0f;
            gameTime.Start();
            while (running && win.IsOpen())
            {
            //		gameTime.Update();

                GamePadInputManager.update();
                KeyboardInputManager.update();

                if (currentGameState == GameState.InGame) { inGameFrameCount++; }
                currentGameState = state.update(deltaTime * Constants.gameSpeedFactor);

                if (currentGameState != prevGameState)
                {
                    handleNewGameState();
                }

                // draw current frame
                win.Clear(new Color(100, 149, 237));    //cornflowerblue ftw!!! 1337
                state.draw(win, view);
                state.drawGUI(gui);

                win.SetView(view);
                win.Display();

                // check for window-events. e.g. window closed
                win.DispatchEvents();

                System.Threading.Thread.Sleep(5);
                // update GameTime
                gameTime.Update();
                deltaTime = (float)gameTime.EllapsedTime.TotalSeconds;
            //	int waitTime = (int)(16.667f - gameTime.EllapsedTime.TotalMilliseconds);
            //	if (waitTime > 0) System.Threading.Thread.Sleep(waitTime);
            //	win.SetTitle(waitTime.ToString());
            //	win.SetTitle((count/60f).ToString("0.0") + " | " + gameTime.TotalTime.TotalSeconds.ToString("0.0"));
            }
        }
示例#2
0
 public void drawGUI(GUI gui)
 {
 }