-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.go
71 lines (52 loc) · 1.62 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
package main
import (
"fmt"
goz "github.com/20tab/gozmo"
)
var cameraSpeed float32 = 5
type CameraMover struct{}
func (mover *CameraMover) Start(gameObject *goz.GameObject) {}
func (mover *CameraMover) Update(gameObject *goz.GameObject) {
var x float32 = 0
var y float32 = 0
if goz.IsTrue(gameObject.GetAttr("kbd", "A")) {
x = -cameraSpeed * gameObject.DeltaTime
}
if goz.IsTrue(gameObject.GetAttr("kbd", "D")) {
x = cameraSpeed * gameObject.DeltaTime
}
if goz.IsTrue(gameObject.GetAttr("kbd", "W")) {
y = cameraSpeed * gameObject.DeltaTime
}
if goz.IsTrue(gameObject.GetAttr("kbd", "S")) {
y = -cameraSpeed * gameObject.DeltaTime
}
gameObject.AddPosition(x, y)
}
type DrawCallsPrinter struct {
lastValue float64
}
func (dcp *DrawCallsPrinter) Start(gameObject *goz.GameObject) {}
func (dcp *DrawCallsPrinter) Update(gameObject *goz.GameObject) {
newValue := goz.GetPerFrameStats("GL.DrawCalls")
if newValue != dcp.lastValue {
fmt.Println("GL.DrawCalls =", newValue)
}
dcp.lastValue = newValue
}
func main() {
window := goz.OpenWindow(1024, 576, "Camera Scroll")
scene := goz.NewSceneFromFilename("assets/scene.json")
camera := scene.NewGameObject("Camera")
camera.AddComponent("camera", goz.NewCamera())
camera.AddComponent("kbd", goz.NewKeyboard())
camera.AddComponent("mover", &CameraMover{})
rightLimit := scene.FindGameObject("bg_4_0").Position[0]
camera.AddComponent("cage", goz.NewCage(0, 0, -20, rightLimit))
stats := scene.NewGameObject("Stats")
// Ensure stats are managed last.
stats.SetOrder(9999)
stats.AddComponent("stats", &DrawCallsPrinter{})
window.SetScene(scene)
window.Run()
}