Skip to content

Commit

Permalink
Fixing up examples to use pointer to the Space.
Browse files Browse the repository at this point in the history
Fixing up AddShape() to just panic.
  • Loading branch information
SolarLune committed Jan 14, 2019
1 parent 34d1d4c commit 36d3513
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 16 deletions.
4 changes: 3 additions & 1 deletion main.go
Expand Up @@ -14,7 +14,7 @@ var screenWidth int32 = 320
var screenHeight int32 = 240
var cell int32 = 4

var space resolv.Space
var space *resolv.Space
var renderer *sdl.Renderer
var window *sdl.Window
var avgFramerate int
Expand Down Expand Up @@ -43,6 +43,8 @@ func main() {

// Change this to one of the other World structs to change the world and see different tests

space = resolv.NewSpace()

var world WorldInterface = &World1{}

world.Create()
Expand Down
3 changes: 1 addition & 2 deletions resolv/space.go
Expand Up @@ -20,8 +20,7 @@ func NewSpace() *Space {
func (sp *Space) AddShape(shapes ...Shape) {
for _, shape := range shapes {
if shape == sp {
fmt.Println("ERROR! Space ", shape, " cannot add itself!")
panic("")
panic(fmt.Sprintf("ERROR! Space %s cannot add itself!", shape))
}
*sp = append(*sp, shape)
}
Expand Down
4 changes: 2 additions & 2 deletions world1.go
Expand Up @@ -78,7 +78,7 @@ func (w *World1) Create() {
space.AddShape(resolv.NewRectangle(cell+(x*cell), cell+(y*cell), cell*(1+rand.Int31n(16)), cell*(1+rand.Int31n(16))))
}

for _, shape := range space {
for _, shape := range *space {
shape.SetTags("solid")
}

Expand Down Expand Up @@ -159,7 +159,7 @@ func (w *World1) Update() {

func (w World1) Draw() {

for _, shape := range space {
for _, shape := range *space {

// Living on the edge~~~
// We know that this Space just has Rectangles, so we'll just assume they are
Expand Down
4 changes: 2 additions & 2 deletions world2.go
Expand Up @@ -17,7 +17,7 @@ func (w World2) Create() {
space.AddShape(resolv.NewRectangle(screenWidth-cell, cell, cell, screenHeight-cell))
space.AddShape(resolv.NewRectangle(cell, screenHeight-cell, screenWidth-(cell*2), cell))

for _, shape := range space {
for _, shape := range *space {
shape.SetTags("solid")
}

Expand Down Expand Up @@ -111,7 +111,7 @@ func (w World2) Draw() {

touching := "You aren't touching a zone"

for _, shape := range space {
for _, shape := range *space {

renderer.SetDrawColor(255, 255, 255, 255)

Expand Down
4 changes: 2 additions & 2 deletions world3.go
Expand Up @@ -24,7 +24,7 @@ func (w World3) Create() {
space.AddShape(resolv.NewRectangle(cell, screenHeight-cell, screenWidth-(cell*2), cell))
space.AddShape(resolv.NewCircle(30, 60, cell))

for _, shape := range space {
for _, shape := range *space {
shape.SetTags("solid")
}

Expand Down Expand Up @@ -86,7 +86,7 @@ func (world World3) Draw() {

touching := "Not touching a zone"

for _, shape := range space {
for _, shape := range *space {

renderer.SetDrawColor(255, 255, 255, 255)

Expand Down
4 changes: 3 additions & 1 deletion world5.go
Expand Up @@ -40,6 +40,8 @@ func (w *World5) Create() {
line = resolv.NewLine(lx, ly+ls, lx, ly)
space.AddShape(line)

space.AddShape(space)

}

func (w *World5) Update() {
Expand All @@ -66,7 +68,7 @@ func (w *World5) Update() {

func (w *World5) Draw() {

for _, shape := range space {
for _, shape := range *space {

line, ok := shape.(*resolv.Line)

Expand Down
4 changes: 2 additions & 2 deletions world6.go
Expand Up @@ -36,7 +36,7 @@ func (w *World6) Create() {

space.AddShape(resolv.NewRectangle(c*4, screenHeight-c*4, c*3, c))

for _, shape := range space {
for _, shape := range *space {
shape.SetTags("solid")
}

Expand Down Expand Up @@ -164,7 +164,7 @@ func (w *World6) Update() {

func (w *World6) Draw() {

for _, shape := range space {
for _, shape := range *space {

rect, ok := shape.(*resolv.Rectangle)

Expand Down
6 changes: 2 additions & 4 deletions world7.go
Expand Up @@ -36,7 +36,7 @@ func (w *World7) Create() {
space.AddShape(resolv.NewRectangle(0, 0, screenWidth, 16))
space.AddShape(resolv.NewRectangle(0, screenHeight-16, screenWidth, 16))

for _, shape := range space {
for _, shape := range *space {
shape.SetTags("solid")
}

Expand Down Expand Up @@ -234,9 +234,7 @@ func DrawObject(shape resolv.Shape) {

func (w *World7) Draw() {

shapes := space[:]

for _, shape := range shapes {
for _, shape := range *space {
DrawObject(shape)
}

Expand Down

0 comments on commit 36d3513

Please sign in to comment.