Beispiel #1
0
        public virtual void update(MouseInfo mouse, KeyInfo keys, float deltaTime)
        {
            for (int i = uiTransitions.Count - 1; i >= 0; i--)
            {
                UITransition transition = uiTransitions[i];

                if (transition.deleteFlag)
                {
                    uiTransitions.RemoveAt(i);
                    continue;
                }

                transition.update(deltaTime);
            }

            foreach (var element in uiElements)
            {
                element.update(mouse, keys, deltaTime);
            }
        }
Beispiel #2
0
        protected override void Update(GameTime gameTime)
        {
            base.Update(gameTime);

            float deltaTime = delta(gameTime);

            fpsCounter.update(deltaTime);
            if ((int)gameTime.TotalGameTime.TotalSeconds > secondsPassed)
            {
                secondsPassed = (int)gameTime.TotalGameTime.TotalSeconds;
                Window.Title  = "FPS: " + (int)fpsCounter.AverageFramesPerSecond;
            }

            KeyboardState keyState   = Keyboard.GetState();
            MouseState    mouseState = Mouse.GetState();

            KeyInfo   keys  = new KeyInfo(keyState, lastKeyState);
            MouseInfo mouse = new MouseInfo(mouseState, lastMouseState);

            lastKeyState   = keyState;
            lastMouseState = mouseState;

            if (keys.down(Keys.Escape))
            {
                exitGame();
            }


            if (uiScreen != null)
            {
                uiScreen.update(mouse, keys, deltaTime);
                return;
            }



            if (keys.pressed(Keys.L))
            {
                startEditMode();
            }

            if (keys.pressed(Keys.S) && keys.down(Keys.LeftControl))
            {
                wiringEditor?.saveWiring(levelName);
            }

            if (keys.pressed(Keys.T))
            {
                wiringEditor?.applyWiring();
            }

            if (keys.pressed(Keys.G))
            {
                player.godMode = !player.godMode;
            }

            if (keys.pressed(Keys.R))
            {
                restartRun();
            }


            // debug change level
            if (keys.pressed(Keys.Left))
            {
                lastLevel();
            }
            if (keys.pressed(Keys.Right))
            {
                nextLevel();
            }


            // UI
            for (int i = uiTransitions.Count - 1; i >= 0; i--)
            {
                UITransition transition = uiTransitions[i];

                if (transition.deleteFlag)
                {
                    uiTransitions.RemoveAt(i);
                    continue;
                }

                transition.update(deltaTime);
            }

            foreach (var element in uiElements)
            {
                element.update(mouse, keys, deltaTime);
            }

            if (keys.pressed(Keys.P))
            {
                if (!paused)
                {
                    paused     = true;
                    pauseTimer = 0;
                    uiElements = pauseUI;
                    UI.transitionAll(uiElements, element => new SlideIn(element)
                    {
                        endTime = pauseTransitionTime
                    });
                }
                else
                {
                    unPauseClicked();
                }
            }

            if (paused && endingPause && uiTransitions.Count == 0)
            {
                paused      = false;
                endingPause = false;
                uiElements  = gameUI;
            }

            if (paused)
            {
                if (endingPause)
                {
                    pauseTimer -= deltaTime;
                }
                else
                {
                    pauseTimer += deltaTime;
                }
            }

            pauseTimer = Math.Min(pauseTimer, pauseTransitionTime);


            // Must Be Un-paused to Run Following Code =======
            if (paused)
            {
                return;
            }

            if (!player.dead)
            {
                attemptTime += deltaTime;
            }

            adjustMusicFade();

            if (mouse.leftPressed && keys.down(Keys.LeftShift))
            {
                player.pos = camera.toWorld(mouse.pos, player.zPos);
            }

            player.input(keys, deltaTime);

            if (editMode)
            {
                wiringEditor?.input(mouse, keys, deltaTime);
            }

            updateEntities(deltaTime);

            updateParticles(deltaTime);

            map.update(deltaTime);

            camera.pos = player.pos - Vector2.UnitY * 5;
            // screen shake
            if (screenShakeTime > 0)
            {
                screenShakeTime -= deltaTime;
                camera.pos      += Util.polar(screenShakeIntensity * screenShakeTime / screenShakeStart, Util.randomAngle());
            }

            Vector2 diff = camera.screenCenter / (camera.scale * camera.farMult(-2));
            float   clampCameraBottom = ChunkMap.mapHeight() - 1 - diff.Y;
            float   clampCameraTop    = 1 + diff.Y;

            camera.pos.Y = Math.Clamp(camera.pos.Y, clampCameraTop, clampCameraBottom);

            for (int i = 0; i < entities.Length; i++)
            {
                entities[i] = new List <Entity>();
            }

            foreach (var entity in updatedEntities)
            {
                sortIntoEntities(entity);
            }
        }