/// <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);
            }
        }
        /// <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;
        }
Exemple #3
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;
        }
        /// <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);
            }
        }
        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
        }
Exemple #6
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;
            }
        }