-
Notifications
You must be signed in to change notification settings - Fork 49
/
Copy pathDebug.yue
186 lines (176 loc) · 6.39 KB
/
Debug.yue
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
--[[ Copyright (c) 2016-2025 Li Jin <[email protected]>
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ]]
_ENV = Dora Dora.ImGui, Dora.Platformer
import "UI.View.Shape.Star"
store:Store = Data
{
:world
:ZombieLayer
:PlayerGroup
} = Store
playerGroup = Group ["player", "unit"]
zombieGroup = Group ["zombie", "unit"]
userControl = false
playerChoice = 1
controlChoice = switch App.platform
when "iOS", "Android", "macOS" then 0
else 1
camZoom = world.camera.zoom
decisions = []
showDecisionTrace = false
lastDecisionTree = ""
world\schedule ->
:width = App.visualSize
SetNextWindowPos Vec2(width - 250, 10), "FirstUseEver"
SetNextWindowSize Vec2(240, userControl and 500 or 300)
Begin "Zombie Game Demo", ["NoResize", "NoSavedSettings"], ->
TextWrapped "Zombie Killed: #{Store.zombieKilled}"
SameLine!
if Button "Army"
for _i = 0, 10
available = false
pos = Vec2.zero
while not available
pos = Vec2 App.rand % 2400 - 1200, -430
available = not world\query Rect(pos,Size(5, 5)), => @group == Data.groupTerrain
Entity
unitDef: "Unit_Zombie#{App.rand % 2 + 1}"
order: ZombieLayer
position: pos
group: PlayerGroup
faceRight: App.rand % 2 == 0
stared: true
changed,camZoom = DragFloat "Zoom", camZoom, 0.01, 0.5, 2, "%.2f"
world.camera.zoom = camZoom if changed
playerGroup\each => TextWrapped "#{@unit.tag} HP: #{@hp}"
changed, result = Checkbox "Physics Debug", world.showDebug
world.showDebug = result if changed
changed, showDecisionTrace = Checkbox "AI Debug", showDecisionTrace
if changed
playerGroup\each => @unit.receivingDecisionTrace = showDecisionTrace
changed, userControl = Checkbox "Take Control", userControl
if userControl
if Store.controlPlayer == "Zombie" and
not playerGroup\each =>
if @unit.tag == "Zombie"
if @hp <= 0
@player = nil
@unit.children.last\removeFromParent!
@unit.decisionTree = ""
@unit.tag = "ZombieDead"
return false
else return true
return false
zombieGroup\each =>
return false if @hp <= 0
@player = true
@zombie = nil
world.camera.followTarget = with @unit
.tag = "Zombie"
.group = PlayerGroup
.decisionTree = "AI_PlayerControl"
.sensity = 0
\addChild Star {
y: 100
size: 18
borderColor: 0xffff8800
fillColor: 0x66ff8800
fillOrder: 1
lineOrder: 2
}
true
Separator!
pressedA, choice = RadioButton "Male", playerChoice, 0
playerChoice = choice if pressedA
pressedB, choice = RadioButton "Female", playerChoice, 1
playerChoice = choice if pressedB
pressedC, choice = RadioButton "Zombie", playerChoice, 2
playerChoice = choice if pressedC
if pressedA or pressedB or pressedC or changed
Store.controlPlayer = switch playerChoice
when 0 then "KidM"
when 1 then "KidW"
when 2 then "Zombie"
if Store.controlPlayer == "Zombie" and
not playerGroup\each => @unit.tag == "Zombie"
zombieGroup\each =>
@player = true
@zombie = nil
with @unit
.tag = "Zombie"
.group = PlayerGroup
\addChild Star {
y: 100
size: 18
borderColor: 0xffff8800
fillColor: 0x66ff8800
fillOrder: 1
lineOrder: 2
}
true
playerGroup\each =>
if @unit.tag == Store.controlPlayer
@unit.decisionTree = "AI_PlayerControl"
@unit.sensity = 0
world.camera.followTarget = @unit
else
@unit.decisionTree = switch @unit.tag
when "KidM" then "AI_KidFollow"
when "KidW" then "AI_KidSearch"
when "Zombie" then "AI_Zombie"
@unit.sensity = 0.1
if changed
Store.keyboardEnabled = controlChoice == 1
Director.ui.children.first.visible = controlChoice == 0
Separator!
TextWrapped if controlChoice == 1
"Keyboard: Left(A), Right(D), Shoot(J), Jump(K)"
else "TouchPad: Use buttons in lower screen to control unit."
Separator!
pressedA, choice = RadioButton "TouchPad", controlChoice, 0
if pressedA
controlChoice = choice
Store.keyboardEnabled = false
Director.ui\eachChild => @visible = true
pressedB, choice = RadioButton "Keyboard", controlChoice, 1
if pressedB
controlChoice = choice
Store.keyboardEnabled = true
Director.ui.children.first.visible = false
elseif changed
playerGroup\each =>
@unit.decisionTree = switch @unit.tag
when "KidM" then "AI_KidFollow"
when "KidW" then "AI_KidSearch"
when "Zombie" then "AI_Zombie"
@unit.sensity = 0.1
Store.keyboardEnabled = false
Director.ui.children.first.visible = false
target = world.camera.followTarget
if target
player = target.entity
decisionTrace = player.decisionTrace
lastDecision = decisions[#decisions]
if lastDecision ~= decisionTrace
decisions[] = decisionTrace
table.remove decisions,1 if #decisions > 5
lastDecisionTree = target.decisionTree
if showDecisionTrace
SetNextWindowPos Vec2(width / 2 - 200, 10), "FirstUseEver"
SetNextWindowSize Vec2(400, 160), "FirstUseEver"
Begin "Decision Trace (#{lastDecisionTree})", {"NoSavedSettings"}, ->
Text table.concat decisions, "\n"
with Observer "Add", ["group", "unit", "player", "stared"]
\watch (_entity, _group, unit): false ->
unit\addChild Star {
y: 100
size: 18
borderColor: 0xff66ccff
fillColor: 0x6666ccff
fillOrder: 1
lineOrder: 2
}
with Observer "Add", ["unit", "player"]
\watch (_entity, unit): false -> unit.receivingDecisionTrace = true