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 = gg.T() ret.SetPosition(gg.V(-100, -100)) 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.Collidable = true ret.Type = gg.CollisionStaticPhysics ret.Layer = TriangleL //ret.Connect(player) return ret } func (t *Tri) Update(c *Context) { //redges := rect.Edges() //tedges := t.Edges() //crosses, ok := tedges.CrossWithEdges(redges) //fmt.Println("shit:", crosses, ok) if false { //fmt.Println("edges:", tedges) } col, hasCol := gg.Collide(t, rect) if hasCol && len(col.Crosses) > 0 { fmt.Println("col:", col) } dt := c.Dt().Seconds() if !t.ContainedPoints(gg.Points{c.AbsCursorPosition()}).Empty() { t.Color = gg.Rgba(0, 1, 0, 1) } else { t.Color = gg.Rgba(1, 0, 1, 1) } if t.Spawned { return } keys := c.Keys() d := +1. if c.IsPressed(gg.KeyShift) { d = -1 } for _, key := range keys { switch key { case gg.KeyM: t.Move(gg.Y(100*dt*d)) case gg.KeyN: t.Move(gg.X(100*dt*d)) case gg.KeyV: t.Rotate(d * gg.Pi * 0.3 * dt) 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 : if t.Spawned { break } tt := *t tt.Spawned = true tt.Disconnect() if c.Spawn(&tt) == nil { counter++ } }} 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) } }}} }