gg/cmd/test/main.go

106 lines
1.8 KiB
Go
Raw Normal View History

2023-02-17 07:04:29 +03:00
package main
import (
2024-01-05 04:22:53 +03:00
"vultras.su/core/gg"
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"
//_ "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
const (
2023-10-23 15:45:18 +03:00
HighestL gg.Layer = -iota
DebugL
TriangleL
PlayerL
RectL
LowestL
)
const (
Stand gg.AnimationId = iota
Walk
)
2023-02-17 23:51:40 +03:00
var (
playerAnimations gg.AnimationSet
2023-10-23 15:45:18 +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{
Title: "Test title",
Width: 720,
Height: 480,
2023-10-23 15:45:18 +03:00
VSync: true,
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()
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()
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)
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
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{
Size: 32,
DPI: 72,
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
}