package main import ( "vultras.su/core/gg" "github.com/hajimehoshi/ebiten/v2/examples/resources/images" "github.com/hajimehoshi/ebiten/v2/examples/resources/fonts" //_ "github.com/silbinarywolf/preferdiscretegpu" "bytes" "log" "fmt" ) type Context = gg.Context type Grid struct { gg.Sprite Cage, Width gg.Float } func (grid *Grid) Update(c *Context) { //d := c.IsPressed(gg.KeyShift) for _, ev := range c.Events { switch e := ev.(type){ case *gg.KeyDown : switch e.Key { case gg.Key9 : grid.Cage /= 10 grid.Width /= 5 case gg.Key0 : grid.Cage *= 10 grid.Width *= 5 }}} } func (grid *Grid) Draw(c *Context) []gg.EVertex { scale := c.Camera.Scale() pos := c.Camera.Position() grid.Uniforms["Zoom"] = gg.Float(scale.X) grid.Uniforms["PosX"] = pos.X grid.Uniforms["PosY"] = pos.Y grid.Uniforms["Cage"] = grid.Cage grid.Uniforms["Width"] = grid.Width return grid.Sprite.Draw(c) } const ( HighestL gg.Layer = -iota DebugL TriangleL PlayerL RectL BackgroundLayer LowestL ) const ( Stand gg.AnimationId = iota Walk ) var ( playerAnimations gg.AnimationSet playerImg *gg.Image player *Player rectMove gg.Rectangle rect *Rect tri *Tri ) func main() { e := gg.NewEngine(&gg.WindowConfig{ Title: "Test title", Width: 720, Height: 480, VSync: true, Fullscreen: false, }) var err error playerImg, err = gg.LoadImage(bytes.NewReader(images.Runner_png)) if err != nil { log.Fatal(err) } rect = NewRect() playerAnimations, _ = gg.AnimationSetFromImage( playerImg, 8, 3, 10, 1, gg.AD(Stand).DefRow(0, 0, 1, 2, 3, 4), gg.AD(Walk).DefRow(1, 0, 1, 2, 3, 4, 5, 6, 7), ) player = NewPlayer() tri = NewTri() e.Spawn(&Debug{}) e.Spawn(player) e.Spawn(rect) e.Spawn(tri) /*circle := &gg.Circle{} circle.Transform = gg.T() circle.Rotation = 300 circle.Color = gg.Rgba(1, 1, 1, 1) circle.Antialias = true circle.Layer = HighestL circle.Visible = true*/ //e.Spawn(circle) bgShader := gg.MustNewShader([]byte(` package main //kage:unit pixels //var cameraScaleX, cameraScaleY var Zoom float var PosX, PosY float var Cage float var Width float const ( ) func Fragment(dst vec4, src vec2, _ vec4) vec4 { c := imageSrc0UnsafeAt(src) dstSize := imageDstSize()/Zoom absDst := vec2( dst.x/Zoom - dstSize.x/2 - PosX, dst.y/Zoom - dstSize.y/2 - PosY, ) cx := c*step(Cage-Width, mod(absDst.x-Width/2, Cage)) cy := c*step(Cage-Width, mod(absDst.y-Width/2, Cage)) if cx.a == 0 { return cy } return cx } `)) grid := &Grid{} grid.Transform = gg.T() grid.SetAround(gg.V2(0)) grid.Layer = BackgroundLayer grid.Images[0] = gg.NewImage(720, 480) grid.Images[0].Fill(gg.Rgba(1, 1, 1, 1)) grid.Shader = bgShader grid.Uniforms = map[string] any{} //bg.Floating = true grid.Visible = true grid.Floating = true grid.Cage = 100 grid.Width = 5 e.Spawn(grid) txt := &Text{} txt.Transform = gg.T() //txt.Position = gg.V2(400) txt.Color = gg.Rgba(1, 1, 1, 1) txt.Layer = HighestL txt.Visible = true txt.Data = "Hello, World!\nПривет, Мир!" txt.Face, err = gg.MakeFaceFromTtf( bytes.NewReader(fonts.MPlus1pRegular_ttf), &gg.TtfFaceOptions{ Size: 32, DPI: 72, Hinting: gg.FontHintingNone, }, ) if err != nil { panic(err) } e.Spawn(txt) //fmt.Println(rect.GetLayer(), player.GetLayer()) fmt.Println("Starting...") err = e.Run() if err != nil { panic(err) } }