Exemple #1
0
        static void Main(string[] args)
        {
            // initialize window and view
            win = new RenderWindow(new VideoMode(1000, 700), "Hadoken!!!");
            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 gameTime = new GameTime();
            gameTime.Start();

            // debug Text
            Text debugText = new Text("debug Text", new Font("Fonts/calibri.ttf"));

            while (running && win.IsOpen())
            {
                KeyboardInputManager.update();

                currentGameState = state.update();

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

                // first the state must be drawn, before I can change the currentState
                if (currentGameState != prevGameState)
                {
                    handleNewGameState();
                }

                // do the actual drawing
                win.SetView(view);
                win.Display();

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

                // update GameTime
                gameTime.Update();
                float deltaTime = (float)gameTime.EllapsedTime.TotalSeconds;

                // idleLoop for fixed FrameRate
                float deltaPlusIdleTime = deltaTime;
                while (deltaPlusIdleTime < (1F / fixedFps))
                {
                    gameTime.Update();
                    deltaPlusIdleTime += (float)gameTime.EllapsedTime.TotalSeconds;
                }
                Console.WriteLine("real fps: " + (int)(1F / deltaPlusIdleTime) + ", theo fps: " + (int)(1F / deltaTime));
            }
        }
Exemple #2
0
        public Sprite updateFrame(GameTime currentTime)
        {
            int currentFrame = 0;

            if (startSecond.HasValue)
            {
                float passedSeconds = 0F;
                passedSeconds = (float)currentTime.TotalTime.TotalSeconds - startSecond.Value;
                passedSeconds /= ((float)frameCount * secondsPerFrame);
                passedSeconds -= (float)Math.Floor(passedSeconds);

                currentFrame = (int)(passedSeconds * frameCount);
            }

            TextureRect = new IntRect(upperLeftCorner.X + (currentFrame * spriteSize.X), upperLeftCorner.Y, spriteSize.X, spriteSize.Y);
            return this;

        }
Exemple #3
0
 /// <summary>start or restart the animation</summary>
 public void restartAnimation(GameTime currentTime)
 {
     startSecond = (float)currentTime.TotalTime.TotalSeconds;
 }