Пример #1
0
 public void beginGame(string map, Color col)
 {
     state = GameState.InGame;
     playingField = new PlayingField(this);
     playingField.loadContent(map);
     playingField.playerCol = col;
 }
Пример #2
0
        protected override void Update(GameTime gt)
        {
            KeyboardState kb = Keyboard.GetState();

            if(state == GameState.Menu) {
                if(menuMusic.State != SoundState.Playing) menuMusic.Play();
                if(gameMusic.State == SoundState.Playing) gameMusic.Stop();
                menu.updateMenu();

                if(kb.IsKeyDown(Keys.F1) && !helpPrevPressed) state = GameState.Help;
            }
            else if(endTimer == 0 && state == GameState.InGame) {
                if(menuMusic.State == SoundState.Playing) menuMusic.Stop();
                if(gameMusic.State != SoundState.Playing) gameMusic.Play();
                playingField.update(gt);
            }
            else if(endTimer == 0) {
                if(kb.IsKeyDown(Keys.F1) && !helpPrevPressed) state = GameState.Menu;
            }
            else {
                endTimer++;
                if(endTimer > 100) {
                    playingField = null;
                    state = GameState.Menu;
                    endTimer = 0;
                }
            }

            if(Controls.screenshotPressed && !screenshotPrev) {
                ssCount += 1;

                int w = GraphicsDevice.PresentationParameters.BackBufferWidth;
                int h = GraphicsDevice.PresentationParameters.BackBufferHeight;

                Draw(new GameTime());

                int[] backBuffer = new int[w * h];
                GraphicsDevice.GetBackBufferData(backBuffer);

                Texture2D texture = new Texture2D(GraphicsDevice, w, h, false, GraphicsDevice.PresentationParameters.BackBufferFormat);
                texture.SetData(backBuffer);

                Stream stream = File.OpenWrite("ss" + ssCount + ".png");

                texture.SaveAsPng(stream, w, h);
                stream.Dispose();
                texture.Dispose();
            }

            elapsedTime += (float) gt.ElapsedGameTime.TotalSeconds;
            totalFrames++;

            if(elapsedTime >= 1.0f) {
                fps = totalFrames;
                totalFrames = 0;
                elapsedTime = 0;
            }

            Window.Title = "Nano Commander : " + fps + " fps";

            screenshotPrev = Controls.screenshotPressed;
            helpPrevPressed = kb.IsKeyDown(Keys.F1);
            base.Update(gt);
        }