-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscene_choose.go
153 lines (125 loc) · 3.83 KB
/
scene_choose.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
package main
import (
"fmt"
"os"
"rapidengine/geometry"
"rapidengine/ui"
)
var b1Text *ui.TextBox
var b2Text *ui.TextBox
var b3Text *ui.TextBox
func InitializeChooseScene() {
ChooseScene = Engine.SceneControl.NewScene("choose")
chooseText := Engine.TextControl.NewTextBox("Choose World", "pixel", (1920 / 2), 600, 3, [3]float32{255, 255, 255})
chooseText.X -= float32(chooseText.GetLength() / 2)
ChooseScene.InstanceText(chooseText)
rect1 := Engine.ChildControl.NewChild2D()
rect1.AttachMesh(geometry.NewRectangle())
rect1.ScaleX = 800
rect1.ScaleY = 75
rect1.SetPosition((1920/2)-400, 400)
rect2 := Engine.ChildControl.NewChild2D()
rect2.AttachMesh(geometry.NewRectangle())
rect2.ScaleX = 800
rect2.ScaleY = 75
rect2.SetPosition((1920/2)-400, 300)
rect3 := Engine.ChildControl.NewChild2D()
rect3.AttachMesh(geometry.NewRectangle())
rect3.ScaleX = 800
rect3.ScaleY = 75
rect3.SetPosition((1920/2)-400, 200)
b1Text = Engine.TextControl.NewTextBox("Play", "pixel", (1920/2)+300, 600, 1, [3]float32{255, 255, 255})
b2Text = Engine.TextControl.NewTextBox("Play", "pixel", (1920/2)+300, 600, 1, [3]float32{255, 255, 255})
b3Text = Engine.TextControl.NewTextBox("Play", "pixel", (1920/2)+300, 600, 1, [3]float32{255, 255, 255})
c1Text := Engine.TextControl.NewTextBox("Save 1", "pixel", (1920/2)-300, 425+12.5, 1, [3]float32{255, 255, 255})
c2Text := Engine.TextControl.NewTextBox("Save 2", "pixel", (1920/2)-300, 325+12.5, 1, [3]float32{255, 255, 255})
c3Text := Engine.TextControl.NewTextBox("Save 3", "pixel", (1920/2)-300, 225+12.5, 1, [3]float32{255, 255, 255})
ChooseScene.InstanceText(c1Text)
ChooseScene.InstanceText(c2Text)
ChooseScene.InstanceText(c3Text)
b1 := Engine.UIControl.NewUIButton((1920/2)+300, 425, 75, 25)
b1.SetClickCallback(choose1)
b1.AttachText(b1Text)
b2 := Engine.UIControl.NewUIButton((1920/2)+300, 325, 75, 25)
b2.SetClickCallback(choose2)
b2.AttachText(b2Text)
b3 := Engine.UIControl.NewUIButton((1920/2)+300, 225, 75, 25)
b3.SetClickCallback(choose3)
b3.AttachText(b3Text)
Engine.UIControl.InstanceElement(b1, ChooseScene)
Engine.UIControl.InstanceElement(b2, ChooseScene)
Engine.UIControl.InstanceElement(b3, ChooseScene)
ChooseScene.InstanceChild(SkyChild)
ChooseScene.InstanceChild(SunChild)
ChooseScene.InstanceChild(Back4Child)
ChooseScene.InstanceChild(Back3Child)
ChooseScene.InstanceChild(Back2Child)
ChooseScene.InstanceChild(Back1Child)
ChooseScene.InstanceChild(rect1)
ChooseScene.InstanceChild(rect2)
ChooseScene.InstanceChild(rect3)
}
func updateChooseScene() {
if doesWorldExist(1) {
b1Text.Text = "Play"
} else {
b1Text.Text = "New"
}
if doesWorldExist(2) {
b2Text.Text = "Play"
} else {
b2Text.Text = "New"
}
if doesWorldExist(3) {
b3Text.Text = "Play"
} else {
b3Text.Text = "New"
}
}
func choose1() {
CurrentWorld = 1
if b1Text.Text == "Play" {
loadWorld()
} else {
newWorld()
}
}
func choose2() {
CurrentWorld = 2
if b2Text.Text == "Play" {
loadWorld()
} else {
newWorld()
}
}
func choose3() {
CurrentWorld = 3
/*if b3Text.Text == "Play" {
loadWorld()
} else {
newWorld()
}*/
initializeWorldTree()
generateTestWorldTree()
}
func loadWorld() {
ProgressText.Text = "Loading world..."
ProgressBar.SetPercentage(0)
Engine.SceneControl.SetCurrentScene(LoadingScene)
updateLoadingScreen()
initializeWorldTree()
WorldMap.LoadFromFile("./worlds/world" + fmt.Sprint(CurrentWorld) + ".hln")
Player1.PlayerChild.SetPosition(float32(WorldWidth*BlockSize/2), float32((HeightMap[WorldWidth/2]+25)*BlockSize))
Engine.SceneControl.SetCurrentScene(WorldScene)
}
func newWorld() {
ProgressText.Text = "Generating world..."
Engine.SceneControl.SetCurrentScene(LoadingScene)
generateWorldTree()
}
func doesWorldExist(world int) bool {
if _, err := os.Stat("./worlds/world" + fmt.Sprint(world) + ".hln"); os.IsNotExist(err) {
return false
}
return true
}