-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodel.go
50 lines (40 loc) · 970 Bytes
/
model.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
package main
import (
"fmt"
"github.com/hajimehoshi/ebiten/v2"
"github.com/hajimehoshi/ebiten/v2/ebitenutil"
)
type ActionType string
const (
ActionTypeIdle ActionType = "idle"
ActionTypeSleep ActionType = "sleep"
ActionTypeWalkingLeft ActionType = "walking_left"
ActionTypeWalkingRight ActionType = "walking_right"
)
type Action struct {
Type ActionType
Images []ebiten.Image
}
type ActionSource struct {
ImagePaths []string
}
func (src ActionSource) ToAction(actType ActionType) (*Action, error) {
images := make([]ebiten.Image, 0, len(src.ImagePaths))
for _, imgPath := range src.ImagePaths {
img, _, err := ebitenutil.NewImageFromFile(imgPath)
if err != nil {
return nil, fmt.Errorf("unable to load image due: %v", err)
}
images = append(images, *img)
}
return &Action{Type: actType, Images: images}, nil
}
type Point struct {
X int
Y int
}
type Dimension struct {
Width int
Height int
}
const walkSpeed = 4