コード例 #1
0
ファイル: SceneTitle.cs プロジェクト: DaedalusGame/7DRL_2021
        public override void Update(GameTime gameTime)
        {
            UpdateTimeModifier();

            Menu.Update(this);
            Menu.HandleInput(this);

            TitleSM.Update();

            MorphoFlash.Update(TimeModCurrent);
            TextFlash.Update(TimeModCurrent);
            UpdateProtoEffects();

            GroundVelocityBase.Update(TimeModCurrent);
            MorphoPositionBase.Update(TimeModCurrent);
            MorphoHeight.Update(TimeModCurrent);
            CastleHeight.Update(TimeModCurrent);
            GroundOffset += GroundVelocity;

            foreach (var particle in GroundParticles)
            {
                particle.Position += GroundVelocity;
                particle.Update(this);
            }
            foreach (var particle in Particles)
            {
                particle.Update(this);
            }
            GroundParticles.RemoveAll(x => x.ProtoEffect.Destroyed);
            Particles.RemoveAll(x => x.ProtoEffect.Destroyed);

            if (MorphoHeight.Value >= 60 && Frame % 6 == 0)
            {
                var direction = Vector2.Normalize(MorphoFacing);
                var lateral   = direction.TurnRight();
                var offset    = direction * 32 + lateral * (Frame % 12 == 0 ? -16 : +16);
                var lifetime  = 30;
                var velocity  = Util.AngleToVector(Random.NextAngle()) * 10;

                var particle = new ParticleGround(new Explosion(this, SpriteLoader.Instance.AddSprite("content/effect_moon_big"), lifetime)
                {
                    Angle = Util.VectorToAngle(GroundVelocity),
                }, MorphoPosition + offset);
                particle.Offset.Set(velocity, LerpHelper.Linear, lifetime);
                GroundParticles.Add(particle);
            }

            MenuCursor = Menu.GetMouseOver(InputState.MouseX, InputState.MouseY);
        }
コード例 #2
0
 public override void Update(GameTime gameTime)
 {
     Menu.Update(this);
     Menu.HandleInput(this);
 }
コード例 #3
0
        protected override void Update(GameTime gameTime)
        {
            base.Update(gameTime);

            //Get input
            HandleInput(gameTime);

            //Get time of first frame
            if (startTime == -1)
            {
                startTime = (int)gameTime.TotalGameTime.TotalSeconds;
            }

            //Countdown
            countdown = startTime + TrafficGame.Duration - (int)gameTime.TotalGameTime.TotalSeconds;
            countdownUI.Update(countdown);
            if (countdown == -3)
            {
                EndGame();
            }

            //Detect if in target lane
            int lane = Road.GetLane(player.Position.X, 0.35f);

            inTargetLane = lane == environment.road.GetHighlightAtPlayerPos();
            environment.road.SetHighlightStatus(lane);

            //Step forward time (slo-mo if player crashed or countdown finished)
            float timeScale = 1.0f;

            if (player.crashed || countdown <= 0)
            {
                timeScale = 0.25f;
            }
            world.Step((float)gameTime.ElapsedGameTime.TotalSeconds * timeScale);

            if (state == GameState.RUNNING)
            {
                if (!player.crashed)
                {
                    //Minimum of 1 point per frame.
                    //Score based on velocity, double points if in correct lane
                    //TODO: For low velocities, we may want less than 1 point per frame.
                    int deltaScore = (int)Math.Max(1, (player.Velocity.Y * gameTime.ElapsedGameTime.TotalSeconds));
                    if (inTargetLane)
                    {
                        deltaScore *= 2;
                    }
                    score += deltaScore;
                }
            }
            else if (state == GameState.STARTING)
            {
                Camera.main.Zoom = Math.Min(1, Camera.main.Zoom + 0.05f);      //Zoom out camera to normal position
                if (gameTime.TotalGameTime.TotalSeconds - stateChangeTime > 3) //Start game after 3 seconds
                {
                    state           = GameState.RUNNING;
                    stateChangeTime = gameTime.TotalGameTime.TotalSeconds;
                    player.Velocity = new Vector2(player.Velocity.X, adjustedSpeed);
                }
            }
            else if (state == GameState.RESTARTING)
            {
                Camera.main.Zoom = Math.Max(0, Camera.main.Zoom - 0.05f);      //Zoom camera in as a transition
                if (gameTime.TotalGameTime.TotalSeconds - stateChangeTime > 1) //Reset world after 1 second
                {
                    state           = GameState.STARTING;
                    stateChangeTime = gameTime.TotalGameTime.TotalSeconds;
                    environment.Reset();
                    trafficManager.Reset();
                    player.Reset();
                    score = 0;
                }
            }

            //Update game stuff
            trafficManager.Update(gameTime, player, state);
            environment.Update(gameTime, player);
            player.Update(gameTime, InputManager.LateralMovement);

            //Light & camera follow player
            Camera.main.Target = new Vector2(player.Position.X, player.Position.Y);
            Lighting.Position  = new Vector3(Lighting.Position.X, player.Position.Y + 15, Lighting.Position.Z);

            //Update GUI
            scoreUI.Update(gameTime, score);
            fpsUI.Update(gameTime);
            titleUI.Update(gameTime);
        }