コード例 #1
0
        public Entity(Texture2D tex, Rectangle bounds, World world, Body body = null, float density = 10.0f)
            : base(tex)
        {
            entityWorld = world;
            if (body == null)
            {
                entityBody = BodyFactory.CreateCircle(world,
                                                      WorldConversions.ConvertFromPixels(tex.Width / 2), density);
            }
            else
            {
                entityBody = body;
            }
            // Set the Entity instance as userdata so we can reference it later
            // e.g. in collisions
            Body.UserData             = this;
            entityBody.BodyType       = BodyType.Dynamic;
            entityBody.AngularDamping = 0.1f;
            float mass = entityBody.Mass;

            MaxAngularVelocity = 2.0f;
            LevelBounds        = bounds;
            TorqueForce        = 30.0f;
            Damage             = 0f;
        }
コード例 #2
0
        public virtual bool UpdateEntity(GameTime time)
        {
            base.Position = WorldConversions.ConvertFromWorld(entityBody.Position);
            base.Rotation = entityBody.Rotation;

            // Reset the velocity damping
            if (Velocity < MaxLinearVelocity)
            {
                Body.LinearDamping = 0;
            }

            return(true);
        }
コード例 #3
0
ファイル: Ship.cs プロジェクト: codesmith-fi/smithngine
        /// <summary>
        /// Deaccelerate the ship
        /// </summary>
        /// <param name="amount">1.0 is maximun engine thrust, 0.0 is minimum</param>
        /// <returns>false if max speed limit achieved</returns>
        public virtual bool Deaccelerate(float amount = 1.0f)
        {
            amount = MathHelper.Clamp(amount, -1.0f, 1.0f);
            bool result = false;

            if (FrontThruster != null)
            {
                result = Thrust(FrontThruster, amount);
                if (FrontThruster.Effect != null)
                {
                    Vector2 posLocal = Body.GetWorldPoint(
                        new Vector2(0, -WorldConversions.ConvertFromPixels(Texture.Height / 2)));
                    FrontThruster.Effect.Position = WorldConversions.ConvertFromWorld(posLocal);
                    FrontThruster.Effect.Rotation = Rotation;
                    if (amount != 0)
                    {
                        FrontThruster.Effect.Generate(10);
                    }
                }
            }
            return(result);
        }