package ox import ( "github.com/hajimehoshi/ebiten/v2" //"fmt" ) import "surdeus.su/core/gg/mx" import "surdeus.su/core/gg" var _ = gg.Drawer(&Sprite{}) type Sprite struct { Transform Drawity } var ( //spritesOp DrawImageOptions ) func (s *Sprite) Draw(c gg.Context) *gg.Drawing { // Nothing to draw. if s.Images[0] == nil { return nil } t := s.GetRectangleToDraw().Transform m := t.GetMatrice() if !s.IsFloating() { m.Concat(c.Camera().GetRealMatrice(c)) } // Drawing without shader. if s.Shader == nil { c.Image().DrawImage(s.Images[0], &ebiten.DrawImageOptions{ GeoM: m, }) return nil } w, h := s.Images[0].Size() // Drawing with shader. c.Image().DrawRectShader( w, h, s.Shader, &ebiten.DrawRectShaderOptions{ Images: s.Images, Uniforms: s.Uniforms, GeoM: m, }, ) return nil } // Return the rectangle that contains the sprite to draw. func (s *Sprite) GetRectangleToDraw() Rectangle { if s.Images[0] == nil { return Rectangle{} } w, h := s.Images[0].Size() t := s.Transform t.SetAround( t.GetAround().Mul( mx.Vector{mx.Float(w), mx.Float(h)}, ), ) return Rectangle{ Transform: t, } } // Return the rectangle that contains // the sprite in the engine. func (s *Sprite) GetRectangle() Rectangle { if s.Images[0] == nil { return Rectangle{ Transform: s.Transform, } } w, h := s.Images[0].Size() t := s.Transform return Rectangle{ Transform: t, Width: mx.Float(w), Height: mx.Float(h), } } // Get triangles of the rectangle that contains the sprite // and has the same widght and height. func (s *Sprite) MakeTriangles() mx.Triangles { return s.GetRectangle().MakeTriangles() } func (s *Sprite) Vertices() mx.Vectors { return s.GetRectangle().Vertices() } func (s *Sprite) Edges() mx.Lines { return s.GetRectangle().Edges() } func (s *Sprite) ContainsPoint( pt mx.Vector, ) bool { return s.GetRectangle().ContainsPoint(pt) } func (s *Sprite) GetContainedPoints( pts mx.Vectors, ) mx.Vectors { return s.GetRectangle().GetContainedPoints(pts) }