示例#1
0
 // Currently broken.
 public LineItem(PhysicalScene scene, Vector2 start, float rotation, float length)
     : base(scene)
 {
     var end = start * length;
     end = Vector2.Transform(end, Matrix.CreateRotationZ(rotation));
     Body = BodyFactory.CreateEdge(scene.World, start, end);
 }
示例#2
0
        public CircleItem(PhysicalScene scene, float radius)
            : base(scene)
        {
            Body = BodyFactory.CreateCircle(scene.World, radius, 1f);

            Body.UserData = this;
        }
示例#3
0
        public static Obstacle CreateObstacle(PhysicalScene scene)
        {
            var obstacleTexture = BounceGame.ContentManager.Load<Texture2D>("obstacle");
            var o = new Obstacle(scene, obstacleTexture);

            return o;
        }
示例#4
0
文件: Paddle.cs 项目: zfogg/Bounce
        public Paddle(PhysicalScene scene, Texture2D texture)
            : base(scene)
        {
            this.Texture = texture;

            origin = new Vector2(Texture.Width / 2, Texture.Height / 2);
            DrawColor = Color.MidnightBlue;

            var unitCircle = new UnitCircle();

            //Body = BodyFactory.CreateRoundedRectangle(scene.World,
            //    ConvertUnits.ToSimUnits(texture.Width) * physicalScale.X, 0.35f,
            //    ConvertUnits.ToSimUnits(texture.Height) * physicalScale.Y, 0.15f,
            //    10, 1f);

            Body = BodyFactory.CreateSolidArc(scene.World,
                2f, (float)Math.PI / 2.6f, 24, 1.8f, Vector2.UnitY * 1.6f, (float)Math.PI);

            Body.BodyType = BodyType.Kinematic;
            Body.Restitution = 1f;
            Body.Friction = 0f;

            scene.Input.OnKeyHoldDown += new KeyboardEvent(onKeyHoldDown);
            Body.UserData = this;
        }
示例#5
0
        public static Obstacle CreateObstacle(PhysicalScene scene, Vector2 spawnPosition)
        {
            var o = CreateObstacle(scene);
            o.Body.Position = ConvertUnits.ToSimUnits(spawnPosition);

            return o;
        }
示例#6
0
        public static List<Obstacle> CreateRandomlyPositionedObstacles(PhysicalScene scene, Vector2 frameSize, int number)
        {
            var obstacleList = new List<Obstacle>();
            var rectangleList = new List<Rectangle>();
            Texture2D texture = BounceGame.ContentManager.Load<Texture2D>("obstacle");
            Vector2 spawnPositionOffset = new Vector2(texture.Width / 2, (texture.Height / 2) * 5f);

            for (int i = 0; i < number; i++)
            {
                Obstacle o = ItemFactory.CreateObstacle(scene,
                    VectorStructures.RandomPosition(frameSize, spawnPositionOffset));
                o.UpdatePosition();
                while (doesObstacleIntersect(o, rectangleList))
                {
                    o.Body.Position = ConvertUnits.ToSimUnits(
                        VectorStructures.RandomPosition(frameSize, spawnPositionOffset));
                    o.UpdatePosition();
                }

                obstacleList.Add(o);
                rectangleList.Add(o.Rectangle);
            }

            return obstacleList;
        }
示例#7
0
        public static Metroid CreateMetroid(PhysicalScene scene)
        {
            var texture = BounceGame.ContentManager.Load<Texture2D>("metroid");
            var m = new Metroid(scene, texture);

            return m;
        }
示例#8
0
        public static Metroid CreateMetroid(PhysicalScene scene, Vector2 spawnPosition)
        {
            var m = CreateMetroid(scene);
            m.Body.Position = ConvertUnits.ToSimUnits(spawnPosition);

            return m;
        }
示例#9
0
        public static Brick CreateBrick(PhysicalScene scene, Vector2 spawnPosition)
        {
            var b = CreateBrick(scene);
            b.Body.Position = ConvertUnits.ToSimUnits(spawnPosition);

            return b;
        }
示例#10
0
        public static List<RectangleItem> CreateFraming(PhysicalScene scene, Vector2 frameSize, int width)
        {
            var rectangles = new List<RectangleItem>();

            float x = frameSize.X;
            float y = frameSize.Y;

            //The following algorithm is absolutely ridiculous, and was written purely for fun.
            //That said, it works perfectly.
            for (float i = 0f; i <= x; i += x)
            {
                for (float j = 0f; j <= y; j += y)
                {
                    var newItem = ItemFactory.CreateRectangleItem(scene,
                        ConvertUnits.ToSimUnits(i == 0 ? (int)x : width),
                        ConvertUnits.ToSimUnits(i == 0 ? width : (int)y));

                    Vector2 position = new Vector2(
                        i == 0 ? x / 2 : (i + (j == 0 ? width / 2 : -i + (-width / 2))),
                        j == 0 ? (i == 0 ? -width / 2 : y / 2) : (i == 0 ? j + width / 2 : j / 2));

                    newItem.Body.Position = ConvertUnits.ToSimUnits(position);
                    newItem.Body.BodyType = BodyType.Static;
                    rectangles.Add(newItem);
                }
            }

            return rectangles;
        }
示例#11
0
        public static Paddle CreatePaddle(PhysicalScene scene, Vector2 spawnPosition)
        {
            var p = createPaddle(scene);
            p.Body.Position = ConvertUnits.ToSimUnits(spawnPosition);

            return p;
        }
示例#12
0
 public RectangleItem(PhysicalScene scene, float width, float height)
     : base(scene)
 {
     Body = BodyFactory.CreateRectangle(scene.World, width, height, 1f);
     Rectangle = new Rectangle(0, 0, (int)ConvertUnits.ToDisplayUnits(width), (int)ConvertUnits.ToDisplayUnits(height));
     Body.Restitution = 1f;
     Body.UserData = this;
 }
示例#13
0
        public static List<Brick> BrickRow(PhysicalScene scene, int numberOfBricks, Vector2 startingPosition, int pixelsApart)
        {
            var spawnPositions = VectorStructures.Row(numberOfBricks, startingPosition, pixelsApart);
            var brickList = new List<Brick>((int)numberOfBricks);

            foreach (Vector2 spawnPosition in spawnPositions)
                brickList.Add(ItemFactory.CreateBrick(scene, spawnPosition));

            return brickList;
        }
示例#14
0
        public static PaddleBall CreatePaddleBall(PhysicalScene scene, Paddle paddle)
        {
            var texture = BounceGame.ContentManager.Load<Texture2D>("dragonBall");
            var pb = new PaddleBall(scene, paddle, texture);

            pb.FixToPaddle(
                ConvertUnits.ToSimUnits(
                    Vector2.UnitY * pb.Texture.Height));

            return pb;
        }
示例#15
0
文件: Brick.cs 项目: zfogg/Bounce
        public Brick(PhysicalScene scene, Texture2D texture)
            : base(scene, ConvertUnits.ToSimUnits(texture.Width), ConvertUnits.ToSimUnits(texture.Height))
        {
            Body.BodyType = BodyType.Static;
            Body.Restitution = 1f;
            DrawColor = randomColor();
            this.Texture = texture;
            origin = new Vector2(Texture.Width / 2, Texture.Height / 2);

            scene.Input.OnMouseHover += new MouseEvent(onMouseHover);
            scene.Input.OnRightClickUp += new MouseEvent(onRightClickUp);
            Body.UserData = this;
        }
示例#16
0
        public PaddleBall(PhysicalScene scene, Paddle paddle, Texture2D texture)
            : base(scene, ConvertUnits.ToSimUnits(texture.Width / 2f))
        {
            this.paddle = paddle;
            this.Texture = texture;
            this.origin = new Vector2(Texture.Width / 2, Texture.Height / 2);

            Body.BodyType = BodyType.Dynamic;
            Body.IgnoreGravity = true;
            Body.Mass = 5f;
            Body.Restitution = 1.0725f;
            Body.Friction = 1f;

            scene.Input.OnKeyDown += new KeyboardEvent(onKeyDown);

            Body.OnCollision += new OnCollisionEventHandler(onCollision);
        }
示例#17
0
    void Awake()
    {
        scene = GetComponent <PhysicalScene>();
        scene.Load();

        if (scene.integratorType == "explicit-euler")
        {
            integrator = new ExplicitEulerIntegrator();
        }
        else if (scene.integratorType == "symplectic-euler")
        {
            integrator = new SymplecticEulerIntegrator();
        }
        else
        {
            Debug.Assert(false, "Can Not Find Any Suitable Integrator.");
        }
    }
示例#18
0
        public static List<Metroid> MetroidColumn(PhysicalScene scene, int numberOfMetroids, Vector2 startingPosition, int pixelsApart)
        {
            var spawnPositions = VectorStructures.Column(numberOfMetroids, startingPosition, pixelsApart);
            var metroidList = new List<Metroid>((int)numberOfMetroids);

            var unitCircle = new UnitCircle();
            int radiusIndex = 2;
            foreach (Vector2 spawnPosition in spawnPositions)
            {
                var m = ItemFactory.CreateMetroid(scene, spawnPosition);
                m.MotionRadius.X = (float)unitCircle.RadiansList.Values[radiusIndex];

                metroidList.Add(m);
                radiusIndex += 2;
            }

            return metroidList;
        }
示例#19
0
文件: Metroid.cs 项目: zfogg/Bounce
        public Metroid(PhysicalScene scene, Texture2D texture)
            : base(scene, ConvertUnits.ToSimUnits(texture.Width / 2))
        {
            this.Texture = texture;
            origin = new Vector2(Texture.Width / 2, Texture.Height / 2);

            unitCircle = new UnitCircle();

            Body.IgnoreGravity = true;

            Body.BodyType = BodyType.Dynamic;
            Body.Mass = 1f;
            Body.Friction = 0.25f;
            Body.Restitution = 0.75f;
            Body.AngularDamping = 0.075f;

            scene.Input.OnKeyDown += new KeyboardEvent(onKeyDown);
            scene.Input.OnMiddleClickDown += new MouseEvent(onMiddleClickDown);
            Body.UserData = this;
        }
示例#20
0
文件: Samus.cs 项目: zfogg/Bounce
        public Samus(PhysicalScene scene, Texture2D texture)
            : base(scene)
        {
            this.Texture = texture;

            Body = BodyFactory.CreateCompoundPolygon(
                scene.World, VectorStructures.TextureToBayazitList(Texture), 1f, true);
            origin = VectorStructures.TextureToVertices(Texture).GetCentroid(); //Need the centroid, not center, for a polygon body shape.

            Body.BodyType = BodyType.Dynamic;
            Body.FixedRotation = true; //This causes Body.Mass to reset.
            Body.Mass = 4.50f;
            Body.Friction = .475f;
            Body.Restitution = 0.55f;
            Body.AngularDamping = 0.50f;
            Body.LinearDamping = 0.25f;

            scene.Input.OnKeyDown += new KeyboardEvent(onKeyPressDown);
            scene.Input.OnKeyHoldDown += new KeyboardEvent(onKeyHoldDown);
            scene.Input.OnKeyUp += new KeyboardEvent(onKeyUp);
            Body.UserData = this;
        }
示例#21
0
文件: Obstacle.cs 项目: zfogg/Bounce
        public Obstacle(PhysicalScene scene, Texture2D texture)
            : base(scene, ConvertUnits.ToSimUnits(texture.Width), ConvertUnits.ToSimUnits(texture.Height))
        {
            this.Texture = texture;
            Body.BodyType = BodyType.Dynamic;
            Body.Mass = 1f;
            Body.Restitution = 0.1f * restitutionCoEf;
            Body.Friction = 0.1f * frictionCoEf;

            DrawColor = new Color(Vector4.UnitW);
            origin = new Vector2(Texture.Width / 2, Texture.Height / 2);

            scene.Input.OnKeyDown += new KeyboardEvent(onKeyDown);
            scene.Input.OnKeyUp += new KeyboardEvent(onKeyUp);
            scene.Input.OnLeftClickDown += new MouseEvent(onLeftClick);
            scene.Input.OnRightClickDown += new MouseEvent(onRightClick);
            scene.Input.OnMouseWheel += new MouseEvent(onMouseWheel);
            scene.Input.OnMouseHover += new MouseEvent(onMouseHover);
            Body.UserData = this;

            initializeJoints();
        }
示例#22
0
        public static List<Metroid> MetroidsNearItems(PhysicalScene scene, ICollection<PhysicalItem> items, Vector2 offsetFromItem, int percentChance)
        {
            var metroidList = new List<Metroid>();

            if (items != null)
            {
                foreach (PhysicalItem item in items)
                    if (BounceGame.r.Next(1, 101) < percentChance)
                    {
                        metroidList.Add(ItemFactory.CreateMetroid(scene, new Vector2(
                            ConvertUnits.ToDisplayUnits(item.Body.Position.X) + offsetFromItem.X,
                            ConvertUnits.ToDisplayUnits(item.Body.Position.Y) - offsetFromItem.Y)));
                    }
            }

            return metroidList;
        }
示例#23
0
 public static Samus CreateSamus(PhysicalScene scene)
 {
     var texture = BounceGame.ContentManager.Load<Texture2D>("samus");
     return new Samus(scene, texture);
 }
示例#24
0
 public static RectangleItem CreateRectangleItem(PhysicalScene scene, int width, int height)
 {
     return CreateRectangleItem(scene, (float)width, (float)height);
 }
示例#25
0
 public static RectangleItem CreateRectangleItem(PhysicalScene scene, float width, float height)
 {
     var r = new RectangleItem(scene, width, height);
     return r;
 }
示例#26
0
        public static Samus CreateSamus(PhysicalScene scene, Vector2 spawnPosition)
        {
            var s = CreateSamus(scene);
            s.Body.Position = spawnPosition;

            return s;
        }
示例#27
0
 private static Paddle createPaddle(PhysicalScene scene)
 {
     var texture = BounceGame.ContentManager.Load<Texture2D>("obstacle");
     return new Paddle(scene, texture);
 }
示例#28
0
 public static Brick CreateBrick(PhysicalScene scene)
 {
     var texture = BounceGame.ContentManager.Load<Texture2D>("brick");
     return new Brick(scene, texture);
 }
示例#29
0
    public void StepOneFrame(PhysicalScene scene)
    {
        m_DragDampingJob = new DragDampingJob
        {
            b        = scene.m_DragDamping,
            velocity = scene.m_Velocities,
            gradiant = scene.m_gradiants,
        };

        m_SpringForceJob = new SpringForceJob
        {
            position     = scene.m_Positions,
            velocity     = scene.m_Velocities,
            springForces = scene.springForces,
            edges        = scene.edgeIndexList,
            gradiant     = scene.m_gradiants,
        };

        m_GravitationalForceJob = new GravitationalForceJob
        {
            mass                = scene.m_masses,
            position            = scene.m_Positions,
            gradiant            = scene.m_gradiants,
            gravitationalforces = scene.gravitationalforces,
        };

        m_GravityGradiantJob = new SimpleGravityJob
        {
            gravity  = scene.m_Gravity,
            gradiant = scene.m_gradiants,
            mass     = scene.m_masses,
            fixes    = scene.m_fixes,
        };

        m_ExplicitEulerJob = new ExplicitEulerJob
        {
            deltaTime = scene.dt,
            velocity  = scene.m_Velocities,
            fixes     = scene.m_fixes,
            position  = scene.m_Positions,
            gradiant  = scene.m_gradiants,
            mass      = scene.m_masses,
        };

        m_UpdateJob = new UpdateJob
        {
            position = scene.m_Positions,
            gradiant = scene.m_gradiants,
        };

        m_PotentialEnergyJob = new PotentialEnergyJob
        {
            mass     = scene.m_masses,
            velocity = scene.m_Velocities,
            position = scene.m_Positions,
            gravity  = scene.m_Gravity,
        };

        float springEnergy = m_SpringForceJob.Execute();

        float gravitationalEnergy = m_GravitationalForceJob.Execute();

        scene.totalEnergy = m_PotentialEnergyJob.Execute(springEnergy, gravitationalEnergy);

        m_DragDampingJobHandle = m_DragDampingJob.Schedule(scene.objectCount, 64);

        m_GravityGradiantJobHandle = m_GravityGradiantJob.Schedule(scene.objectCount, 64, m_DragDampingJobHandle);

        m_ExplicitEulerJobHandle = m_ExplicitEulerJob.Schedule(scene.objectCount, 64, m_GravityGradiantJobHandle);

        m_UpdateJobHandle = m_UpdateJob.Schedule(scene.m_TransformsAccessArray, m_ExplicitEulerJobHandle);

        m_UpdateJobHandle.Complete();
    }
示例#30
0
 public RectangleItem(PhysicalScene scene, int width, int height)
     : this(scene, (float)width, (float)height)
 {
 }