-
Notifications
You must be signed in to change notification settings - Fork 0
/
hurtBox.go
36 lines (32 loc) · 902 Bytes
/
hurtBox.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package forceSpace
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"
"github.com/oakmound/oak/timing"
)
type HurtBox struct {
*DirectionSpace
}
func NewHurtBox(x, y, w, h float64, duration time.Duration, l collision.Label, fv physics.ForceVector, debug ...bool) {
hb := new(HurtBox)
hb.DirectionSpace = NewDirectionSpace(collision.NewLabeledSpace(x, y, w, h, l), fv)
collision.Add(hb.Space)
// Debug renderable to see the hurtbox
if len(debug) == 0 {
cb := render.NewColorBox(int(w), int(h), color.RGBA{100, 100, 100, 100})
cb.SetPos(x, y)
render.Draw(cb, layers.DebugLayer)
go timing.DoAfter(duration, func() {
collision.Remove(hb.Space)
cb.UnDraw()
})
} else {
go timing.DoAfter(duration, func() {
collision.Remove(hb.Space)
})
}
}