2023-12-23 00:09:07 +03:00
|
|
|
package main
|
|
|
|
|
2024-01-05 04:22:53 +03:00
|
|
|
import "vultras.su/core/gg"
|
2023-12-28 02:31:43 +03:00
|
|
|
import "fmt"
|
2023-12-23 00:09:07 +03:00
|
|
|
|
|
|
|
type Tri struct {
|
2023-12-26 23:31:04 +03:00
|
|
|
gg.DrawablePolygon
|
2023-12-23 00:09:07 +03:00
|
|
|
gg.Layer
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewTri() *Tri {
|
|
|
|
ret := &Tri{}
|
2023-12-24 15:05:34 +03:00
|
|
|
ret.Transform.Scale = gg.V2(1)
|
2023-12-23 00:09:07 +03:00
|
|
|
|
|
|
|
ret.Triangles = gg.Triangles{
|
|
|
|
gg.Triangle{
|
2023-12-27 01:35:50 +03:00
|
|
|
gg.V(0, 10),
|
|
|
|
gg.V(100, 0),
|
|
|
|
gg.V(0, -10),
|
2023-12-23 00:09:07 +03:00
|
|
|
},
|
|
|
|
}
|
2023-12-28 02:31:43 +03:00
|
|
|
ret.Color = gg.Rgba(1, 1, 0, 1)
|
2023-12-23 00:09:07 +03:00
|
|
|
ret.Visible = true
|
|
|
|
ret.Layer = TriangleL
|
2023-12-28 14:34:52 +03:00
|
|
|
ret.Connect(player)
|
2023-12-23 00:09:07 +03:00
|
|
|
|
|
|
|
return ret
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *Tri) Update(c *Context) {
|
|
|
|
if t.ContainsPoint(c.AbsCursorPosition()) {
|
|
|
|
t.Color = gg.Rgba(0, 1, 0, 1)
|
|
|
|
} else {
|
|
|
|
t.Color = gg.Rgba(1, 0, 1, 1)
|
|
|
|
}
|
2023-12-26 23:31:04 +03:00
|
|
|
|
|
|
|
d := +1.
|
|
|
|
if c.IsPressed(gg.KeyShift) {
|
|
|
|
d = -1.
|
|
|
|
}
|
|
|
|
if c.IsPressed(gg.KeyM) {
|
|
|
|
absPos := tri.AbsPosition()
|
|
|
|
tri.SetAbsPosition(
|
2024-01-04 17:05:51 +03:00
|
|
|
absPos.Add(gg.V(0, 100*c.DT()*d)),
|
2023-12-26 23:31:04 +03:00
|
|
|
)
|
|
|
|
}
|
|
|
|
if c.IsPressed(gg.KeyN) {
|
|
|
|
absPos := tri.AbsPosition()
|
|
|
|
tri.SetAbsPosition(
|
2024-01-04 17:05:51 +03:00
|
|
|
absPos.Add(gg.V(100*c.DT()*d, 0)),
|
2023-12-26 23:31:04 +03:00
|
|
|
)
|
|
|
|
}
|
2023-12-23 00:09:07 +03:00
|
|
|
}
|
2023-12-28 02:31:43 +03:00
|
|
|
|
|
|
|
func (t *Tri) Event(c *Context) {
|
|
|
|
switch e := c.Event.(type) {
|
2024-01-04 17:05:51 +03:00
|
|
|
case *gg.KeyDown:
|
2023-12-28 02:31:43 +03:00
|
|
|
if e.Key != gg.Key1 {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
if t.Connected() {
|
|
|
|
fmt.Println("disconnecting:", tri.Transform)
|
|
|
|
t.Disconnect()
|
|
|
|
} else {
|
|
|
|
t.Connect(player)
|
|
|
|
fmt.Println("connecting:", tri.Transform)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|