-
Notifications
You must be signed in to change notification settings - Fork 0
/
SceneMain.go
62 lines (55 loc) · 1.54 KB
/
SceneMain.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
package main
import (
"game/components"
"game/engine"
"game/resources"
"game/systems"
rl "github.com/gen2brain/raylib-go/raylib"
)
type SceneMain struct {
engine.BaseScene
*resources.AssetManager
}
func (s *SceneMain) Init() {
s.LoadAssets()
_, plrDest := s.AssetManager.GetTexture("cloud")
s.EntityManager.CreateEntity("player",
components.NewSprite().WithDest(plrDest),
components.NewInput(),
components.NewPlayer(0.3, 5, 0.3),
components.NewTransform().
WithPositionX(float64(plrDest.X)).
WithPostionY(float64(plrDest.Y)),
)
}
func (s *SceneMain) Render() {
tex, dest := s.AssetManager.GetTexture("backdrop")
s.DrawTexture(tex, dest, rl.White)
tex, dest = s.AssetManager.GetTexture("container")
s.DrawTextureRotateCenter(tex, dest, 0, rl.RayWhite)
tex, _ = s.AssetManager.GetTexture("cloud")
e := s.EntityManager.GetFirstEntityWithTag("player")
comp, _ := e.GetComponent(components.SpriteComponentId)
sprite := comp.(*components.Sprite)
s.DrawTextureRotateCenter(tex, sprite.Dest, 0, rl.ColorAlpha(rl.White, 1.0))
}
func (s *SceneMain) Update(virtualWidth float32, virtualHeight float32) {
s.UpdateBaseScene(virtualWidth, virtualHeight)
s.ForEachEntity(
func(e *engine.Entity) {
systems.InputSystem(e)
systems.MovementSystem(e)
systems.UpdateSpriteSystem(e)
},
)
}
func (s *SceneMain) NextScene() string {
return "menu"
}
func (s *SceneMain) Unload() {
s.AssetManager.Unload()
}
func (s *SceneMain) LoadAssets() {
configPath := "TextureConfigSceneMain.json"
s.AssetManager = resources.NewAssetManager(configPath)
}