Пример #1
0
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
}
Пример #2
0
func addBall() {
	x := rand.Intn(350-115) + 115
	ball := chipmunk.NewCircle(vect.Vector_Zero, float32(ballRadius))
	ball.SetElasticity(0.95)

	body := chipmunk.NewBody(vect.Float(ballMass), ball.Moment(float32(ballMass)))
	body.SetPosition(vect.Vect{vect.Float(x), 600.0})
	body.SetAngle(vect.Float(rand.Float32() * 2 * math.Pi))

	body.AddShape(ball)
	space.AddBody(body)
	balls = append(balls, ball)
}
Пример #3
0
func NewPhysics(static bool, space *chipmunk.Space) *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(), Space: space, Body: body, Box: box.GetAsBox(), Shape: box}
	body.AddShape(box)
	return p
}
Пример #4
0
func NewPhysicsShape(static bool, space *chipmunk.Space, shape *chipmunk.Shape) *Physics {

	var body *chipmunk.Body
	if static {
		body = chipmunk.NewBodyStatic()
		//s := chipmunk.NewBox(vect.Vect{-100, -10}, 200, 5)
		//body.AddShape(s)
		//p := &Physics{BaseComponent: NewComponent(), Space: space, Body: body, Box: s.GetAsBox(), Shape: s}
		//return p
	} else {
		body = chipmunk.NewBody(1, shape.ShapeClass.Moment(1))
	}

	body.AddShape(shape)
	p := &Physics{BaseComponent: NewComponent(), Space: space, Body: body, Box: shape.GetAsBox(), Shape: shape}
	return p
}
Пример #5
0
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
}