-
Notifications
You must be signed in to change notification settings - Fork 50
/
Copy pathAction.yue
208 lines (192 loc) · 5.44 KB
/
Action.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
--[[ 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.Platformer
store: Store = Data
{
:LayerBunny
:LayerBlock
:GroupPlayerPoke
:GroupEnemyPoke
:GroupPlayer
:GroupEnemy
:MaxBunnies
} = Store
UnitAction\add "fallOff",
priority: 1
reaction: 0.1
recovery: 0
available: => not @onSurface
create: =>
with @playable
.speed = 1.5
\play "jump", true
=> @onSurface
pushSwitchEnd = (name, playable) ->
switch name when "switch", "attack"
playable.parent\stop!
UnitAction\add "pushSwitch",
priority: 4
reaction: 3
recovery: 0.2
queued: true
available: => @onSurface
create: =>
with @playable
.speed = 1.5
.look = "noweapon"
\play "switch"
if not .playing
\play "attack"
\slot "AnimationEnd", pushSwitchEnd
with @data.atSwitch
.data.pushed = true
.data.fromRight = @x > .x
-> false
stop: =>
@playable\slot("AnimationEnd")\remove pushSwitchEnd
UnitAction\add "waitUser",
priority: 1
reaction: 0.1
recovery: 0.2
available: -> true
create: =>
with @playable
.speed = 1
\play "idle", true
-> false
switchPushed = (name, playable) ->
switch name when "pushRight", "pushLeft"
playable.parent\stop!
UnitAction\add "pushed",
priority: 2
reaction: 0.1
recovery: 0.2
queued: true
available: -> true
create: =>
with @playable
.recovery = 0.2
.speed = 1.5
\play @data.fromRight and "pushLeft" or "pushRight"
\slot "AnimationEnd", switchPushed
once =>
sleep 0.5
Audio\play "Audio/switch.wav"
heroes = Group {"hero"}
switch @entity.switch
when "Switch"
heroes\each (hero) ->
if @group == hero.group and hero.ep >= 1
Entity with { }
.bunny, .group, .faceRight, .position = switch @group
when GroupPlayer
"BunnyG", GroupPlayer, true, Vec2 1000, 1004 - 500
when GroupEnemy
"BunnyP", GroupEnemy, false, Vec2 3130, 1004 - 500
.AI = "BunnyForwardReturnAI"
.layer = LayerBunny
bunnyCount = 0
Group(["bunny",])\each (bunny) ->
bunnyCount += 1 if bunny.group == @group
.hp = 0.0 if bunnyCount > MaxBunnies
emit "EPChange", @group, -1
return true
when "SwitchG"
heroes\each (hero) ->
if @group == hero.group and hero.ep >= 2
Entity with { }
.layer = LayerBlock
.poke, .group, .position = switch @group
when GroupPlayer
"pokeb", GroupPlayerPoke, Vec2 192, 1004 - 512
when GroupEnemy
"pokep", GroupEnemyPoke, Vec2 3904, 1004 - 512
emit "EPChange", @group, -2
return true
while true
sleep!
stop: =>
@data.pushed = false
@playable\slot("AnimationEnd")\remove pushSwitchEnd
strikeEnd = (name, playable) ->
playable.parent\stop! if name == "hit"
UnitAction\add "strike",
priority: 4
reaction: 3
recovery: 0
queued: true
available: -> true
create: =>
with @playable
.speed = 1
.look = "fail"
\play "hit"
\slot "AnimationEnd", strikeEnd
Audio\play "Audio/hit.wav"
-> false
stop: =>
@playable\slot("AnimationEnd")\remove strikeEnd
villyAttackEnd = (name, playable) ->
playable.parent\stop! if name == "attack"
UnitAction\add "villyAttack",
priority: 3
reaction: 10
recovery: 0.1
queued: true
available: -> true
create: =>
{
:attackSpeed
:targetAllow
:damageType
:attackBase
:attackBonus
:attackFactor
:attackPower
} = @entity
with @playable
.speed = attackSpeed
.look = "fight"
\play "attack"
\slot "AnimationEnd", villyAttackEnd
once =>
bulletDef = Store[@unitDef.bulletType]
onAttack = ->
Audio\play "Audio/v_att.wav"
with Bullet bulletDef, @
.targetAllow = targetAllow
\slot "HitTarget", (bullet, target, pos) ->
with target.data
.hitPoint = pos
.hitPower = attackPower
.hitFromRight = bullet.velocityX < 0
:entity = target
factor = Data\getDamageFactor damageType, entity.defenceType
damage = (attackBase + attackBonus) * (attackFactor + factor)
entity.hp -= damage
bullet.hitStop = true
\addTo @world, @order
sleep 0.17 / attackSpeed
onAttack!
sleep 0.63 / attackSpeed
onAttack!
sleep 1.0
true
stop: =>
@playable\slot("AnimationEnd")\remove villyAttackEnd
UnitAction\add "wait",
priority: 1
reaction: 0.1
recovery: 0
available: => @onSurface
create: =>
with @playable
.speed = 1
.look = Store.winner == @group and "happy" or "fail"
\play "idle", true
=>
if not @onSurface
return true
false