gg/cmd/test/trianlge.go

114 lines
2 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-01 22:01:17 +03:00
//import "log"
2024-01-08 07:12:35 +03:00
var (
counter int
)
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
}
func NewTri() *Tri {
ret := &Tri{}
2024-06-01 16:07:28 +03:00
ret.Transform = ox.T()
ret.SetPosition(mx.V2(-100))
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
//ret.Collidable = true
2024-06-01 16:07:28 +03:00
//ret.Type = gg.CollisionStaticPhysics
ret.Layer = LayerTriangle
//ret.Connect(player)
2023-12-23 00:09:07 +03:00
return ret
}
2024-06-01 16:07:28 +03:00
func (t *Tri) OnUpdate(c Context) {
2024-06-01 22:01:17 +03:00
//log.Println("onup:", t.IsVisible())
//redges := rect.Edges()
//tedges := t.Edges()
//crosses, ok := tedges.CrossWithEdges(redges)
//fmt.Println("shit:", crosses, ok)
2024-05-19 21:11:58 +03:00
if false {
//fmt.Println("edges:", tedges)
}
2024-06-01 16:07:28 +03:00
/*col, hasCol := gg.Collide(t, rect)
if hasCol && len(col.Crosses) > 0 {
fmt.Println("col:", col)
2024-06-01 16:07:28 +03:00
}*/
e := c.Engine()
dt := e.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)
2024-06-01 16:07:28 +03:00
}*/
if t.Spawned {
return
}
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
}
2024-06-01 16:07:28 +03:00
/*t.Triangles = append(t.Triangles, gg.Triangle{
gg.V(0, 10+ mx.Float(counter)),
gg.V(100+ mx.Float(counter), 0),
2024-05-19 21:11:58 +03:00
gg.V(0, -10-gg.Float(counter)),
2024-06-01 16:07:28 +03:00
})*/
2024-05-19 21:11:58 +03:00
case gg.Key3:
if t.Spawned {
break
}
tt := *t
tt.Spawned = true
tt.Disconnect()
2024-06-01 16:07:28 +03:00
if e.Spawn(&tt) == nil {
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-01 16:07:28 +03:00
for _, down := range c.Events().Keyboard.KeyDowns {
switch down.Key {
case gg.Key1:
if t.IsConnected() {
t.Disconnect()
} else {
t.Connect(player)
}
2024-05-19 21:11:58 +03:00
}
}
}