Skip to content
This repository has been archived by the owner on May 31, 2024. It is now read-only.

Commit

Permalink
still working
Browse files Browse the repository at this point in the history
  • Loading branch information
GaryBrownEEngr committed Dec 1, 2023
1 parent a064744 commit 4a43424
Showing 1 changed file with 15 additions and 32 deletions.
47 changes: 15 additions & 32 deletions examples/marblemachine/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ type object struct {
physicsShape *cp.Shape
}

/*
A Body appears to be what has mass, momentum
A Shape is what touches other things, and is attached to a body.
A shape seems to usually be made out of segments.
A segment seems to be a wide line with rounded ends.
*/

func simStartFunc(sim models.Scratch) {
oList := []*object{}

Expand All @@ -33,12 +41,12 @@ func simStartFunc(sim models.Scratch) {

container := space.AddBody(cp.NewKinematicBody())
container.SetAngularVelocity(0.4)
container.SetPosition(cp.Vector{0, 0})
container.SetPosition(cp.Vector{X: 0, Y: 0})

a := cp.Vector{-200, -200}
b := cp.Vector{-200, 200}
c := cp.Vector{200, 200}
d := cp.Vector{200, -200}
a := cp.Vector{X: -200, Y: -200}
b := cp.Vector{X: -200, Y: 200}
c := cp.Vector{X: 200, Y: 200}
d := cp.Vector{X: 200, Y: -200}

AddWall(space, container, a, b, 1)
AddWall(space, container, b, c, 1)
Expand All @@ -55,7 +63,8 @@ func simStartFunc(sim models.Scratch) {

typ := rand.Intn(3)
if typ == 0 {
// AddBox(space, pos, mass, width, height)
a := AddBox(sim, space, pos, mass, width, height)
oList = append(oList, a)
} else if typ == 1 {
// AddSegment(space, pos, mass, width, height)
} else {
Expand Down Expand Up @@ -103,32 +112,6 @@ func createRectangleImage(width, height float64, c color.Color) image.Image {
return dc.Image()
}

// func createContainer(sim models.Scratch, space *cp.Space) []*object {
// container := space.AddBody(cp.NewKinematicBody())
// container.SetAngularVelocity(0.4)
// container.SetPosition(cp.Vector{X: 0, Y: 0})

// container
// shape := space.AddShape(circle.Shape)

// a := cp.Vector{X: -200, Y: -200}
// b := cp.Vector{X: -200, Y: 200}
// c := cp.Vector{X: 200, Y: 200}
// d := cp.Vector{X: 200, Y: -200}

// AddWall(space, container, a, b, 1)
// AddWall(space, container, b, c, 1)
// AddWall(space, container, c, d, 1)
// AddWall(space, container, d, a, 1)

// ret := &object{
// sprite: sprite,
// physicsShape: shape,
// }

// return ret
// }

func AddWall(space *cp.Space, body *cp.Body, a, b cp.Vector, radius float64) {
// swap so we always draw the same direction horizontally
if a.X < b.X {
Expand Down

0 comments on commit 4a43424

Please sign in to comment.