func NewPhysicsShape(static bool, shape *chipmunk.Shape) *Physics { var body *chipmunk.Body if static { body = chipmunk.NewBodyStatic() } else { body = chipmunk.NewBody(1, shape.ShapeClass.Moment(1)) } p := &Physics{BaseComponent: NewComponent(), Body: body, Box: shape.GetAsBox(), Shape: shape} body.AddShape(shape) return p }
func NewPhysicsCircle(static bool) *Physics { var body *chipmunk.Body shape := chipmunk.NewCircle(vect.Vector_Zero, 1) if static { body = chipmunk.NewBodyStatic() } else { body = chipmunk.NewBody(1, shape.ShapeClass.Moment(1)) } p := &Physics{BaseComponent: NewComponent(), Body: body, Box: shape.GetAsBox(), Shape: shape} body.AddShape(shape) return p }
func NewPhysics(static bool) *Physics { var body *chipmunk.Body box := chipmunk.NewBox(vect.Vect{0, 0}, vect.Float(1), vect.Float(1)) if static { body = chipmunk.NewBodyStatic() } else { body = chipmunk.NewBody(1, box.Moment(1)) } p := &Physics{BaseComponent: NewComponent(), Body: body, Box: box.GetAsBox(), Shape: box} body.AddShape(box) return p }
func NewPhysicsShapes(static bool, shapes []*chipmunk.Shape) *Physics { var body *chipmunk.Body if static { body = chipmunk.NewBodyStatic() } else { moment := vect.Float(0) for _, shape := range shapes { moment += shape.Moment(1) } body = chipmunk.NewBody(1, moment) } p := &Physics{BaseComponent: NewComponent(), Body: body, Box: nil, Shape: nil} for _, shape := range shapes { body.AddShape(shape) } return p }