Skip to content

Commit

Permalink
Merge pull request #85 from oakmound/release/2.2.0
Browse files Browse the repository at this point in the history
Release/2.2.0
  • Loading branch information
200sc committed Mar 23, 2019
2 parents 60bdd36 + ef2afe5 commit 393793f
Show file tree
Hide file tree
Showing 19 changed files with 195 additions and 79 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Expand Up @@ -12,3 +12,7 @@

# Project-local glide cache, RE: https://github.com/Masterminds/glide/issues/736
.glide/

# As a library we can't commit our vendor directory if it ever accidentally kept
# around after updating dependencies
vendor/*
54 changes: 31 additions & 23 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 1 addition & 10 deletions Gopkg.toml
Expand Up @@ -24,11 +24,6 @@
# go-tests = true
# unused-packages = true


[[constraint]]
branch = "master"
name = "github.com/200sc/go-dist"

[[constraint]]
name = "github.com/200sc/klangsynthese"
version = "0.1.1"
Expand All @@ -53,13 +48,9 @@
branch = "master"
name = "github.com/golang/freetype"

[[constraint]]
branch = "master"
name = "github.com/oakmound/lowrez17"

[[constraint]]
name = "github.com/oakmound/shiny"
version = "0.1.0"
version = "0.2.0"

[[constraint]]
name = "github.com/stretchr/testify"
Expand Down
6 changes: 6 additions & 0 deletions collision/rtree.go
Expand Up @@ -22,6 +22,11 @@ type Rtree struct {
height int
}

// Size returns the rtree's size
func (tree *Rtree) Size() int {
return tree.size
}

// NewTree creates a new R-tree instance.
func newTree(MinChildren, MaxChildren int) *Rtree {
rt := Rtree{MinChildren: MinChildren, MaxChildren: MaxChildren}
Expand Down Expand Up @@ -307,6 +312,7 @@ func (tree *Rtree) Delete(obj *Space) bool {
for i, e := range n.entries {
if e.obj == obj {
ind = i
break
}
}
if ind < 0 {
Expand Down
25 changes: 16 additions & 9 deletions collision/tree.go
Expand Up @@ -83,15 +83,16 @@ func (t *Tree) Remove(sps ...*Space) int {
return removed
}

// UpdateLabel will set the input space's label in this tree. Modifying a
// space's label without going through a tree's method such as this will
// have no effect.
// UpdateLabel will set the input space's label. DEPRECATED. Just set
// the Label field on the Space pointer.
func (t *Tree) UpdateLabel(classtype Label, s *Space) {
t.Remove(s)
s.Label = classtype
t.Add(s)
}

// ErrNotExist is returned by methods on spaces
// when the space to update or act on did not exist
var ErrNotExist = errors.New("Space did not exist to update")

// UpdateSpace resets a space's location to a given
// rtreego.Rect.
// This is not an operation on a space because
Expand All @@ -102,7 +103,11 @@ func (t *Tree) UpdateSpace(x, y, w, h float64, s *Space) error {
}
loc := NewRect(x, y, w, h)
t.Lock()
t.Delete(s)
deleted := t.Delete(s)
if !deleted {
t.Unlock()
return ErrNotExist
}
s.Location = loc
t.Insert(s)
t.Unlock()
Expand All @@ -116,7 +121,11 @@ func (t *Tree) UpdateSpaceRect(rect floatgeom.Rect3, s *Space) error {
return oakerr.NilInput{InputName: "s"}
}
t.Lock()
t.Delete(s)
deleted := t.Delete(s)
if !deleted {
t.Unlock()
return ErrNotExist
}
s.Location = rect
t.Insert(s)
t.Unlock()
Expand All @@ -138,8 +147,6 @@ func (t *Tree) ShiftSpace(x, y float64, s *Space) error {
// themselves, if they exist in the tree, but self-collision
// will not be reported by Hits.
func (t *Tree) Hits(sp *Space) []*Space {
// Eventually we'll expose SearchIntersect for use cases where you
// want to see if you intersect yourself
results := t.SearchIntersect(sp.Bounds())
hitSelf := -1
i := 0
Expand Down
5 changes: 5 additions & 0 deletions entities/reactive.go
Expand Up @@ -66,6 +66,11 @@ func (r *Reactive) GetSpace() *collision.Space {
return r.RSpace.Space
}

// GetReactiveSpace returns this reactive's RSpace
func (r *Reactive) GetReactiveSpace() *collision.ReactiveSpace {
return r.RSpace
}

// Overwrites

// Init satisfies event.Entity
Expand Down
8 changes: 5 additions & 3 deletions entities/x/btn/textBox.go
Expand Up @@ -35,9 +35,11 @@ func NewTextBox(cid event.CID, x, y, w, h, txtX, txtY float64,
b.Text = f.NewStrText("Init", 0, 0)
b.Text.Vector = b.Text.Attach(b.Box.Vector, txtX, (-txtY)+b.H)

// Add one to the layer so that the text shows up above the box itself
layers[len(layers)-1]++
render.Draw(b.Text, layers...)
// We dont want to modify the input's layers but we do want the text to show up on top of the base renderable.
txtLayers := make([]int, len(layers))
copy(txtLayers, layers)
txtLayers[len(txtLayers)-1]++
render.Draw(b.Text, txtLayers...)
return b
}

Expand Down
9 changes: 4 additions & 5 deletions entities/x/force/hurtBox.go
Expand Up @@ -4,7 +4,6 @@ import (
"image/color"
"time"

"github.com/oakmound/lowrez17/game/layers"
"github.com/oakmound/oak/collision"
"github.com/oakmound/oak/physics"
"github.com/oakmound/oak/render"
Expand All @@ -28,20 +27,20 @@ func NewHurtBox(x, y, w, h float64, duration time.Duration, l collision.Label, f

// NewHurtColor creates a temporary collision space with a given force it should
// apply to objects it collides with. The box is rendered as the given color
func NewHurtColor(x, y, w, h float64, duration time.Duration, l collision.Label, fv physics.ForceVector, c color.Color) {
func NewHurtColor(x, y, w, h float64, duration time.Duration, l collision.Label, fv physics.ForceVector, c color.Color, layers ...int) {
cb := render.NewColorBox(int(w), int(h), c)
NewHurtDisplay(x, y, w, h, duration, l, fv, cb)
NewHurtDisplay(x, y, w, h, duration, l, fv, cb, layers...)
}

// NewHurtDisplay creates a temporary collision space with a given force it should
// apply to objects it collides with. The box is rendered as the given renderable.
// The input renderable is not copied before it is drawn.
func NewHurtDisplay(x, y, w, h float64, duration time.Duration, l collision.Label, fv physics.ForceVector, r render.Renderable) {
func NewHurtDisplay(x, y, w, h float64, duration time.Duration, l collision.Label, fv physics.ForceVector, r render.Renderable, layers ...int) {
hb := new(hurtBox)
hb.DirectionSpace = NewDirectionSpace(collision.NewLabeledSpace(x, y, w, h, l), fv)
collision.Add(hb.Space)
r.SetPos(x, y)
render.Draw(r, layers.DebugLayer)
render.Draw(r, layers...)
go timing.DoAfter(duration, func() {
collision.Remove(hb.Space)
r.Undraw()
Expand Down
21 changes: 21 additions & 0 deletions entities/x/move/shift.go
@@ -0,0 +1,21 @@
package move

// ShiftX will ShiftX on the vector of the mover and
// set the renderable and space positions to that of the updated vector.
func ShiftX(mvr Mover, x float64) {
vec := mvr.Vec()
vec.ShiftX(x)
mvr.GetRenderable().SetPos(vec.X(), vec.Y())
sp := mvr.GetSpace()
sp.Update(vec.X(), vec.Y(), sp.GetW(), sp.GetH())
}

// ShiftY will ShiftY on the vector of the mover and
// set the renderable and space positions to that of the updated vector.
func ShiftY(mvr Mover, y float64) {
vec := mvr.Vec()
vec.ShiftY(y)
mvr.GetRenderable().SetPos(vec.X(), vec.Y())
sp := mvr.GetSpace()
sp.Update(vec.X(), vec.Y(), sp.GetW(), sp.GetH())
}
7 changes: 4 additions & 3 deletions entities/x/move/topdown.go
Expand Up @@ -38,7 +38,8 @@ func TopDown(mvr Mover, up, down, left, right string) {
}
vec.Add(delta)
mvr.GetRenderable().SetPos(vec.X(), vec.Y())
mvr.GetSpace().Update(vec.X(), vec.Y(), 16, 16)
sp := mvr.GetSpace()
sp.Update(vec.X(), vec.Y(), sp.GetW(), sp.GetH())
}

// CenterScreenOn will cause the screen to center on the given mover, obeying
Expand All @@ -58,12 +59,12 @@ func Limit(mvr Mover, rect floatgeom.Rect2) {
wf := float64(w)
hf := float64(h)
if vec.X() < rect.Min.X() {
vec.SetX(0)
vec.SetX(rect.Min.X())
} else if vec.X() > rect.Max.X()-wf {
vec.SetX(rect.Max.X() - wf)
}
if vec.Y() < rect.Min.Y() {
vec.SetY(0)
vec.SetY(rect.Min.Y())
} else if vec.Y() > rect.Max.Y()-hf {
vec.SetY(rect.Max.Y() - hf)
}
Expand Down

0 comments on commit 393793f

Please sign in to comment.