forked from vova616/GarageEngine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Mouse.go
41 lines (32 loc) · 862 Bytes
/
Mouse.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
37
38
39
40
41
package engine
import (
"github.com/vova616/chipmunk"
"github.com/vova616/chipmunk/vect"
)
type Mouse struct {
BaseComponent
}
func NewMouse() *Mouse {
return &Mouse{NewComponent()}
}
func (m *Mouse) OnComponentAdd() {
gameObject := m.GameObject()
gameObject.Tag = MouseTag
gameObject.AddComponent(NewPhysicsShape(false, chipmunk.NewCircle(vect.Vect{0, 0}, 0.5)))
ph := gameObject.Physics
ph.Body.SetMass(Inf)
ph.Body.SetMoment(Inf)
ph.Body.IgnoreGravity = true
ph.Shape.IsSensor = true
}
func (m *Mouse) Update() {
m.Transform().SetPosition(CurrentCamera().MouseLocalPosition())
}
func (m *Mouse) Start() {
}
func (m *Mouse) OnCollisionEnter(arbiter Arbiter) bool {
return onMouseEnterGameObject(arbiter.GameObjectB(), arbiter)
}
func (m *Mouse) OnCollisionExit(arbiter Arbiter) {
onMouseExitGameObject(arbiter.GameObjectB(), arbiter)
}