-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSceneMain.go
60 lines (53 loc) · 1.43 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
package main
import (
"fmt"
"game/components"
"game/engine"
rl "github.com/gen2brain/raylib-go/raylib"
"github.com/jakecoffman/cp"
)
type SceneMain struct {
engine.BaseScene
}
func (s *SceneMain) Init() {
s.EntityManager.CreateEntity("player",
&components.Health{},
&components.Transform{
Position: cp.Vector{X: 1280 / 2, Y: 720 / 2},
},
)
}
func (s *SceneMain) Render() {
s.ForEachEntity(func(e *engine.Entity) {
health, ok := e.GetComponent(components.HealthComponentID)
if ok {
health := health.(*components.Health)
rl.DrawText(fmt.Sprint("Health is ", health.HP), int32(s.VirtualWidth/2), int32(s.VirtualHeight/2), 20, rl.White)
}
})
rl.DrawText("This is the Main scene! or.. Is it?, \npress backsapce to go to the menu scene ", 300, 200, 30, rl.Green)
}
func (s *SceneMain) Update(virtualWidth float32, virtualHeight float32) {
s.UpdateBaseScene(virtualWidth, virtualHeight)
if rl.IsKeyPressed(rl.KeyBackspace) {
s.GoToNextScene()
}
entities := s.EntityManager.GetEntities()
for element := entities.Front(); element != nil; element = element.Next() {
// do something with element.Value
entity := element.Value.(*engine.Entity)
health, ok := entity.GetComponent(components.HealthComponentID)
if ok {
health := health.(*components.Health)
health.HP--
if health.HP <= 0 {
health.HP = 100
}
}
}
}
func (s *SceneMain) NextScene() string {
return "menu"
}
func (s *SceneMain) Unload() {
}