gg/cmd/test/main.go

135 lines
2.3 KiB
Go
Raw Normal View History

2023-02-17 07:04:29 +03:00
package main
import (
2024-05-19 21:11:58 +03:00
"surdeus.su/core/gg"
2024-05-28 11:24:12 +03:00
"surdeus.su/core/gg/ox"
2024-06-01 16:07:28 +03:00
//"surdeus.su/core/gg/mx"
"surdeus.su/core/gg/ax"
2023-02-17 23:51:40 +03:00
"github.com/hajimehoshi/ebiten/v2/examples/resources/images"
//_ "github.com/silbinarywolf/preferdiscretegpu"
2023-02-17 23:51:40 +03:00
"bytes"
"log"
2023-05-26 18:31:04 +03:00
"fmt"
2023-02-17 07:04:29 +03:00
)
type Context = gg.Context
2024-06-01 16:07:28 +03:00
const (
LayerHighest gg.Layer = -iota
2024-01-24 19:14:07 +03:00
2024-06-01 16:07:28 +03:00
LayerDebug
LayerTriangle
LayerPlayer
LayerRect
LayerBackground
2024-01-24 19:14:07 +03:00
2024-06-01 16:07:28 +03:00
LayerLowest
)
const (
2024-06-01 16:07:28 +03:00
Stand ax.AnimationID = iota
Walk
)
2024-06-01 16:07:28 +03:00
2023-02-17 23:51:40 +03:00
var (
2024-06-01 16:07:28 +03:00
playerAnimations ax.AnimationSet
2024-05-19 21:11:58 +03:00
playerImg *gg.Image
player *Player
2024-06-01 16:07:28 +03:00
rectMove ox.Rectangle
2024-05-19 21:11:58 +03:00
rect *Rect
tri *Tri
2024-06-01 16:07:28 +03:00
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
}
`))
2023-02-17 23:51:40 +03:00
)
2023-02-17 07:04:29 +03:00
func main() {
2024-06-01 16:07:28 +03:00
e := gg.NewEngine(gg.WindowConfig{
2024-05-19 21:11:58 +03:00
Title: "Test title",
Width: 720,
Height: 480,
VSync: true,
Fullscreen: false,
2023-02-17 07:04:29 +03:00
})
2024-06-01 22:01:17 +03:00
camera = NewCamera()
2024-06-01 16:07:28 +03:00
e.SetCamera(camera)
e.Spawn(camera)
2023-02-17 07:04:29 +03:00
2023-02-17 23:51:40 +03:00
var err error
2023-10-23 15:45:18 +03:00
playerImg, err = gg.LoadImage(bytes.NewReader(images.Runner_png))
2023-02-17 23:51:40 +03:00
if err != nil {
log.Fatal(err)
}
2023-05-30 14:34:10 +03:00
rect = NewRect()
2024-06-01 22:01:17 +03:00
playerAnimations, err = ax.AnimationSetFromImage(
playerImg,
8, 3,
10, 1,
2024-06-01 16:07:28 +03:00
ax.AD(Stand).DefRow(0, 0, 1, 2, 3, 4),
ax.AD(Walk).DefRow(1, 0, 1, 2, 3, 4, 5, 6, 7),
)
2024-06-01 22:01:17 +03:00
if err != nil {
panic(err)
}
player = NewPlayer()
2023-06-20 14:04:55 +03:00
tri = NewTri()
2023-10-23 15:45:18 +03:00
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*/
2024-01-13 18:17:34 +03:00
//e.Spawn(circle)
2024-06-01 16:07:28 +03:00
e.Spawn(NewGrid())
2024-01-24 19:14:07 +03:00
2024-06-01 16:07:28 +03:00
text, err := NewText()
2024-01-13 18:17:34 +03:00
if err != nil {
panic(err)
}
2024-06-01 16:07:28 +03:00
e.Spawn(text)
2023-10-23 15:45:18 +03:00
2024-01-13 18:17:34 +03:00
//fmt.Println(rect.GetLayer(), player.GetLayer())
fmt.Println("Starting...")
2023-12-25 23:41:12 +03:00
err = e.Run()
if err != nil {
panic(err)
}
2023-02-17 07:04:29 +03:00
}