package main import "surdeus.su/core/gg" import "surdeus.su/core/gg/ox" import "surdeus.su/core/gg/mx" //import "fmt" //import "log" var ( counter int ) type Tri struct { ox.DrawablePolygon Spawned bool } func NewTri() *Tri { ret := &Tri{} 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), }, } ret.Color = gg.RGBA(1, 1, 0, 1) ret.Visible = true //ret.Collidable = true //ret.Type = gg.CollisionStaticPhysics ret.Layer = LayerTriangle //ret.Connect(player) return ret } func (t *Tri) OnUpdate(c Context) { //log.Println("onup:", t.IsVisible()) //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) }*/ e := c.Engine() dt := e.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 := e.GetKeyboardKeys() d := +1. if e.IsPressed(gg.KeyShift) { d = -1 } for _, key := range keys { switch key { case gg.KeyM: t.Move(mx.VY(100 * dt * d)) case gg.KeyN: t.Move(mx.VX(100 * dt * d)) case gg.KeyV: t.Rotate(d * mx.Pi * 0.3 * dt) case gg.Key2: if t.Spawned { break } /*t.Triangles = append(t.Triangles, gg.Triangle{ gg.V(0, 10+ mx.Float(counter)), gg.V(100+ mx.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 e.Spawn(&tt) == nil { counter++ } } } for _, down := range c.Events().Keyboard.KeyDowns { switch down.Key { case gg.Key1: if t.IsConnected() { t.Disconnect() } else { t.Connect(player) } } } }