forked from EngoEngine/engo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hello.go
68 lines (54 loc) · 1.31 KB
/
hello.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
package main
import (
"image/color"
"log"
"engo.io/ecs"
"engo.io/engo"
"engo.io/engo/common"
)
type DefaultScene struct{}
type Guy struct {
ecs.BasicEntity
common.RenderComponent
common.SpaceComponent
}
func (*DefaultScene) Preload() {
engo.Files.Load("icon.png")
}
func (*DefaultScene) Setup(w *ecs.World) {
common.SetBackground(color.White)
w.AddSystem(&common.RenderSystem{})
// Retrieve a texture
texture, err := common.PreloadedSpriteSingle("icon.png")
if err != nil {
log.Println(err)
}
// Create an entity
guy := Guy{BasicEntity: ecs.NewBasic()}
// Initialize the components, set scale to 8x
guy.RenderComponent = common.RenderComponent{
Drawable: texture,
Scale: engo.Point{8, 8},
}
guy.SpaceComponent = common.SpaceComponent{
Position: engo.Point{0, 0},
Width: texture.Width() * guy.RenderComponent.Scale.X,
Height: texture.Height() * guy.RenderComponent.Scale.Y,
}
// Add it to appropriate systems
for _, system := range w.Systems() {
switch sys := system.(type) {
case *common.RenderSystem:
sys.Add(&guy.BasicEntity, &guy.RenderComponent, &guy.SpaceComponent)
}
}
}
func (*DefaultScene) Type() string { return "GameWorld" }
func main() {
opts := engo.RunOptions{
Title: "Hello World Demo",
Width: 1024,
Height: 640,
}
engo.Run(opts, &DefaultScene{})
}