-
Notifications
You must be signed in to change notification settings - Fork 49
/
Copy pathScene.yue
235 lines (212 loc) · 8.46 KB
/
Scene.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
--[[ Copyright (c) 2016-2025 Li Jin <dragon-fly@qq.com>
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.Platformer
store: Store = Data
{
:GroupPlayer
:GroupEnemy
:GroupPlayerBlock
:GroupEnemyBlock
:GroupTerrain
:GroupDisplay
:LayerBlock
:LayerBunny
:LayerSwitch
:LayerPlayerHero
:LayerEnemyHero
:LayerBackground
} = Store
GameWorld = Class PlatformWorld,
__init: =>
Entity world: @
const DesignWidth = 1024
@camera.zoom = View.size.width / DesignWidth
@onAppChange (settingName) -> if settingName == "Size"
@camera.zoom = View.size.width / DesignWidth
buildBackground: =>
terrainDef = with BodyDef!
.type = "Static"
\attachPolygon Vec2(2048, 1004 - 994), 4096, 10
\attachPolygon Vec2(2048, 1004), 4096, 10
\attachPolygon Vec2(-5, 1004 - 512), 10, 1024
\attachPolygon Vec2(4101, 1004 - 512), 10, 1024
@addChild with Body terrainDef, @, Vec2.zero
.order = LayerBackground
.group = GroupTerrain
@addChild with Sprite "Model/items.clip|background"
.order = LayerBackground
.anchor = Vec2.zero
.scaleX = 4146 / .width
.scaleY = 1600 / .height
.y = -50
@addChild with Node!
.order = LayerBackground
.y = -44
for i = 0, 32
\addChild with Sprite "Model/misc.clip|floor"
.scaleX = 8
.scaleY = 8
.x = i * 128
.filter = "Point"
buildGameReadme: =>
pos = @camera.position
readmeDef = with BodyDef!
.type = "Static"
\attachPolygon Vec2(pos.x, 1004 - 994), 1024, 10
\attachPolygon Vec2(pos.x, 1004), 1024, 10
\attachPolygon Vec2(pos.x - 512, 1004 - 512), 10, 1024
\attachPolygon Vec2(pos.x + 512, 1004 - 512), 10, 1024
readme = with Body readmeDef, @, Vec2.zero
.order = LayerBackground
.group = GroupDisplay
\addTo @
\gslot "PlayerSelect", ->
.children\each (child) ->
with Visual "Particle/heart.par"
.position = child\convertToWorldSpace Vec2.zero
\autoRemove!
\start!
\removeFromParent!
for item in *[
["war", Vec2(pos.x - 512 + 369, 1004 - 413 - 200)]
["use", Vec2(pos.x - 512 + 459, 1004 - 575 - 200)]
["key", Vec2(pos.x - 512 + 521, 1004 - 499 - 200)]
["loli", Vec2(pos.x - 512 + 655, 1004 - 423 - 200)]
["select", Vec2(pos.x - 512 + 709, 1004 - 509 - 200)]
["mosic", Vec2(pos.x - 512 + 599, 1004 - 339 - 200)]
["breakblocks", Vec2(pos.x - 512 + 578, 1004 - 626 - 200)]
["search", Vec2(pos.x - 512 + 746, 1004 - 604 - 200)]
["quit", Vec2(pos.x - 512 + 363, 1004 - 566 - 200)]
["pushSwitch", Vec2(pos.x - 512 + 494, 1004 - 631 - 200)]
["attack", Vec2(pos.x - 512 + 630, 1004 - 631 - 200)]
]
sp = with Sprite "Model/misc.clip|#{item[1]}"
.scaleX = 2
.scaleY = 2
.filter = "Point"
rectDef = with BodyDef!
.linearAcceleration = Vec2 0, -10
.type = "Dynamic"
\attachPolygon sp.width * 2, sp.height * 2, 1, 0, 1
with Body rectDef, @, item[2]
.order = LayerBackground
.group = GroupDisplay
\addChild sp
\addTo readme
buildCastles: (_self) ->
Block = (block, group, look, x, y) ->
Entity
block: "Block#{block}"
:group
layer: LayerBlock
:look
position: Vec2 x, y
-- Player's castle 1
Block "C", GroupPlayerBlock, "gray", 419, 1004 - 280
Block "A", GroupPlayerBlock, "green", 239, 1004 - 190
Block "A", GroupPlayerBlock, "green", 419, 1004 - 190
Block "A", GroupPlayerBlock, "green", 599, 1004 - 190
Block "C", GroupPlayerBlock, "gray", 419, 1004 - 580
Block "B", GroupPlayerBlock, "", 291, 1004 - 430
Block "B", GroupPlayerBlock, "", 416, 1004 - 430
Block "B", GroupPlayerBlock, "", 540, 1004 - 430
Block "A", GroupPlayerBlock, "gray", 239, 1004 - 670
Block "A", GroupPlayerBlock, "gray", 599, 1004 - 670
Block "A", GroupPlayerBlock, "blue", 239, 1004 - 760
Block "A", GroupPlayerBlock, "blue", 599, 1004 - 760
Block "A", GroupPlayerBlock, "red", 239, 1004 - 850
Block "A", GroupPlayerBlock, "red", 599, 1004 - 850
Block "C", GroupPlayerBlock, "jade", 419, 1004 - 940
-- Player's castle 2
Block "C", GroupPlayerBlock, "jade", 1074, 1004 - 552
Block "C", GroupPlayerBlock, "jade", 1074, 1004 - 731
Block "A", GroupPlayerBlock, "blue", 894, 1004 - 463
Block "A", GroupPlayerBlock, "blue", 1075, 1004 - 463
Block "A", GroupPlayerBlock, "blue", 1254, 1004 - 463
Block "A", GroupPlayerBlock, "green", 956, 1004 - 642
Block "A", GroupPlayerBlock, "green", 1194, 1004 - 642
Block "B", GroupPlayerBlock, "", 893, 1004 - 881
Block "B", GroupPlayerBlock, "", 1254, 1004 - 881
-- Enemy's castle 1
Block "C", GroupEnemyBlock, "gray", 3674, 1004 - 281
Block "A", GroupEnemyBlock, "green", 3494, 1004 - 191
Block "A", GroupEnemyBlock, "green", 3674, 1004 - 191
Block "A", GroupEnemyBlock, "green", 3854, 1004 - 191
Block "C", GroupEnemyBlock, "gray", 3674, 1004 - 581
Block "B", GroupEnemyBlock, "", 3546, 1004 - 431
Block "B", GroupEnemyBlock, "", 3671, 1004 - 431
Block "B", GroupEnemyBlock, "", 3795, 1004 - 431
Block "A", GroupEnemyBlock, "gray", 3494, 1004 - 671
Block "A", GroupEnemyBlock, "gray", 3854, 1004 - 671
Block "A", GroupEnemyBlock, "blue", 3494, 1004 - 761
Block "A", GroupEnemyBlock, "blue", 3854, 1004 - 761
Block "A", GroupEnemyBlock, "red", 3494, 1004 - 851
Block "A", GroupEnemyBlock, "red", 3854, 1004 - 851
Block "C", GroupEnemyBlock, "jade", 3674, 1004 - 941
-- Enemy's castle 2
Block "C", GroupEnemyBlock, "jade", 3024, 1004 - 552
Block "C", GroupEnemyBlock, "jade", 3024, 1004 - 731
Block "A", GroupEnemyBlock, "blue", 2844, 1004 - 463
Block "A", GroupEnemyBlock, "blue", 3025, 1004 - 463
Block "A", GroupEnemyBlock, "blue", 3204, 1004 - 463
Block "A", GroupEnemyBlock, "green", 2906, 1004 - 642
Block "A", GroupEnemyBlock, "green", 3144, 1004 - 642
Block "B", GroupEnemyBlock, "", 2843, 1004 - 881
Block "B", GroupEnemyBlock, "", 3204, 1004 - 881
playerBlockHP = 0
enemyBlockHP = 0
with Group ["block",]
\each => switch @group
when GroupPlayerBlock
playerBlockHP += Store[@block].hp
when GroupEnemyBlock
enemyBlockHP += Store[@block].hp
emit "BlockValue", GroupPlayer, playerBlockHP
emit "BlockValue", GroupEnemy, enemyBlockHP
buildSwitches: (_self) ->
Switch = (switchType, group, look, x, y) ->
Entity
switch: switchType
:group
:look
layer: LayerSwitch
position: Vec2 x, y
Switch "Switch", GroupPlayer, "normal", 777, 1004 - 923
Switch "SwitchG", GroupPlayer, "gold", 116, 1004 - 923
Switch "Switch", GroupEnemy, "normal", 3331, 1004 - 923
Switch "SwitchG", GroupEnemy, "gold", 3977, 1004 - 923
addBunnySwither: (_self, group) ->
switchGExist = false
switchNExist = false
bunnySwitchers = Group ["bunny", "targetSwitch"]
bunnySwitchers\each (switcher) ->
if switcher.group == group
switch switcher.targetSwitch
when "SwitchG" then switchGExist = true
when "Switch" then switchNExist = true
if not switchGExist
Entity with { }
.group = group
.bunny, .faceRight, .position = switch group
when GroupPlayer then "BunnyG", false, Vec2 216, 500
when GroupEnemy then "BunnyP", true, Vec2 3877, 500
.AI = "BunnySwitcherAI"
.layer = LayerBunny
.targetSwitch = "SwitchG"
if not switchNExist
Entity with { }
.group = group
.bunny, .faceRight, .position = switch group
when GroupPlayer then "BunnyG", true, Vec2 677, 500
when GroupEnemy then "BunnyP", false, Vec2 3431, 500
.AI = "BunnySwitcherAI"
.layer = LayerBunny
.targetSwitch = "Switch"
clearScene: =>
@removeLayer LayerBlock
@removeLayer LayerBunny
@removeLayer LayerPlayerHero
@removeLayer LayerEnemyHero
export default GameWorld!