package main import "vultras.su/core/gg" //import "fmt" var ( counter int ) type Tri struct { gg.DrawablePolygon Spawned bool } func NewTri() *Tri { ret := &Tri{} ret.Transform.Scale = gg.V2(1) ret.Triangles = gg.Triangles{ gg.Triangle{ gg.V(0, 10), gg.V(100, 0), gg.V(0, -10), }, } ret.Color = gg.Rgba(1, 1, 0, 1) ret.Visible = true ret.Layer = TriangleL ret.Connect(player) return ret } func (t *Tri) Update(c *Context) { if t.Spawned { return } dt := c.DT() if t.ContainsPoint(c.AbsCursorPosition()) { t.Color = gg.Rgba(0, 1, 0, 1) } else { t.Color = gg.Rgba(1, 0, 1, 1) } keys := c.Keys() d := +1. if c.IsPressed(gg.KeyShift) { d = -1 } for _, key := range keys { switch key { case gg.KeyM: absPos := t.AbsPosition() t.SetAbsPosition( absPos.Add(gg.V(0, 100*c.DT()*d)), ) case gg.KeyN: absPos := t.AbsPosition() t.SetAbsPosition( absPos.Add(gg.V(100*c.DT()*d, 0)), ) case gg.KeyV: t.Rotation += d * gg.Pi * 0.3 * dt case gg.Key2 : if t.Spawned { break } counter++ tt := *t tt.Spawned = true tt.Disconnect() c.Spawn(&tt) }} 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) } }}} }