Beispiel #1
0
// createBodies sets up the chipmunk space and static bodies
func createBodies() {
	space = chipmunk.NewSpace()
	space.Gravity = vect.Vect{0, 2900}

	staticBody := chipmunk.NewBodyStatic()
	staticLines = []*chipmunk.Shape{
		chipmunk.NewSegment(vect.Vect{100.0, 500.0}, vect.Vect{1000.0, 500.0}, 0),
		chipmunk.NewSegment(vect.Vect{1000.0, 500.0}, vect.Vect{1000.0, 100.0}, 0),
	}
	for _, segment := range staticLines {
		segment.SetElasticity(0.9)
		staticBody.AddShape(segment)
	}
	space.AddBody(staticBody)
}
Beispiel #2
0
func NewRace(track *Track) *Race {
	id, _ := uuid.NewV4()
	race := &Race{id.String(), track, make([]*PlayerPosition, 0), chipmunk.NewSpace(), false, 0}
	staticBody := chipmunk.NewBodyStatic()
	for _, wall := range track.Segments {
		segment := chipmunk.NewSegment(wall.Point1, wall.Point2, 0)
		staticBody.AddShape(segment)
	}
	race.Space.AddBody(staticBody)
	return race
}