-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
75 lines (62 loc) · 1.44 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package main
import (
"log"
"github.com/kharism/hanashi/core"
"github.com/hajimehoshi/ebiten/v2"
"github.com/hajimehoshi/ebiten/v2/ebitenutil"
)
type Game struct {
Scene *core.Scene
}
func (g *Game) Update() error {
g.Scene.Update()
return nil
}
func (g *Game) Draw(screen *ebiten.Image) {
g.Scene.Draw(screen)
}
func (g *Game) Layout(width, height int) (int, int) {
return 768, 512
}
// return width and height of the scene
func (g *Game) GetLayout() (width, height int) {
return 768, 512
}
// return the starting text position where the box containing name of the character appear on the scene
// return negative number if no such box needed
func (g *Game) GetNamePosition() (x, y int) {
return 0, 512 - 100
}
// get the starting position of the text
func (g *Game) GetTextPosition() (x, y int) {
return 0, 512 - 70
}
type ImagePool struct {
Map map[string]*ebiten.Image
}
func (m *ImagePool) GetImage(key string) (*ebiten.Image, error) {
if _, ok := m.Map[key]; ok {
return m.Map[key], nil
}
img, _, err := ebitenutil.NewImageFromFile(key)
if err != nil {
return nil, err
}
m.Map[key] = img
return img, nil
}
var (
imgPool ImagePool
)
func main() {
ebiten.SetWindowSize(640, 480)
ebiten.SetWindowTitle("Hello, World!")
imgPool = ImagePool{Map: map[string]*ebiten.Image{}}
game := &Game{}
scene := Scene1(game)
// scene.SetLayouter(game)
game.Scene = scene
if err := ebiten.RunGame(game); err != nil {
log.Fatal(err)
}
}