예제 #1
0
        void SetupParticle(Particle particle)
        {
#if EDITOR
#else
            //  Life
            float life = SpinAssist.GetRandom(_minLifeTime, _maxLifeTime);

            //  Velocity
            float angle = SpinAssist.GetRandom(this._minSpawnAngle, this._maxSpawnAngle);
            angle = MathHelper.ToRadians(angle);
            Vector2 direction = new Vector2((float)Math.Cos(angle), (float)Math.Sin(angle));

            float speed = SpinAssist.GetRandom(this._minSpeed, this._maxSpeed);
            _velocity = direction * speed;

            Vector2 acceleration = Vector2.Zero;

            //if (_useGravity)
            //{
            //    acceleration = _world.Gravity * _gravityModifier;
            //}


            particle.Init(this._position, _velocity, acceleration, life);
            particle.Alpha = _alpha;
            particle.Scale = _scale;
#endif
        }
예제 #2
0
        /// <summary>
        /// Create
        /// </summary>
        private void CreateSteamPlume()
        {
            //  Get a random initial rotation as rotation speed is predecided.
            float rotation = SpinAssist.GetRandom(0, (float)(Math.PI * 2));

            _steamSprite.Rotation = rotation;

            //  Randomize how quickly it should dissipate
            float alphadecay = SpinAssist.GetRandom(0.02f, 0.08f);

            _steamSprite.AlphaDecay = alphadecay;

            //  Check if the fart cheat is on
            if (GameSettings.Instance.FartCheat)
            {
                //  Make it come from his buttocks and turn it green..
                _steamSprite.Tint     = Color.LightGreen.ToVector3();
                _steamSprite.Position = ConvertUnits.ToDisplayUnits(_mainBody.Position);
            }
            else
            {
                //  Otherwise from the wheel.
                _steamSprite.Position = ConvertUnits.ToDisplayUnits(_wheelBody.Position);
            }

            //  Then add it to the SpriteManager for handling.
            SpriteManager.Instance.AddSprite((Sprite)_steamSprite.Clone());
        }
예제 #3
0
        /// <summary>
        /// Apply the force to the player.
        /// </summary>
        private void ApplyForces()
        {
            Player playerInstance = Player.Instance;

            //  What direction the player should be pushed. In this case, Up before modify.
            Vector2 dir = SpinAssist.ModifyVectorByOrientation(new Vector2(0, -100), _orientation);

            //  Normalize the direction...
            dir.Normalize();

            //  Then apply a speed.
            dir *= 8;

            //  Check all the fixtures that are touching the trigger and apply a force to them.
            for (int i = _touchingFixtures.Count - 1; i >= 0; i--)
            {
                //  We have a special way to push the player, so check if 'i' is a player fixture.
                if (playerInstance.CheckHitBoxFixture(_touchingFixtures[i]))
                {
                    //  If Harland is dead, remove him and continue.
                    if (playerInstance.PlayerState == PlayerState.Dead)
                    {
                        this._touchingFixtures.RemoveAt(i);
                        continue;
                    }

                    //  It is the player, so apply the force
                    playerInstance.ApplyForce(dir, 10.0f);
                    continue;
                }

                //  It's a random object, so apply a force to it too.
                this._touchingFixtures[i].Body.ApplyForce(dir);
            }
        }
예제 #4
0
        public void Update(float delta)
        {
            Player       playerInstance = Player.Instance;
            InputManager input          = InputManager.Instance;

            if (_cameraType == CameraType.Level && _cameraPosition != Vector2.Zero)
            {
                this._cameraPosition = Vector2.Zero;
            }
            else if (_cameraType == CameraType.Focus)
            {
                if (playerInstance.PlayerState != PlayerState.Dead)
                {
                    this._cameraPosition = ConvertUnits.ToDisplayUnits(playerInstance.GetMainBody().Position);
                }
            }
#if Development
            else if (_cameraType == CameraType.Free)
            {
                if (InputManager.Instance.RightThumbstick.X != 0)
                {
                    _cameraPosition += SpinAssist.ModifyVectorByUp(new Vector2(InputManager.Instance.RightThumbstick.X * 10, 0));
                }
                if (InputManager.Instance.RightThumbstick.Y != 0)
                {
                    _cameraPosition -= SpinAssist.ModifyVectorByUp(new Vector2(0, InputManager.Instance.RightThumbstick.Y * 10));
                }
            }

            ZoomModifierInput();

            //  Debug camera control
            if (InputManager.Instance.GP_Back)
            {
                //  Cycle through
                switch (_cameraType)
                {
                case CameraType.Free:
                    _cameraType = CameraType.Level;
                    break;

                case CameraType.Level:
                    _cameraType = CameraType.Focus;
                    break;

                case CameraType.Focus:
                    _cameraType = CameraType.Free;
                    break;
                }
            }
#endif
            this.handleInput();
            this.handleRotation(delta);
        }
예제 #5
0
        void HandleSwinging(float delta)
        {
            this._mainBody.Rotation = _grabbingRotation;

            if (InputManager.Instance.MoveLeft(false))
            {
                this._wheelBody.ApplyForce(SpinAssist.ModifyVectorByUp(new Vector2(-_midAirForce * 1.5f, 0)));
            }
            else if (InputManager.Instance.MoveRight(false))
            {
                this._wheelBody.ApplyForce(SpinAssist.ModifyVectorByUp(new Vector2(_midAirForce * 1.5f, 0)));
            }
        }
예제 #6
0
        /// <summary>
        /// Add and randomize a steam sprite that is expelled from the platform.
        /// </summary>
        private void AddSprite()
        {
            //  Get a random offset for the x acceleration to differentiate the numerous clouds
            float xVelo = SpinAssist.GetRandom(-2.0f, 2.0f);

            //  Create a new velocity and rotation for this sprite to fire.
            this._exhaustSprite.Velocity = SpinAssist.ModifyVectorByOrientation(new Vector2(xVelo, -20), _orientation);
            this._exhaustSprite.Rotation = SpinAssist.GetRandom(0, MathHelper.TwoPi);

            //  Clone the editted base steam sprite to expell
            Sprite newSprite = (Sprite)_exhaustSprite.Clone();

            SpriteManager.Instance.AddSprite(newSprite);

            //  How long should it wait before expelling another steam sprite.
            _createDelay = 0.07f;
        }
예제 #7
0
        protected override void SetupPhysics(World world)
        {
            this.Body = BodyFactory.CreateRectangle(world,
                                                    ConvertUnits.ToSimUnits(30),
                                                    ConvertUnits.ToSimUnits(30),
                                                    1.0f);

            //  Change the position to it's above the lowest point of the doors
            //  texture
            this.Body.Position = ConvertUnits.ToSimUnits(_position + SpinAssist.ModifyVectorByOrientation(
                                                             new Vector2(0, (this._height * 0.5f) - (30 * 0.5f)),
                                                             this._orientation));

            this.Body.OnSeparation += Body_OnSeparation;
            this.Body.OnCollision  += Body_OnCollision;

            this.Body.IsSensor = true;
            this.Body.Enabled  = _enabled;
        }
예제 #8
0
        /// <summary>
        /// Get the position of the trigger.
        /// </summary>
        /// <param name="convert">Should the output return it converted to sim units?</param>
        /// <returns>The trigger position</returns>
        private Vector2 GetTriggerPosition(bool convert)
        {
            Vector2 bodyPos = Vector2.Zero;

            //  We want the bottom of the trigger placed at the top of the trigger.
            bodyPos.Y = (this.Height + this.TriggerHeight) * 0.5f;

            //  Modify it for the objects rotation
            bodyPos = SpinAssist.ModifyVectorByOrientation(bodyPos, _orientation);

            //  Modify the offset for later calculation
            Vector2 newOffset = SpinAssist.ModifyVectorByOrientation(_triggerOffset, _orientation);

            if (convert)
            {
                return(ConvertUnits.ToSimUnits(this._position - bodyPos + newOffset));
            }
            else
            {
                return(this._position - bodyPos + newOffset);
            }
        }
예제 #9
0
        void AddParticle()
        {
#if EDITOR
#else
            int numParticles = SpinAssist.GetRandom(_minParticles, _maxParticles);

            for (int j = 0; j < numParticles; j++)
            {
                if (_queuedParticles.Count == 0)
                {
                    for (int i = 0; i < numParticles; i++)
                    {
                        Particle p = new Particle();
                        _particles.Add(p);
                        _queuedParticles.Enqueue(p);
                    }
                }

                Particle particle = _queuedParticles.Dequeue();
                SetupParticle(particle);
            }
#endif
        }
예제 #10
0
        public override void Load(ContentManager content, World world)
        {
            this._texture = content.Load <Texture2D>(this._textureAsset);
            this._origin  = new Vector2(this._texture.Width, this._texture.Height) * 0.5f;

#if EDITOR
            _devTexture = content.Load <Texture2D>(Defines.DEVELOPMENT_TEXTURE);

            if (Width == 0 || Height == 0)
            {
                Width  = _texture.Width;
                Height = _texture.Height;
            }

            if (this.TriggerHeight == 0 || this.TriggerWidth == 0)
            {
                this._triggerWidth  = _texture.Width * 0.33f;
                this._triggerHeight = 250.0f;
            }
#else
            this.SetupPhysics(world);
            this.RegisterObject();
            this._soundEffectAsset = "Steam_Emit_Constant";

            #region Setup the steam sprite
            _exhaustSprite = new Sprite();
            _exhaustSprite.Init(ConvertUnits.ToDisplayUnits(this.Body.Position) + SpinAssist.ModifyVectorByOrientation(new Vector2(0, _triggerHeight * 0.5f), _orientation));
            _exhaustSprite.SetTexture(content.Load <Texture2D>(_exhaustTextureAsset));
            _exhaustSprite.Alpha         = 0.4f;
            _exhaustSprite.AlphaDecay    = 0.02f;
            _exhaustSprite.ZLayer        = this._zLayer + 0.01f;
            _exhaustSprite.Scale         = 0.3f;
            _exhaustSprite.RotationSpeed = 0.001f;
            _exhaustSprite.ScaleFactor   = SpinAssist.GetRandom(0.0005f, 0.01f);
            #endregion
#endif
        }
예제 #11
0
        private void PlayRandomAmbience()
        {
            for (int i = 0; i < 4; i++)
            {
                int odds = SpinAssist.GetRandom(1, 10);

                if (odds > 5)
                {
                    switch (i)
                    {
                    case 0:
                    {
                        AudioManager.Instance.PlayCue("Background_Clangs", true);
                        break;
                    }

                    case 1:
                    {
                        AudioManager.Instance.PlayCue("Background_Creeks", true);
                        break;
                    }

                    case 2:
                    {
                        AudioManager.Instance.PlayCue("Background_Echos", true);
                        break;
                    }

                    case 3:
                    {
                        AudioManager.Instance.PlayCue("Background_Wind", true);
                        break;
                    }
                    }
                }
            }
        }
예제 #12
0
        protected override void SetupPhysics(World world)
        {
#if !EDITOR
            Vector2 simPosition = ConvertUnits.ToSimUnits(this._position);

            if (_useShape)
            {
                float simHeight = ConvertUnits.ToSimUnits(this._height);
                float simWidth  = ConvertUnits.ToSimUnits(this._width);
                this.Body          = new Body(world);
                this.Body.Position = simPosition;

                this._origin = new Vector2(this._texture.Width, this._texture.Height) * 0.5f;

                switch (_shapeType)
                {
                case ObjectShape.Quadrilateral:
                {
                    Fixture fixture = FixtureFactory.AttachRectangle(simWidth, simHeight, _mass, Vector2.Zero, Body);
                    break;
                }

                case ObjectShape.Circle:
                {
                    Fixture fixture = FixtureFactory.AttachCircle(simWidth * 0.5f, _mass, this.Body);
                    break;
                }
                }

                this._revoluteJoint = JointFactory.CreateFixedRevoluteJoint(world, Body, Vector2.Zero, simPosition);
            }
            else
            {
                bool useCentroid = false;

                if (_rotatesWithLevel)
                {
                    useCentroid = true;
                }

                TexVertOutput input = SpinAssist.TexToVert(world, _texture, _mass, false);

                this._origin = Vector2.Zero;
                this.Body    = input.Body;


                this.Body.Position = simPosition;
                if (useCentroid)
                {
                    this._revoluteJoint = JointFactory.CreateFixedRevoluteJoint(world, Body, this.Body.LocalCenter, simPosition);
                }
                else
                {
                    this._revoluteJoint = JointFactory.CreateFixedRevoluteJoint(world, Body, this.Body.LocalCenter, simPosition);
                }

                this._revoluteJoint.MaxMotorTorque = float.MaxValue;
                this._revoluteJoint.MotorEnabled   = true;

                if (!_rotatesWithLevel)
                {
                    this.Body.BodyType = BodyType.Dynamic;
                }
                else
                {
                    this.Body.BodyType = BodyType.Dynamic;
                    this.Body.Rotation = this._rotation;
                    float newSpeed = 1 / _motorSpeed;
                    this._motorSpeed = newSpeed;
                }

                if (this._motorEnabled)
                {
                    this._revoluteJoint.MotorSpeed = _motorSpeed;
                }
                else
                {
                    this._revoluteJoint.MotorSpeed = 0.0f;
                }
            }
            this.Body.CollidesWith        = Category.All & ~Category.Cat20;
            this.Body.CollisionCategories = Category.Cat20;

            this.Body.Friction = 3.0f;

            this.Body.UserData = _materialType;
#endif
        }
예제 #13
0
        protected override void SetupPhysics(World world)
        {
            float   textureWidth  = ConvertUnits.ToSimUnits(this._texture.Width);
            float   textureHeight = ConvertUnits.ToSimUnits(this._texture.Height);
            Vector2 axis          = SpinAssist.ModifyVectorByOrientation(new Vector2(0, -1), _orientation);
            Body    body;

            #region Shaft
            for (int i = 0; i < _shaftPieces; i++)
            {
                body          = new Body(world);
                body.Position = ConvertUnits.ToSimUnits(this._position);
                body.Rotation = SpinAssist.RotationByOrientation(this._orientation);

                if (i == 0)
                {
                    Fixture fixture = FixtureFactory.AttachRectangle(textureWidth, textureHeight, 1.0f, Vector2.Zero, body);
                    body.BodyType = BodyType.Static;
                }
                else
                {
                    Fixture fixture = FixtureFactory.AttachRectangle(textureWidth - ((textureWidth * 0.04f) * i), textureHeight, 1.0f, Vector2.Zero, body);
                    body.BodyType = BodyType.Dynamic;

                    FixedPrismaticJoint _joint = JointFactory.CreateFixedPrismaticJoint(world, body, ConvertUnits.ToSimUnits(this._position), axis);
                    _joint.MotorEnabled  = true;
                    _joint.MaxMotorForce = float.MaxValue;
                    _joint.LimitEnabled  = true;
                    _joint.LowerLimit    = 0;
                    _joint.UpperLimit    = (textureHeight * i);
                    _joints.Add(_joint);
                }
                body.Friction            = 3.0f;
                body.CollisionCategories = Category.Cat2;
                //  Ignore collision with Statics and other pistons.
                body.CollidesWith = Category.All & ~Category.Cat2 & ~Category.Cat20;
                body.UserData     = _materialType;
                _shaftBodies.Add(body);
            }
            #endregion

            #region Endpiece

            TexVertOutput input = SpinAssist.TexToVert(world, _crusherTexture, ConvertUnits.ToSimUnits(10), true);

            _crusherTextureOrigin = -ConvertUnits.ToSimUnits(input.Origin);

            this.Body                     = input.Body;
            this.Body.Position            = ConvertUnits.ToSimUnits(this._position);
            this.Body.Rotation            = this._rotation;
            this.Body.Friction            = 3.0f;
            this.Body.Restitution         = 0.0f;
            this.Body.BodyType            = BodyType.Dynamic;
            this.Body.Mass                = 100.0f;
            this.Body.CollisionCategories = Category.Cat2;
            //  Ignore collision with Statics and other pistons.
            this.Body.CollidesWith = Category.All & ~Category.Cat2 & ~Category.Cat20;
            this.Body.UserData     = _materialType;

            this._prismaticJoint               = JointFactory.CreateFixedPrismaticJoint(world, this.Body, ConvertUnits.ToSimUnits(this._position + new Vector2(0, 40)), axis);
            this._prismaticJoint.UpperLimit    = (textureHeight * (_shaftPieces));
            this._prismaticJoint.LowerLimit    = (textureHeight * 0.5f);
            this._prismaticJoint.LimitEnabled  = true;
            this._prismaticJoint.MotorEnabled  = true;
            this._prismaticJoint.MaxMotorForce = float.MaxValue;

            #endregion

            if (_isLethal)
            {
                float endHeight = ConvertUnits.ToSimUnits(_crusherTexture.Height);

                Fixture fix = FixtureFactory.AttachRectangle(
                    ConvertUnits.ToSimUnits(_crusherTexture.Width - 20),
                    endHeight * 0.38f,
                    1.0f, new Vector2(0, -endHeight * 0.4f),
                    Body);
                fix.IsSensor = true;
                fix.IgnoreCollisionWith(this.Body.FixtureList[0]);

                fix.Body.OnCollision  += TouchedLethal;
                fix.Body.OnSeparation += LeftLethal;
            }
        }
예제 #14
0
        void HandleAir(float delta)
        {
            Vector2 bodyPos  = ConvertUnits.ToDisplayUnits(_mainBody.Position);
            float   distance = SpinAssist.ModifyVectorByUp(bodyPos - _lastSafePosition).Y;

            if (_inAir && (Math.Abs(distance) > 550) && !_deadlyFall)
            {
                _deadlyFall = true;
                AudioManager.Instance.PlayCue("Harland_Falling", true);
            }

            if (_playerState != Characters.PlayerState.Falling)
            {
                if (CurrentAnimation.Completed)
                {
                    this.PlayerState = PlayerState.Falling;
                }
            }

            if (InputManager.Instance.MoveLeft(false))
            {
                UpIs  upIs       = Camera.Instance.GetUpIs();
                float speedLimit = 25;

                this._wheelBody.ApplyForce(SpinAssist.ModifyVectorByUp(new Vector2(-_midAirForce, 0)));

                if (upIs == UpIs.Up || upIs == UpIs.Down)
                {
                    this._wheelBody.LinearVelocity = new Vector2(
                        MathHelper.Clamp(_wheelBody.LinearVelocity.X, -speedLimit, speedLimit),
                        _wheelBody.LinearVelocity.Y);
                }
                else
                {
                    this._wheelBody.LinearVelocity = new Vector2(
                        _wheelBody.LinearVelocity.X,
                        MathHelper.Clamp(_wheelBody.LinearVelocity.Y, -speedLimit, speedLimit));
                }

                this._lookingDirection = SpriteEffects.FlipHorizontally;
            }
            else if (InputManager.Instance.MoveRight(false))
            {
                UpIs  upIs       = Camera.Instance.GetUpIs();
                float speedLimit = 25;

                this._wheelBody.ApplyForce(SpinAssist.ModifyVectorByUp(new Vector2(_midAirForce, 0)));

                if (upIs == UpIs.Up || upIs == UpIs.Down)
                {
                    this._wheelBody.LinearVelocity = new Vector2(
                        MathHelper.Clamp(_wheelBody.LinearVelocity.X, -speedLimit, speedLimit),
                        _wheelBody.LinearVelocity.Y);
                }
                else
                {
                    this._wheelBody.LinearVelocity = new Vector2(
                        _wheelBody.LinearVelocity.X,
                        MathHelper.Clamp(_wheelBody.LinearVelocity.Y, -speedLimit, speedLimit));
                }

                this._lookingDirection = SpriteEffects.None;
            }
        }
예제 #15
0
        void HandleJumping(Vector2 Gravity)
        {
            if (_playerState == Characters.PlayerState.Swinging)
            {
                return;
            }

            Vector2      force = Gravity;
            InputManager input = InputManager.Instance;

            //  First jump
            if (_canJump)
            {
                if (_playerState == PlayerState.Climbing)
                {
                    if (!(input.MoveLeft(false) || input.MoveRight(false)))
                    {
                        return;
                    }

                    force *= 3.0f;

                    if (input.MoveLeft(false))
                    {
                        Vector2 additionalForce = SpinAssist.ModifyVectorByUp(new Vector2(-150, -force.Y * 0.5f));
                        Vector2.Add(ref force, ref additionalForce, out force);
                        this._lookingDirection = SpriteEffects.FlipHorizontally;
                    }
                    else if (InputManager.Instance.MoveRight(false))
                    {
                        Vector2 additionalForce = SpinAssist.ModifyVectorByUp(new Vector2(150, -force.Y * 0.5f));
                        Vector2.Add(ref force, ref additionalForce, out force);
                        this._lookingDirection = SpriteEffects.None;
                    }

                    this.ToggleBodies(true);
                    this._wheelBody.ApplyLinearImpulse(force);
                    this.PlayerState = PlayerState.Jumping;
                    this._canJump    = false;
                }
                else
                {
                    force *= _jumpForce;
                    _wheelBody.FixtureList[0].Body.ApplyLinearImpulse(force);
                    this.PlayerState = PlayerState.Jumping;
                    this._canJump    = false;
                    this._airTime    = 0.0f;
                    AudioManager.Instance.PlayCue("Harland_Grunt", true);
                }
            }
            //  Second jump (steam jump)
            else if (GameSettings.Instance.DoubleJumpEnabled && _canDoubleJump)
            {
                //  We only want to 0 the Up/Down depending on the
                //  orientation.
                #region Reset the Y dynamics.
                if (Math.Abs(Gravity.Y) > 0)
                {
                    this._mainBody.LinearVelocity  = new Vector2(_mainBody.LinearVelocity.X, 0);
                    this._wheelBody.LinearVelocity = new Vector2(_mainBody.LinearVelocity.X, 0);
                }
                else
                {
                    this._mainBody.LinearVelocity  = new Vector2(0, _mainBody.LinearVelocity.Y);
                    this._wheelBody.LinearVelocity = new Vector2(0, _mainBody.LinearVelocity.Y);
                }

                #endregion

                force *= _jumpForce;

                // Apply 2 forces. Up and then direction
                if (Math.Abs(InputManager.Instance.LeftThumbstick.X) >= 0.2)
                {
                    Vector2 direction = new Vector2(InputManager.Instance.LeftThumbstick.X, 0);
                    direction.Normalize();
                    direction *= 15.0f;

                    _wheelBody.ApplyLinearImpulse(direction);
                }

                //  Disable the possibilty to double jump.
                this._canDoubleJump = false;

                //  Reset any previous jump/fall timers.
                this._airTime          = 0.0f;
                this._deadlyFall       = false;
                this._lastSafePosition = ConvertUnits.ToDisplayUnits(_mainBody.Position);

                //  Switch the animation and reset it incase the player
                //  is already jumping.
                this.PlayerState = PlayerState.Jumping;
                this.CurrentAnimation.ResetCurrentFrame();

                //  Apply the force
                this._wheelBody.FixtureList[0].Body.ApplyLinearImpulse(force);

                //  then create the steam plume.
                this.CreateSteamPlume();
                AudioManager.Instance.PlayCue("Harland_Jump_Steam", true);
            }
        }