Ejemplo n.º 1
0
        public override void Update(GameTime gameTime)
        {
            if (gameTime != null)
            {
                KeyboardDebouncer ks = KeyboardController.GetState();
                if (!this.Transitioning && this.doorTrigger.IsActive)
                {
                    if (ks.IsKeyDown(KeyboardController.InteractionKey, true) && string.Compare(this.Sprites["Door"].CurrentAnimationString, "Open", StringComparison.CurrentCulture) != 0)
                    {
                        this.Sprites["Door"].CurrentAnimationString = "Open";
                        this.Transitioning = true;
                    }
                    else if (this.isDoorOpen && this.layerTrigger.IsActive)
                    {
                        this.Sprites["Door"].CurrentAnimationString = "Close";
                        this.Sprites["Door"].Depth = 1f;
                        this.Transitioning         = true;
                    }
                }
                else if (string.Compare(this.Sprites["Door"].CurrentAnimationString, "Open", StringComparison.CurrentCulture) == 0 && !this.doorTrigger.IsActive && !this.Receiving)
                {
                    this.isDoorOpen = false;
                    uint index = this.Sprites["Door"].CurrentFrame;
                    this.Sprites["Door"].CurrentAnimationString = "Close";
                    this.Sprites["Door"].CurrentFrame           = index;
                    this.Transitioning = true;
                }

                base.Update(gameTime);
            }
        }
Ejemplo n.º 2
0
        private bool GetRotation(KeyboardDebouncer state)
        {
            bool rotated = false;

            if (state.IsKeyDown(KeyboardController.RotateLeftKey))
            {
                if (this.markedRotateMilliseconds > this.nextRotationTime)
                {
                    this.Body.Awake = true;
                    this.Screen.RotateWorld(-this.RotationSpeed);
                    this.nextRotationTime         = this.RotationTiming;
                    this.markedRotateMilliseconds = 0;
                }

                rotated = true;
            }
            else if (state.IsKeyDown(KeyboardController.RotateRightKey))
            {
                if (this.markedRotateMilliseconds > this.nextRotationTime)
                {
                    this.Body.Awake = true;
                    this.Screen.RotateWorld(this.RotationSpeed);
                    this.nextRotationTime         = this.RotationTiming;
                    this.markedRotateMilliseconds = 0;
                }

                rotated = true;
            }

            return(rotated);
        }
Ejemplo n.º 3
0
        public override void Update(GameTime gameTime)
        {
            if (gameTime != null)
            {
                KeyboardDebouncer ks = KeyboardController.GetState();
                if (!this.Transitioning && this.elevatorTrigger.IsActive)
                {
                    PhysicistPath path     = null;
                    int           floordif = int.MaxValue;
                    if (ks.IsKeyDown(KeyboardController.UpKey, true))
                    {
                        if (this.CurrentFloor != 0)
                        {
                            foreach (var p in this.PathManager.Paths)
                            {
                                int floorVal = int.Parse(p.Name, CultureInfo.CurrentCulture);
                                if ((floorVal < this.CurrentFloor) && (this.CurrentFloor - floorVal < floordif))
                                {
                                    floordif = this.CurrentFloor - floorVal;
                                    path     = p;
                                }
                            }
                        }
                    }
                    else if (ks.IsKeyDown(KeyboardController.DownKey, true))
                    {
                        if (this.CurrentFloor != this.FloorCount - 1)
                        {
                            foreach (var p in this.PathManager.Paths)
                            {
                                int floorVal = int.Parse(p.Name, CultureInfo.CurrentCulture);
                                if ((floorVal > this.CurrentFloor) && (floorVal - this.CurrentFloor < floordif))
                                {
                                    floordif = floorVal - this.CurrentFloor;
                                    path     = p;
                                }
                            }
                        }
                    }
                    else if (ks.IsKeyDown(KeyboardController.InteractionKey, true))
                    {
                        if (this.LayerTransition != null)
                        {
                            this.LayerTransition(this, new LayerTransitionEventArgs(this.Position, this.TargetDoor));
                        }
                    }

                    if (path != null)
                    {
                        this.Transitioning = true;
                        path.Reset();
                        path.PathCompleted          += this.FloorReached;
                        path.IsEnabled               = true;
                        this.PathManager.CurrentPath = path.Name;
                    }
                }

                base.Update(gameTime);
            }
        }
Ejemplo n.º 4
0
        private Vector2 GetMovementSpeed(KeyboardDebouncer state)
        {
            var dp = Vector2.Zero;

            if (state.IsKeyDown(KeyboardController.LeftKey))
            {
                var speedMod = Vector2.Transform(new Vector2(-1 * this.MovementSpeed.X, 0), Matrix.CreateRotationZ(-1 * this.Screen.ScreenRotation));
                if (!this.footButton.IsActive)
                {
                    speedMod /= this.midairDampening;
                }

                dp += speedMod;
                this.SpriteState = "Left";
            }
            else if (state.IsKeyDown(KeyboardController.RightKey))
            {
                var speedMod = Vector2.Transform(new Vector2(this.MovementSpeed.X, 0), Matrix.CreateRotationZ(-1 * this.Screen.ScreenRotation));
                if (!this.footButton.IsActive)
                {
                    speedMod /= this.midairDampening;
                }

                dp += speedMod;

                this.SpriteState = "Right";
            }
            else if (this.footButton.IsActive)
            {
                // Dampen the horizontal velocity to simulate the player stopping itself from sliding around
                Vector2 newVelocity = this.Body.LinearVelocity;

                newVelocity    = Vector2.Transform(newVelocity, Matrix.CreateRotationZ(this.Screen.ScreenRotation));
                newVelocity.X /= this.groundDampening;
                newVelocity    = Vector2.Transform(newVelocity, Matrix.CreateRotationZ(-1 * this.Screen.ScreenRotation));

                this.Body.LinearVelocity = newVelocity;
                this.SpriteState         = "Idle";
            }
            else
            {
                this.SpriteState = "Idle";
            }

            return(dp);
        }
Ejemplo n.º 5
0
        private void GetJump(KeyboardDebouncer state)
        {
            if (this.jumpEndTime > 0)
            {
                if (this.markedJumpMilliseconds >= this.jumpEndTime)
                {
                    this.Body.GravityScale = 4;
                    this.jumpEndTime       = 0;

                    // remove the jump velocity
                    Vector2 newVelocity = this.Body.LinearVelocity;

                    newVelocity    = Vector2.Transform(newVelocity, Matrix.CreateRotationZ(this.Screen.ScreenRotation));
                    newVelocity.Y /= 2;
                    newVelocity    = Vector2.Transform(newVelocity, Matrix.CreateRotationZ(-1 * this.Screen.ScreenRotation));

                    this.Body.LinearVelocity = newVelocity;
                }
            }
            else
            {
                this.Body.GravityScale = 4;
            }

            if (state.IsKeyDown(KeyboardController.JumpKey) && this.footButton.IsActive)
            {
                if (this.jumpEndTime == 0)
                {
                    this.jumpEndTime            = this.JumpTiming;
                    this.markedJumpMilliseconds = 0;
                    this.Body.GravityScale      = 0;
                    this.Body.LinearVelocity   += Vector2.Transform(new Vector2(0, -1 * this.JumpSpeed), Matrix.CreateRotationZ(-1 * this.Screen.ScreenRotation));
                }
            }

            if (!state.IsKeyDown(KeyboardController.JumpKey) || this.headButton.IsActive)
            {
                if (this.jumpEndTime != 0 && this.jumpEndTime - 200 > this.markedJumpMilliseconds)
                {
                    this.jumpEndTime = this.markedJumpMilliseconds + 200;
                }
            }
        }