Beispiel #1
0
 public PressureBody(Shape s, float mass, float gasPressure, float edgeSpringK, float edgeSpringDamp, float shapeSpringK, float shapeSpringDamp)
     : base(s, mass, edgeSpringK, edgeSpringDamp, shapeSpringK, shapeSpringDamp)
 {
     pressure = gasPressure;
     normal_list = new Vector2[count];
     edgelength_list = new float[count];
 }
Beispiel #2
0
        public Body(Shape shape, float mass)
        {
            this.base_shape = shape;
            this.curr_shape = shape.Clone();
            this.count = shape.count;

            this.pointmass_list = new PointMass[shape.count];
            for (int i = 0; i < shape.count; i++)
                pointmass_list[i] = new PointMass(shape.points[i], mass);

            this.bitmaskx = new Bitmask();
            this.bitmasky = new Bitmask();
        }
Beispiel #3
0
        public void BuildWall(Plane p)
        {
            ShapeBuilder shapebuilder = new ShapeBuilder(model);

            Matrix transform = GetTransform();
            Vector2[] points = shapebuilder.GetShape(ref transform, p);

            shape = new Shape(points, false);
            offset = shape.GetCenter() - new Vector2(position.X, position.Y);
            shape.CenterAtZero();

            body = new Body(shape, float.MaxValue);
            body.position.X = position.X + offset.X;
            body.position.Y = position.Y + offset.Y;
            body.is_static = true;
            body.Update(0);
        }
Beispiel #4
0
        public Enemy()
        {
            float scale = 0.5f;
            Vector2[] points = new Vector2[]
            {
                new Vector2(0,0),
                new Vector2(0,scale*0.5f),
                new Vector2(scale*0.5f,scale*0.5f),
                new Vector2(scale*0.5f,0),
            };

            shape = new Shape(points, true);

            body = new PressureBody(shape, 1, 1, 1300, 20, 1000, 20);

            max_speed = 2;
            radius = 2f;
        }
Beispiel #5
0
        public SpringBody(Shape shape, float mass, float edgeSpringK, float edgeSpringDamp, float shapeSpringK, float shapeSpringDamp)
            : base(shape, mass)
        {
            is_constrained = true;
            spring_list = new List<Spring>();
            spring_pointmass_list = new List<PointMass>();

            shape_k = shapeSpringK;
            shape_damping = shapeSpringDamp;
            edge_k = edgeSpringK;
            edge_damping = edgeSpringDamp;

            // build default springs.
            int i;
            for (i = 0; i < count - 1; i++)
                this.Add(new Spring(pointmass_list[i], pointmass_list[i + 1], edgeSpringK, edgeSpringDamp));
            this.Add(new Spring(pointmass_list[i], pointmass_list[0], edgeSpringK, edgeSpringDamp));
        }
Beispiel #6
0
        public Bubble(float scale)
        {
            this.scale = scale;
            this.curr_size = k.Length - 1;
            this.alpha = 1f;
            this.max_speed = 1.5f;

            List<Vector2> circle = new List<Vector2>();
            for (int i = 0; i < 360; i += 40)
                circle.Add(new Vector2((float)Math.Cos(MathHelper.ToRadians((float)-i)) * (scale + 0.005f), (float)Math.Sin(MathHelper.ToRadians((float)-i)) * (scale + 0.005f)));

            shape = new Shape(circle.ToArray(), true);
            body = new PressureBody(shape, 1, pressure[curr_size], k[curr_size], 20.0f, k[curr_size], 20.0f);

            vertices = circle;
            vertices.Add(Vector2.Zero);

            texture_coords = new List<Vector2>();
            for (int i = 0; i < circle.Count-1; i++)
            {
                Vector2 point = circle[i];
                if (point.X + point.Y != 0)
                {
                    point.Normalize();
                    point *= 1.025f;
                    point.X = (point.X + 1) * 0.5f;
                    point.Y = (point.Y + 1) * 0.5f;
                }

                texture_coords.Add(point);
            }
            texture_coords.Add(new Vector2(0.5f, 0.5f));

            SetSize(0);

            material = Resources.spriterenderer_material;
        }