-
Notifications
You must be signed in to change notification settings - Fork 49
/
Copy pathinit.yue
362 lines (342 loc) · 9.62 KB
/
init.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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
--[[ 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. ]]
-- GGJ2022
_ENV = Dora
scriptPath = Path\getScriptPath ...
return unless scriptPath
Content\insertSearchPath 1, scriptPath
import "BodyEx"
import "UI.View.Shape.SolidRect"
import "Utils" as :Struct, :Set
root = with Node!
\slot "Cleanup", -> Audio\stopStream 0.2
ui = with Node!
.scaleX = .scaleY = 0.4
\addChild Sprite "Model/duality.clip|stat"
score = 0
scoreTxt = with Label "sarasa-mono-sc-regular", 40
.textAlign = "Center"
.color3 = Color3 0x0
.text = "0"
\addTo ui
world = with PhysicsWorld!
.y = 405
\setShouldContact 0, 0, true
\setShouldContact 0, 1, false
\addTo root
isSpace = true
switchScene = nil
center = nil
spaceBack = nil
dailyBack = nil
Director.ui\addChild with AlignNode true
\css "flex-direction: column"
\slot "AlignLayout", (w, h) ->
worldScale = w / 2970
root.scaleX = worldScale
root.scaleY = worldScale
center.position = Vec2 w / 2, h / 2
spaceBack\removeFromParent! if spaceBack
spaceBack = with Node!
.position = Vec2 w / 2, h / 2
.visible = isSpace
.order = -1
\addChild with Grid "Model/duality.clip|space", 1, 1
\moveUV 1, 1, Vec2 1, 1
\moveUV 2, 1, Vec2 -1, 1
\moveUV 1, 2, Vec2 1, -1
\moveUV 2, 2, Vec2 -1, -1
.scaleX = w / 8
.scaleY = h / 1078
\addChild with Node!
.scaleX = worldScale
.scaleY = worldScale
for y = 1, 8 do for x = 1, 8
\addChild with Sprite "Model/duality.clip|stary"
.anchorX = 0
.x = -3000 + (x - 1) * 1000
.y = 3000 - (y - 1) * 1000
\perform X 10, 0, -1000 * worldScale
\slot "ActionEnd", -> \perform X 10, 0, -1000 * worldScale
\addChild spaceBack
dailyBack\removeFromParent! if dailyBack
dailyBack = with Grid "Model/duality.clip|day", 1, 1
.position = Vec2 w / 2, h / 2
.visible = not isSpace
.order = -1
\moveUV 1, 1, Vec2 1, 1
\moveUV 2, 1, Vec2 -1, 1
\moveUV 1, 2, Vec2 1, -1
\moveUV 2, 2, Vec2 -1, -1
.scaleX = w / 8
.scaleY = h / 1078
\addChild dailyBack
\addChild with AlignNode!
.order = 1
\css "height: 30%; flex-direction: row-reverse"
\addChild with AlignNode!
\css "height: 25; margin-right: 45"
\addChild ui
\addChild with center = AlignNode!
.order = 2
\css "height: 40%"
\addChild with Node!
.touchEnabled = true
.swallowTouches = true
\addChild with banner = Sprite "Model/duality.clip|dismantlism"
center\slot "AlignLayout", (w, h) ->
.position = Vec2 w / 2, h / 2
.scaleX = .scaleY = 0.9 * math.min w / banner.width, h / banner.height
\perform Sequence(
Delay 1
Spawn(
Opacity 1, 1, 0, Ease.OutQuad
Y 1, 0, 100, Ease.InQuad
)
Event "Start"
)
\slot "Start", ->
isSpace = false
switchScene!
center\slot "AlignLayout", nil
\removeFromParent!
\addChild with AlignNode!
\css "height: 30%"
\addChild root
\slot "AlignLayout", (w) -> root.x = w / 2
moveJoint = nil
movingBody = nil
with Node!
.touchEnabled = true
\slot "TapBegan", (touch) ->
worldPos = \convertToWorldSpace touch.location
pos = world\convertToNodeSpace worldPos
world\query Rect(pos - Vec2(1, 1), Size 2, 2), (body) ->
return false if body.tag ~= "" and body.tag ~= (isSpace and "space" or "daily")
moveJoint\destroy! if moveJoint
moveJoint = Joint\move true, body, pos, 400
movingBody = body
true
\slot "TapMoved", (touch) ->
if moveJoint
worldPos = \convertToWorldSpace touch.location
pos = world\convertToNodeSpace worldPos
moveJoint.position = pos
\slot "TapEnded", ->
if moveJoint
moveJoint\destroy!
moveJoint = nil
movingBody = nil
scene = require "scene"
Struct.Body "name", "file", "position", "angle"
Struct\load scene
spaceItems = Set
* "rocket"
* "satlite"
* "spacestation"
* "star1"
* "star2"
* "ufo"
* "get"
dailyItems = Set
* "baseball"
* "burger"
* "donut"
* "fish"
* "radio"
* "tv"
* "pizza"
spaceBodies = []
dailyBodies = []
switchScene = (init) ->
if isSpace
Audio\playStream "Audio/Dismantlism Space.ogg", true
unless init
dailyBack\perform Sequence(
Show!
Opacity 0.5, 1, 0
Hide!
)
spaceBack\perform Sequence(
Show!
Opacity 0.5, 0, 1
)
for body in *dailyBodies
with body.children[1]
if .actionCount == 0
\perform Sequence(
Show!
Scale 0.5, 1, 0, Ease.OutBack
Hide!
)
for body in *spaceBodies
with body.children[1]
if .actionCount == 0
\perform Sequence(
Show!
Scale 0.5, 0, 1, Ease.OutBack
)
else
Audio\playStream "Audio/Dismantlism Daily.ogg", true
unless init
spaceBack\perform Sequence(
Show!
Opacity 0.5, 1, 0
Hide!
)
dailyBack\perform Sequence(
Show!
Opacity 0.5, 0, 1
)
for body in *spaceBodies
with body.children[1]
if .actionCount == 0
\perform Sequence(
Show!
Scale 0.5, 1, 0, Ease.OutBack
Hide!
)
for body in *dailyBodies
with body.children[1]
if .actionCount == 0
\perform Sequence(
Show!
Scale 0.5, 0, 1, Ease.OutBack
)
restartScene = nil
gameEnded = false
buildScene = ->
for i = 1, scene\count!
{
:name
:file
:position = Vec2.zero
:angle = 0
} = scene\get i
node = BodyEx require(Path "Physics", file), world, position, angle
world\addChild node
if spaceItems[file]
node.data\each =>
@tag = "space"
@children[1].tag = file
spaceBodies[] = @
elseif dailyItems[file]
node.data\each =>
@tag = "daily"
@children[1].tag = file
dailyBodies[] = @
else
node.data\each =>
@children[1].tag = file if @children and #@children > 0
switch file
when "removearea"
with node.data.rect
\addChild SolidRect x: -200, y: -200, width: 400, height: 400, color: 0x66000000
\addChild with Label "sarasa-mono-sc-regular", 80
.textAlign = "Center"
.color = Color 0x66ffffff
.text = "Drag It\nHere"
\slot "BodyEnter", (body) ->
return if body.tag ~= "" and body.tag ~= (isSpace and "space" or "daily")
return if body.group == 1
body.group = 1
with body.children[1]
\perform Sequence Spawn(
Opacity 0.5, 1, 0
Scale 0.5, 1, 1.5, Ease.OutBack
), Event "Destroy"
\slot "Destroy", ->
switch .tag
when "star2", "pizza"
score += 10
isSpace = not isSpace
switchScene!
when "quit"
-- App\shutdown!
when "get", "fish"
score += 100
when "credit"
score += 50
world\addChild with Node!
\addChild Sprite "Model/duality.clip|window"
\addChild Sprite "Model/duality.clip|credits1"
.position = body.position
\perform Sequence(
Spawn(
Scale 0.5, 0, 1, Ease.OutBack
Opacity 0.5, 0, 1
)
Delay 3
Scale 0.5, 1, 0, Ease.InBack
Event "End"
)
\slot "End", -> \removeFromParent!
else
score += 10
scoreTxt.text = tostring score
if score > 600
gameEnded = true
center\addChild with Node!
\addChild Sprite "Model/duality.clip|window"
\addChild Sprite "Model/duality.clip|win"
\perform Sequence(
Spawn(
Scale 0.5, 0, 1, Ease.OutBack
Opacity 0.5, 0, 1
)
Delay 3
Scale 0.5, 1, 0, Ease.InBack
Event "End"
)
\slot "End", ->
\removeFromParent!
restartScene!
if movingBody == body and moveJoint
moveJoint\destroy!
moveJoint = nil
movingBody = nil
body\removeFromParent!
when "safearea"
with node.data.rect
\slot "BodyEnter", (body) ->
return if body == movingBody
:tag = body.children[1]
if (name == "safe1" and tag == "get") or
(name == "safe2" and tag == "fish")
if not gameEnded
gameEnded = true
world\addChild with Node!
\addChild Sprite "Model/duality.clip|window"
\addChild Sprite "Model/duality.clip|lose"
.position = body.position
\perform Sequence(
Spawn(
Scale 0.5, 0, 1, Ease.OutBack
Opacity 0.5, 0, 1
)
Delay 2
Scale 0.5, 1, 0, Ease.InBack
Event "End"
)
\slot "End", -> restartScene!
buildScene!
switchScene true
restartScene = ->
score = 0
scoreTxt.text = "0"
isSpace = false
gameEnded = false
if moveJoint
moveJoint\destroy!
moveJoint = nil
movingBody = nil
world\removeFromParent!
world = with PhysicsWorld!
.y = 405
\setShouldContact 0, 0, true
\setShouldContact 0, 1, false
\addTo root
buildScene!
switchScene!