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"
|
2023-02-17 23:51:40 +03:00
|
|
|
|
"github.com/hajimehoshi/ebiten/v2/examples/resources/images"
|
2024-01-13 18:17:34 +03:00
|
|
|
|
"github.com/hajimehoshi/ebiten/v2/examples/resources/fonts"
|
2024-01-16 07:37:53 +03:00
|
|
|
|
//_ "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
|
|
|
|
)
|
|
|
|
|
|
2023-12-20 22:39:33 +03:00
|
|
|
|
type Context = gg.Context
|
|
|
|
|
|
2024-01-24 19:14:07 +03:00
|
|
|
|
type Grid struct {
|
2024-05-28 11:24:12 +03:00
|
|
|
|
ox.Sprite
|
2024-01-24 19:14:07 +03:00
|
|
|
|
Cage, Width gg.Float
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-28 11:24:12 +03:00
|
|
|
|
func (grid *Grid) OnUpdate(c *Context) {
|
2024-01-24 19:14:07 +03:00
|
|
|
|
//d := c.IsPressed(gg.KeyShift)
|
2024-05-19 21:11:58 +03:00
|
|
|
|
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
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-01-24 19:14:07 +03:00
|
|
|
|
}
|
|
|
|
|
|
2024-05-28 11:24:12 +03:00
|
|
|
|
func (grid *Grid) OnDraw(c *Context) []gg.EVertex {
|
2024-01-24 19:14:07 +03:00
|
|
|
|
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)
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-31 11:29:37 +03:00
|
|
|
|
const (
|
2023-10-23 15:45:18 +03:00
|
|
|
|
HighestL gg.Layer = -iota
|
2023-08-31 11:29:37 +03:00
|
|
|
|
DebugL
|
|
|
|
|
TriangleL
|
|
|
|
|
PlayerL
|
|
|
|
|
RectL
|
2024-01-24 19:14:07 +03:00
|
|
|
|
BackgroundLayer
|
2023-08-31 11:29:37 +03:00
|
|
|
|
LowestL
|
|
|
|
|
)
|
|
|
|
|
|
2024-01-13 23:46:12 +03:00
|
|
|
|
const (
|
|
|
|
|
Stand gg.AnimationId = iota
|
|
|
|
|
Walk
|
|
|
|
|
)
|
|
|
|
|
|
2023-02-17 23:51:40 +03:00
|
|
|
|
var (
|
2024-01-13 23:46:12 +03:00
|
|
|
|
playerAnimations gg.AnimationSet
|
2024-05-19 21:11:58 +03:00
|
|
|
|
playerImg *gg.Image
|
|
|
|
|
player *Player
|
|
|
|
|
rectMove gg.Rectangle
|
|
|
|
|
rect *Rect
|
|
|
|
|
tri *Tri
|
2023-02-17 23:51:40 +03:00
|
|
|
|
)
|
|
|
|
|
|
2023-02-17 07:04:29 +03:00
|
|
|
|
func main() {
|
2023-10-23 15:45:18 +03:00
|
|
|
|
e := gg.NewEngine(&gg.WindowConfig{
|
2024-05-19 21:11:58 +03:00
|
|
|
|
Title: "Test title",
|
|
|
|
|
Width: 720,
|
|
|
|
|
Height: 480,
|
|
|
|
|
VSync: true,
|
2024-01-21 16:34:23 +03:00
|
|
|
|
Fullscreen: false,
|
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-01-13 23:46:12 +03:00
|
|
|
|
|
|
|
|
|
playerAnimations, _ = gg.AnimationSetFromImage(
|
|
|
|
|
playerImg,
|
|
|
|
|
8, 3,
|
2024-01-16 07:49:56 +03:00
|
|
|
|
10, 1,
|
2024-01-14 00:03:49 +03:00
|
|
|
|
gg.AD(Stand).DefRow(0, 0, 1, 2, 3, 4),
|
|
|
|
|
gg.AD(Walk).DefRow(1, 0, 1, 2, 3, 4, 5, 6, 7),
|
2024-01-13 23:46:12 +03:00
|
|
|
|
)
|
2023-12-26 23:31:04 +03:00
|
|
|
|
player = NewPlayer()
|
2023-06-20 14:04:55 +03:00
|
|
|
|
tri = NewTri()
|
2023-10-23 15:45:18 +03:00
|
|
|
|
|
2024-01-08 06:09:36 +03:00
|
|
|
|
e.Spawn(&Debug{})
|
|
|
|
|
e.Spawn(player)
|
|
|
|
|
e.Spawn(rect)
|
|
|
|
|
e.Spawn(tri)
|
2024-01-11 07:05:27 +03:00
|
|
|
|
|
2024-01-21 13:35:40 +03:00
|
|
|
|
/*circle := &gg.Circle{}
|
2024-01-11 07:05:27 +03:00
|
|
|
|
circle.Transform = gg.T()
|
|
|
|
|
circle.Rotation = 300
|
|
|
|
|
circle.Color = gg.Rgba(1, 1, 1, 1)
|
|
|
|
|
circle.Antialias = true
|
|
|
|
|
circle.Layer = HighestL
|
2024-01-21 13:35:40 +03:00
|
|
|
|
circle.Visible = true*/
|
2024-01-13 18:17:34 +03:00
|
|
|
|
//e.Spawn(circle)
|
2024-01-11 07:05:27 +03:00
|
|
|
|
|
2024-01-24 19:14:07 +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
|
|
|
|
|
}
|
|
|
|
|
`))
|
|
|
|
|
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
|
2024-05-19 21:11:58 +03:00
|
|
|
|
grid.Uniforms = map[string]any{}
|
2024-01-24 19:14:07 +03:00
|
|
|
|
//bg.Floating = true
|
|
|
|
|
grid.Visible = true
|
|
|
|
|
grid.Floating = true
|
|
|
|
|
grid.Cage = 100
|
|
|
|
|
grid.Width = 5
|
|
|
|
|
e.Spawn(grid)
|
|
|
|
|
|
2024-01-14 03:51:11 +03:00
|
|
|
|
txt := &Text{}
|
2024-01-13 18:17:34 +03:00
|
|
|
|
txt.Transform = gg.T()
|
|
|
|
|
//txt.Position = gg.V2(400)
|
|
|
|
|
txt.Color = gg.Rgba(1, 1, 1, 1)
|
|
|
|
|
txt.Layer = HighestL
|
|
|
|
|
txt.Visible = true
|
2024-01-14 03:51:11 +03:00
|
|
|
|
txt.Data = "Hello, World!\nПривет, Мир!"
|
2024-01-13 18:17:34 +03:00
|
|
|
|
txt.Face, err = gg.MakeFaceFromTtf(
|
|
|
|
|
bytes.NewReader(fonts.MPlus1pRegular_ttf),
|
|
|
|
|
&gg.TtfFaceOptions{
|
2024-05-19 21:11:58 +03:00
|
|
|
|
Size: 32,
|
|
|
|
|
DPI: 72,
|
2024-01-13 18:17:34 +03:00
|
|
|
|
Hinting: gg.FontHintingNone,
|
|
|
|
|
},
|
|
|
|
|
)
|
|
|
|
|
if err != nil {
|
|
|
|
|
panic(err)
|
|
|
|
|
}
|
|
|
|
|
e.Spawn(txt)
|
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
|
|
|
|
}
|