gg/cmd/test/trianlge.go

97 lines
1.5 KiB
Go
Raw Normal View History

2023-12-23 00:09:07 +03:00
package main
2024-01-05 04:22:53 +03:00
import "vultras.su/core/gg"
2024-01-08 07:12:35 +03:00
//import "fmt"
var (
counter int
)
2023-12-23 00:09:07 +03:00
type Tri struct {
gg.DrawablePolygon
Spawned bool
2023-12-23 00:09:07 +03:00
}
func NewTri() *Tri {
ret := &Tri{}
ret.Transform = gg.T()
2023-12-23 00:09:07 +03:00
ret.Triangles = gg.Triangles{
gg.Triangle{
gg.V(0, 10),
gg.V(100, 0),
gg.V(0, -10),
2023-12-23 00:09:07 +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) {
dt := c.Dt().Seconds()
if !t.ContainedPoints(gg.Points{c.AbsCursorPosition()}).Empty() {
2023-12-23 00:09:07 +03:00
t.Color = gg.Rgba(0, 1, 0, 1)
} else {
t.Color = gg.Rgba(1, 0, 1, 1)
}
if t.Spawned {
return
}
2024-01-08 07:12:35 +03:00
keys := c.Keys()
d := +1.
if c.IsPressed(gg.KeyShift) {
2024-01-08 07:12:35 +03:00
d = -1
}
2024-01-08 07:12:35 +03:00
for _, key := range keys { switch key {
case gg.KeyM:
absPos := t.Position()
t.SetPosition(
absPos.Add(gg.V(0, 100*dt*d)),
)
2024-01-08 07:12:35 +03:00
case gg.KeyN:
absPos := t.Position()
t.SetPosition(
absPos.Add(gg.V(100*dt*d, 0)),
)
2024-01-08 07:12:35 +03:00
case gg.KeyV:
t.Rotate(d * gg.Pi * 0.3 * dt)
2024-01-08 07:12:35 +03:00
case gg.Key2 :
if t.Spawned {
break
}
t.Triangles = append(t.Triangles, gg.Triangle{
gg.V(0, 10 + gg.Float(counter)),
gg.V(100 + gg.Float(counter), 0),
gg.V(0, -10 - gg.Float(counter)),
})
case gg.Key3 :
2024-01-08 07:12:35 +03:00
if t.Spawned {
break
}
tt := *t
tt.Spawned = true
tt.Disconnect()
2024-01-08 12:25:18 +03:00
if c.Spawn(&tt) == nil {
counter++
}
2024-01-08 07:12:35 +03:00
}}
2024-01-08 07:12:35 +03:00
for _, event := range c.Events {
switch e := event.(type) { case *gg.KeyDown:
switch e.Key {
case gg.Key1 :
if t.Connected() {
t.Disconnect()
} else {
t.Connect(player)
}
2024-01-08 07:12:35 +03:00
}}}
}
2024-01-08 07:12:35 +03:00