Пример #1
0
        /// <summary>
        /// Generates an offset vector and force vector for a Particle when it is released.
        /// </summary>
        /// <param name="offset">The offset of the Particle from the trigger location.</param>
        /// <param name="force">A unit vector defining the initial force of the Particle.</param>
        protected override void GenerateOffsetAndForce(out Vector2 offset, out Vector2 force)
        {
#if XBOX
            offset = new Vector2();
#endif
            if (this.Frame)
            {
                if (RandomHelper.NextBool())
                {
                    offset.X = RandomHelper.ChooseOne(-this.HalfWidth, this.HalfWidth);
                    offset.Y = RandomHelper.NextFloat(-this.HalfHeight, this.HalfHeight);
                }
                else
                {
                    offset.X = RandomHelper.NextFloat(-this.HalfWidth, this.HalfWidth);
                    offset.Y = RandomHelper.ChooseOne(-this.HalfHeight, this.HalfHeight);
                }
            }
            else
            {
                offset.X = RandomHelper.NextFloat(-this.HalfWidth, this.HalfWidth);
                offset.Y = RandomHelper.NextFloat(-this.HalfHeight, this.HalfHeight);
            }

            // Apply the Emitter rotation to the offset vector...
            Vector2 unrotatedOffset = offset;

            offset.X = ((unrotatedOffset.X * this.AngleCos) + (unrotatedOffset.Y * -this.AngleSin));
            offset.Y = ((unrotatedOffset.X * this.AngleSin) + (unrotatedOffset.Y * this.AngleCos));

            force = RandomHelper.NextUnitVector();
        }
Пример #2
0
        /// <summary>
        /// Generates an offset vector and force vector for a Particle when it is released.
        /// </summary>
        /// <param name="offset">The offset of the Particle from the trigger location.</param>
        /// <param name="force">A unit vector defining the initial force of the Particle.</param>
        protected override void GenerateOffsetAndForce(out Vector2 offset, out Vector2 force)
        {
            force = RandomHelper.NextUnitVector();

            offset = RandomHelper.ChooseOne(this.MaskHits);

            offset.X *= this.Width;
            offset.Y *= this.Height;
        }
Пример #3
0
        private void AddNewPiece()
        {
            Active = CreatePiece(Next);
            Next   = RandomHelper.ChooseOne(Tetromino.All);

            if (TouchesFloorPile(Active))
            {
                // Game Over
                State = GameState.GameOver;
                SendEvent(TetrisEvents.GameOver);
            }
            else
            {
                SendEvent(TetrisEvents.NewPiece);
            }
        }
Пример #4
0
        public bool SendInput(Input keyPress)
        {
            if (State == GameState.InProgress)
            {
                if (Active != null)
                {
                    if (keyPress == Input.MoveRight)
                    {
                        if (Active.GetBricks().All(a => a.X < Width - 1) && // wall
                            !Collision(floor.ForEach().ToArray(), Active.GetBricks(Active.Position.AddX(1), Active.Rotation).ToArray())
                            )
                        {
                            Active.Position = Active.Position.AddX(1);
                            return(true);
                        }
                        return(false);
                    }
                    else if (keyPress == Input.MoveLeft)
                    {
                        if (Active.GetBricks().All(a => a.X > 0) &&
                            !Collision(floor.ForEach().ToArray(), Active.GetBricks(Active.Position.AddX(-1), Active.Rotation).ToArray())
                            )
                        {
                            Active.Position = Active.Position.AddX(-1);
                            return(true);
                        }
                        return(false);
                    }
                    else if (keyPress == Input.Rotate)
                    {
                        if (Active.GetBricks(Active.Rotation + 1).All(a => a.X >= 0 && a.X < Width))
                        {
                            Active.Rotation++;
                            return(true);
                        }
                        return(false);
                    }
                    else if (keyPress == Input.Drop)
                    {
                        while (!TouchesFloorPile(Active))
                        {
                            Active.Position = Active.Position.AddY(1);
                        }
                        return(true);
                    }
                }

                if (keyPress == Input.Quit)
                {
                    SetMessage("Quitting... Bye Bye!");
                    State = GameState.GameOver;
                    return(true);
                }
            }
            else if (State == GameState.WaitingStart && keyPress == Input.Start)
            {
                SetMessage("Good Luck...");
                State  = GameState.InProgress;
                Next   = RandomHelper.ChooseOne(Tetromino.All);
                Active = CreatePiece(Next);
                Next   = RandomHelper.ChooseOne(Tetromino.All);
                return(true);
            }
            return(true);
        }