142 lines
2.4 KiB
Go
142 lines
2.4 KiB
Go
package main
|
|
|
|
import (
|
|
"surdeus.su/core/gg"
|
|
"surdeus.su/core/gg/ox"
|
|
//"surdeus.su/core/gg/mx"
|
|
"surdeus.su/core/gg/ax"
|
|
"github.com/hajimehoshi/ebiten/v2/examples/resources/images"
|
|
//_ "github.com/silbinarywolf/preferdiscretegpu"
|
|
"bytes"
|
|
"log"
|
|
"fmt"
|
|
)
|
|
|
|
type Context = gg.Context
|
|
|
|
const (
|
|
LayerHighest gg.Layer = -iota
|
|
|
|
LayerDebug
|
|
LayerTriangle
|
|
LayerPlayer
|
|
LayerRect
|
|
LayerBackground
|
|
|
|
LayerLowest
|
|
)
|
|
|
|
const (
|
|
TagPlayer gg.Tag = gg.TagLast + 1 + iota
|
|
TagConnectedToPlayer
|
|
TagTriangle
|
|
)
|
|
|
|
const (
|
|
Stand ax.AnimationID = iota
|
|
Walk
|
|
)
|
|
|
|
|
|
var (
|
|
playerAnimations ax.AnimationSet
|
|
playerImg *gg.Image
|
|
player *Player
|
|
rectMove ox.Rectangle
|
|
rect *Rect
|
|
tri *Tri
|
|
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
|
|
}
|
|
`))
|
|
)
|
|
|
|
func main() {
|
|
e := gg.NewEngine(gg.WindowConfig{
|
|
Title: "Test title",
|
|
Width: 720,
|
|
Height: 480,
|
|
VSync: true,
|
|
Fullscreen: false,
|
|
})
|
|
camera = NewCamera()
|
|
e.SetCamera(camera)
|
|
|
|
var err error
|
|
playerImg, err = gg.LoadImage(bytes.NewReader(images.Runner_png))
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
|
|
rect = NewRect()
|
|
|
|
playerAnimations, err = ax.AnimationSetFromImage(
|
|
playerImg,
|
|
8, 3,
|
|
10, 1,
|
|
ax.AD(Stand).DefRow(0, 0, 1, 2, 3, 4),
|
|
ax.AD(Walk).DefRow(1, 0, 1, 2, 3, 4, 5, 6, 7),
|
|
)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
player = NewPlayer()
|
|
tri = NewTri(ox.T())
|
|
|
|
|
|
/*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)
|
|
|
|
text, err := NewText()
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
e.Spawn(text)
|
|
|
|
//fmt.Println(rect.GetLayer(), player.GetLayer())
|
|
fmt.Println("Starting...")
|
|
objects := []gg.Object{
|
|
camera, &Debug{},
|
|
|
|
player, rect, tri,
|
|
NewGrid(), text,
|
|
}
|
|
for _, object := range objects {
|
|
e.Spawn(object)
|
|
}
|
|
err = e.Run()
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
}
|