gg/cmd/test/trianlge.go

103 lines
1.5 KiB
Go
Raw Normal View History

2023-12-23 00:09:07 +03:00
package main
2024-05-19 21:11:58 +03:00
import "surdeus.su/core/gg"
2024-06-01 16:07:28 +03:00
import "surdeus.su/core/gg/ox"
import "surdeus.su/core/gg/mx"
//import "fmt"
2024-06-02 22:27:11 +03:00
import "log"
2024-01-08 07:12:35 +03:00
var (
counter int
)
2023-12-23 00:09:07 +03:00
2024-06-02 23:53:43 +03:00
2023-12-23 00:09:07 +03:00
type Tri struct {
2024-06-01 16:07:28 +03:00
ox.DrawablePolygon
Spawned bool
2023-12-23 00:09:07 +03:00
}
2024-06-02 22:27:11 +03:00
func NewTri(t *ox.Transform) *Tri {
2023-12-23 00:09:07 +03:00
ret := &Tri{}
2024-06-02 22:27:11 +03:00
ret.Transform = *t
2024-06-01 16:07:28 +03:00
ret.Triangles = mx.Triangles{
mx.Triangle{
mx.V(0, 10),
mx.V(100, 0),
mx.V(0, -10),
2023-12-23 00:09:07 +03:00
},
}
2024-06-01 16:07:28 +03:00
ret.Color = gg.RGBA(1, 1, 0, 1)
2023-12-23 00:09:07 +03:00
ret.Visible = true
2024-06-01 16:07:28 +03:00
ret.Layer = LayerTriangle
2023-12-23 00:09:07 +03:00
return ret
}
2024-06-02 23:53:43 +03:00
func (t *Tri) GetTags(c Context) gg.TagMap {
tags := gg.TagMap{
TagTriangle: struct{}{},
}
if t.IsConnected() {
tags[TagConnectedToPlayer] = struct{}{}
}
return tags
}
2024-06-02 22:27:11 +03:00
func (t *Tri) OnStart(c Context) {
log.Println("added a tri")
}
2024-05-19 21:11:58 +03:00
2024-06-02 22:27:11 +03:00
func (t *Tri) OnUpdate(c Context) {
2024-06-01 16:07:28 +03:00
e := c.Engine()
dt := e.DT().Seconds()
2024-06-01 16:07:28 +03:00
keys := e.GetKeyboardKeys()
d := +1.
2024-06-01 16:07:28 +03:00
if e.IsPressed(gg.KeyShift) {
2024-01-08 07:12:35 +03:00
d = -1
}
2024-01-08 07:12:35 +03:00
2024-05-19 21:11:58 +03:00
for _, key := range keys {
switch key {
2024-05-19 21:11:58 +03:00
case gg.KeyM:
2024-06-01 16:07:28 +03:00
t.Move(mx.VY(100 * dt * d))
2024-05-19 21:11:58 +03:00
case gg.KeyN:
2024-06-01 16:07:28 +03:00
t.Move(mx.VX(100 * dt * d))
2024-05-19 21:11:58 +03:00
case gg.KeyV:
2024-06-01 16:07:28 +03:00
t.Rotate(d * mx.Pi * 0.3 * dt)
2024-05-19 21:11:58 +03:00
case gg.Key2:
if t.Spawned {
break
}
case gg.Key3:
if t.Spawned {
break
}
tt := *t
tt.Spawned = true
tt.Disconnect()
if e.Spawn(&tt) {
2024-05-19 21:11:58 +03:00
counter++
}
2024-01-08 12:25:18 +03:00
}
2024-05-19 21:11:58 +03:00
}
2024-06-03 11:04:42 +03:00
for _, down := range c.Events().Keyboard.Downs {
2024-06-01 16:07:28 +03:00
switch down.Key {
case gg.Key1:
if t.IsConnected() {
t.Disconnect()
} else {
t.Connect(player)
}
2024-05-19 21:11:58 +03:00
}
}
}
2024-06-02 22:27:11 +03:00
func (tri *Tri) Draw(c Context) *gg.Drawing {
return tri.DrawablePolygon.Draw(c)
}