zombies.nv
· 8.1 KiB · Text
Исходник
Playground
player $player,
$player at x #400 and y #300,
can update for $player.
update $id, player $id?:
, compute player $id velocity x
, @is-down key a, @is-down key d
, compute player $id velocity y
, @is-down key w, @is-down key s
.
compute player $id velocity x, @key-state down a:
, player $id velocity x computed
, player velocity x #-250
.
compute player $id velocity x, @key-state down d:
, player $id velocity x computed
, player velocity x #250
.
compute player $id velocity x:
, player $id velocity x computed
, player velocity x #0
.
compute player $id velocity y, @key-state down w:
, player $id velocity y computed
, player velocity y #-250
.
compute player $id velocity y, @key-state down s:
, player $id velocity y computed
, player velocity y #250
.
compute player $id velocity y:
, player $id velocity y computed
, player velocity y #0
.
player $id velocity y computed,
player $id velocity x computed:
, player $id velocity computed
.
player $id velocity computed?, @key-state up $key: .
player $id velocity computed?, @key-state down $key: .
tick $dt?
, player $id velocity computed
, $id at x $x and y $y
, player velocity y $vy
, player velocity x $vx:
, commit player $id motion $new-x-token $new-y-token
, @expr eval $new-x-token [%1 * %2 + %3] $vx $dt $x
, @expr eval $new-y-token [%1 * %2 + %3] $vy $dt $y
.
commit player $id motion $new-x-token $new-y-token,
@expr success $x $new-x-token,
@expr success $y $new-y-token:
, finished update for $id
, $id at x $x and y $y
, @circle $x $y #20
.
compute enemy $id velocity
, $id at x $my-x and y $my-y?
, player $player?
, $player at x $player-x and y $player-y?:
, find angle to player for enemy $id using $delta-x-token $delta-y-token
, @expr eval $delta-x-token [%1 - %2] $player-x $my-x
, @expr eval $delta-y-token [%1 - %2] $player-y $my-y
.
find angle to player for enemy $id using $delta-x-token $delta-y-token
, @expr success $delta-x $delta-x-token
, @expr success $delta-y $delta-y-token:
, compute enemy $id motion using $angle-token
, @atan2 from $delta-x $delta-y into $angle-token
.
compute enemy $id motion using $angle-token
, @atan2 angle $angle $angle-token:
, compute new enemy $id location using $vx-token $vy-token
, @expr eval $vx-token [cos(%1) * 200] $angle
, @expr eval $vy-token [sin(%1) * 200] $angle
.
compute new enemy $id location using $vx-token $vy-token
, tick $dt?
, $id at x $x and y $y
, @expr success $vx $vx-token
, @expr success $vy $vy-token:
, complete enemy $id update using $x-token $y-token
, @expr eval $x-token [%1 + %2 * %3] $x $vx $dt
, @expr eval $y-token [%1 + %2 * %3] $y $vy $dt
.
complete enemy $id update using $x-token $y-token,
@expr success $x $x-token,
@expr success $y $y-token:
, finished update for $id
, $id at x $x and y $y
, @circle $x $y #10
.
update $id, enemy $id?:
, compute enemy $id velocity
.
update $self, bullet $self?
, $self at x $x and y $y
, $self velocity is x $vx and y $vy?
, tick $dt?:
, move bullet $self using $x-token $y-token
, @expr eval $x-token [%1 + %2 * %3] $x $vx $dt
, @expr eval $y-token [%1 + %2 * %3] $y $vy $dt
.
move bullet $self using $x-token $y-token,
@expr success $x $x-token,
@expr success $y $y-token:
, $self at x $x and y $y
, check if bullet $self should be destroyed
, finish bullet $self update
.
check if bullet $self should be destroyed, $self at x $x and y $y?:
, is bullet $self in bounds checking
$left-bounds $right-bounds
$top-bounds $bottom-bounds
, @compare $x and #0 producing $left-bounds
, @compare $x and #800 producing $right-bounds
, @compare $y and #0 producing $top-bounds
, @compare $y and #600 producing $bottom-bounds
.
is bullet $self in bounds checking
$left-bounds $right-bounds
$top-bounds $bottom-bounds
, @compare greater-than $left-bounds
, @compare less-than $right-bounds
, @compare greater-than $top-bounds
, @compare less-than $bottom-bounds:
bullet $self is in bounds.
is bullet $self in bounds checking
$left-bounds $right-bounds
$top-bounds $bottom-bounds
, @compare $invalid-1 $left-bounds
, @compare $invalid-2 $right-bounds
, @compare $invalid-3 $top-bounds
, @compare $invalid-4 $bottom-bounds:
bullet $self is out of bounds.
bullet $self is out of bounds?, @compare $ord $token:.
finish bullet $self update,
bullet $self is out of bounds,
bullet $self, $self at x $x and y $y, $self velocity is x $vx and y $vy: .
finish bullet $self update,
bullet $self is in bounds,
$self at x $x and y $y?:
, finished update for $self
, @circle $x $y #5
.
spawn-timer $self
, $self is at #0 seconds
, $self times out every #1 seconds
, can update for $self
.
update $self, spawn-timer $self?, $self is at $time seconds, tick $dt?:
, update timer $self using $new-time-token
, @expr eval $new-time-token [%1 + %2] $time $dt
.
update timer $self using $new-time-token
, $self times out every $time-out seconds?
, @expr success $time $new-time-token:
, update timer $self to $time seconds using $bounds-check
, @compare $time and $time-out producing $bounds-check
.
update timer $self to $time seconds using $bounds-check
, @compare less-than $bounds-check:
, $self is at $time seconds,
, finished update for $self
.
update timer $self to $time seconds using $bounds-check,
@compare $invalid $bounds-check:
, spawn enemy
, $self is at #0 seconds
, finished update for $self
.
spawn enemy:
, compute enemy $id location using $turns-token
, @random generate $turns-token
.
compute enemy $id location using $turns-token,
@random get $turns $turns-token:
, commit new enemy $id at x $x-token and y $y-token
, @expr eval $x-token [cos(6.28318530718 * %1) * 500 + 400] $turns
, @expr eval $y-token [sin(6.28318530718 * %1) * 500 + 300] $turns
.
commit new enemy $id at x $x-token and y $y-token,
@expr success $x $x-token,
@expr success $y $y-token:
, enemy $id
, $id at x $x and y $y
, can update for $id
.
bullet-spawner $self
, can mouse-pressed for $self.
mouse-pressed $self $mouse-x $mouse-y $button, bullet-spawner $self?
, player $p?, $p at x $player-x and y $player-y?:
, shoot bullet at angle using $angle-token
, compute shoot angle using $shoot-x-token $shoot-y-token
producing $angle-token
, @expr eval $shoot-x-token [%1 - %2] $mouse-x $player-x
, @expr eval $shoot-y-token [%1 - %2] $mouse-y $player-y
.
compute shoot angle using $shoot-x-token $shoot-y-token producing $angle-token
, @expr success $shoot-x $shoot-x-token
, @expr success $shoot-y $shoot-y-token:
, @atan2 from $shoot-x $shoot-y into $angle-token
.
shoot bullet at angle using $angle-token
, player $p?, $p at x $player-x and y $player-y?
, @atan2 angle $angle $angle-token:
, create new bullet $id using
$spawn-x-token
$spawn-y-token
$bullet-vx-token
$bullet-vy-token
, @expr eval $spawn-x-token [cos(%1) + %2] $angle $player-x
, @expr eval $spawn-y-token [sin(%1) + %2] $angle $player-y
, @expr eval $bullet-vx-token [cos(%1) * 500] $angle
, @expr eval $bullet-vy-token [sin(%1) * 500] $angle
.
, create new bullet $id using
$spawn-x-token
$spawn-y-token
$bullet-vx-token
$bullet-vy-token
, bullet-spawner $self?
, @expr success $bullet-x $spawn-x-token
, @expr success $bullet-y $spawn-y-token
, @expr success $bullet-vx $bullet-vx-token
, @expr success $bullet-vy $bullet-vy-token:
, bullet $id
, $id at x $bullet-x and y $bullet-y
, $id velocity is x $bullet-vx and y $bullet-vy
, can update for $id
, finished mouse-pressed for $self
.
tick $dt?, can update for $id:
, update $id
.
tick $dt: prepare next tick.
mouse-pressed $x $y $button, can mouse-pressed for $id:
, mouse-pressed $id $x $y $button
.
mouse-pressed $x $y $button: .
prepare next tick?, finished $event for $id:
can $event for $id.
prepare next tick: .
1 | player $player, |
2 | $player at x #400 and y #300, |
3 | can update for $player. |
4 | |
5 | update $id, player $id?: |
6 | , compute player $id velocity x |
7 | , @is-down key a, @is-down key d |
8 | , compute player $id velocity y |
9 | , @is-down key w, @is-down key s |
10 | . |
11 | |
12 | compute player $id velocity x, @key-state down a: |
13 | , player $id velocity x computed |
14 | , player velocity x #-250 |
15 | . |
16 | |
17 | compute player $id velocity x, @key-state down d: |
18 | , player $id velocity x computed |
19 | , player velocity x #250 |
20 | . |
21 | |
22 | compute player $id velocity x: |
23 | , player $id velocity x computed |
24 | , player velocity x #0 |
25 | . |
26 | |
27 | compute player $id velocity y, @key-state down w: |
28 | , player $id velocity y computed |
29 | , player velocity y #-250 |
30 | . |
31 | |
32 | compute player $id velocity y, @key-state down s: |
33 | , player $id velocity y computed |
34 | , player velocity y #250 |
35 | . |
36 | |
37 | compute player $id velocity y: |
38 | , player $id velocity y computed |
39 | , player velocity y #0 |
40 | . |
41 | |
42 | player $id velocity y computed, |
43 | player $id velocity x computed: |
44 | , player $id velocity computed |
45 | . |
46 | |
47 | player $id velocity computed?, @key-state up $key: . |
48 | player $id velocity computed?, @key-state down $key: . |
49 | |
50 | tick $dt? |
51 | , player $id velocity computed |
52 | , $id at x $x and y $y |
53 | , player velocity y $vy |
54 | , player velocity x $vx: |
55 | , commit player $id motion $new-x-token $new-y-token |
56 | , @expr eval $new-x-token [%1 * %2 + %3] $vx $dt $x |
57 | , @expr eval $new-y-token [%1 * %2 + %3] $vy $dt $y |
58 | . |
59 | |
60 | commit player $id motion $new-x-token $new-y-token, |
61 | @expr success $x $new-x-token, |
62 | @expr success $y $new-y-token: |
63 | , finished update for $id |
64 | , $id at x $x and y $y |
65 | , @circle $x $y #20 |
66 | . |
67 | |
68 | |
69 | |
70 | compute enemy $id velocity |
71 | , $id at x $my-x and y $my-y? |
72 | , player $player? |
73 | , $player at x $player-x and y $player-y?: |
74 | , find angle to player for enemy $id using $delta-x-token $delta-y-token |
75 | , @expr eval $delta-x-token [%1 - %2] $player-x $my-x |
76 | , @expr eval $delta-y-token [%1 - %2] $player-y $my-y |
77 | . |
78 | |
79 | find angle to player for enemy $id using $delta-x-token $delta-y-token |
80 | , @expr success $delta-x $delta-x-token |
81 | , @expr success $delta-y $delta-y-token: |
82 | , compute enemy $id motion using $angle-token |
83 | , @atan2 from $delta-x $delta-y into $angle-token |
84 | . |
85 | |
86 | compute enemy $id motion using $angle-token |
87 | , @atan2 angle $angle $angle-token: |
88 | , compute new enemy $id location using $vx-token $vy-token |
89 | , @expr eval $vx-token [cos(%1) * 200] $angle |
90 | , @expr eval $vy-token [sin(%1) * 200] $angle |
91 | . |
92 | |
93 | compute new enemy $id location using $vx-token $vy-token |
94 | , tick $dt? |
95 | , $id at x $x and y $y |
96 | , @expr success $vx $vx-token |
97 | , @expr success $vy $vy-token: |
98 | , complete enemy $id update using $x-token $y-token |
99 | , @expr eval $x-token [%1 + %2 * %3] $x $vx $dt |
100 | , @expr eval $y-token [%1 + %2 * %3] $y $vy $dt |
101 | . |
102 | |
103 | complete enemy $id update using $x-token $y-token, |
104 | @expr success $x $x-token, |
105 | @expr success $y $y-token: |
106 | , finished update for $id |
107 | , $id at x $x and y $y |
108 | , @circle $x $y #10 |
109 | . |
110 | |
111 | update $id, enemy $id?: |
112 | , compute enemy $id velocity |
113 | . |
114 | |
115 | |
116 | update $self, bullet $self? |
117 | , $self at x $x and y $y |
118 | , $self velocity is x $vx and y $vy? |
119 | , tick $dt?: |
120 | , move bullet $self using $x-token $y-token |
121 | , @expr eval $x-token [%1 + %2 * %3] $x $vx $dt |
122 | , @expr eval $y-token [%1 + %2 * %3] $y $vy $dt |
123 | . |
124 | |
125 | move bullet $self using $x-token $y-token, |
126 | @expr success $x $x-token, |
127 | @expr success $y $y-token: |
128 | , $self at x $x and y $y |
129 | , check if bullet $self should be destroyed |
130 | , finish bullet $self update |
131 | . |
132 | |
133 | check if bullet $self should be destroyed, $self at x $x and y $y?: |
134 | , is bullet $self in bounds checking |
135 | $left-bounds $right-bounds |
136 | $top-bounds $bottom-bounds |
137 | , @compare $x and #0 producing $left-bounds |
138 | , @compare $x and #800 producing $right-bounds |
139 | , @compare $y and #0 producing $top-bounds |
140 | , @compare $y and #600 producing $bottom-bounds |
141 | . |
142 | |
143 | is bullet $self in bounds checking |
144 | $left-bounds $right-bounds |
145 | $top-bounds $bottom-bounds |
146 | , @compare greater-than $left-bounds |
147 | , @compare less-than $right-bounds |
148 | , @compare greater-than $top-bounds |
149 | , @compare less-than $bottom-bounds: |
150 | bullet $self is in bounds. |
151 | |
152 | is bullet $self in bounds checking |
153 | $left-bounds $right-bounds |
154 | $top-bounds $bottom-bounds |
155 | , @compare $invalid-1 $left-bounds |
156 | , @compare $invalid-2 $right-bounds |
157 | , @compare $invalid-3 $top-bounds |
158 | , @compare $invalid-4 $bottom-bounds: |
159 | bullet $self is out of bounds. |
160 | |
161 | bullet $self is out of bounds?, @compare $ord $token:. |
162 | |
163 | finish bullet $self update, |
164 | bullet $self is out of bounds, |
165 | bullet $self, $self at x $x and y $y, $self velocity is x $vx and y $vy: . |
166 | |
167 | finish bullet $self update, |
168 | bullet $self is in bounds, |
169 | $self at x $x and y $y?: |
170 | , finished update for $self |
171 | , @circle $x $y #5 |
172 | . |
173 | |
174 | |
175 | |
176 | spawn-timer $self |
177 | , $self is at #0 seconds |
178 | , $self times out every #1 seconds |
179 | , can update for $self |
180 | . |
181 | |
182 | update $self, spawn-timer $self?, $self is at $time seconds, tick $dt?: |
183 | , update timer $self using $new-time-token |
184 | , @expr eval $new-time-token [%1 + %2] $time $dt |
185 | . |
186 | |
187 | update timer $self using $new-time-token |
188 | , $self times out every $time-out seconds? |
189 | , @expr success $time $new-time-token: |
190 | , update timer $self to $time seconds using $bounds-check |
191 | , @compare $time and $time-out producing $bounds-check |
192 | . |
193 | |
194 | update timer $self to $time seconds using $bounds-check |
195 | , @compare less-than $bounds-check: |
196 | , $self is at $time seconds, |
197 | , finished update for $self |
198 | . |
199 | |
200 | update timer $self to $time seconds using $bounds-check, |
201 | @compare $invalid $bounds-check: |
202 | , spawn enemy |
203 | , $self is at #0 seconds |
204 | , finished update for $self |
205 | . |
206 | |
207 | spawn enemy: |
208 | , compute enemy $id location using $turns-token |
209 | , @random generate $turns-token |
210 | . |
211 | |
212 | compute enemy $id location using $turns-token, |
213 | @random get $turns $turns-token: |
214 | , commit new enemy $id at x $x-token and y $y-token |
215 | , @expr eval $x-token [cos(6.28318530718 * %1) * 500 + 400] $turns |
216 | , @expr eval $y-token [sin(6.28318530718 * %1) * 500 + 300] $turns |
217 | . |
218 | |
219 | commit new enemy $id at x $x-token and y $y-token, |
220 | @expr success $x $x-token, |
221 | @expr success $y $y-token: |
222 | , enemy $id |
223 | , $id at x $x and y $y |
224 | , can update for $id |
225 | . |
226 | |
227 | |
228 | |
229 | |
230 | bullet-spawner $self |
231 | , can mouse-pressed for $self. |
232 | |
233 | mouse-pressed $self $mouse-x $mouse-y $button, bullet-spawner $self? |
234 | , player $p?, $p at x $player-x and y $player-y?: |
235 | , shoot bullet at angle using $angle-token |
236 | , compute shoot angle using $shoot-x-token $shoot-y-token |
237 | producing $angle-token |
238 | , @expr eval $shoot-x-token [%1 - %2] $mouse-x $player-x |
239 | , @expr eval $shoot-y-token [%1 - %2] $mouse-y $player-y |
240 | . |
241 | |
242 | compute shoot angle using $shoot-x-token $shoot-y-token producing $angle-token |
243 | , @expr success $shoot-x $shoot-x-token |
244 | , @expr success $shoot-y $shoot-y-token: |
245 | , @atan2 from $shoot-x $shoot-y into $angle-token |
246 | . |
247 | |
248 | shoot bullet at angle using $angle-token |
249 | , player $p?, $p at x $player-x and y $player-y? |
250 | , @atan2 angle $angle $angle-token: |
251 | , create new bullet $id using |
252 | $spawn-x-token |
253 | $spawn-y-token |
254 | $bullet-vx-token |
255 | $bullet-vy-token |
256 | , @expr eval $spawn-x-token [cos(%1) + %2] $angle $player-x |
257 | , @expr eval $spawn-y-token [sin(%1) + %2] $angle $player-y |
258 | , @expr eval $bullet-vx-token [cos(%1) * 500] $angle |
259 | , @expr eval $bullet-vy-token [sin(%1) * 500] $angle |
260 | . |
261 | |
262 | , create new bullet $id using |
263 | $spawn-x-token |
264 | $spawn-y-token |
265 | $bullet-vx-token |
266 | $bullet-vy-token |
267 | , bullet-spawner $self? |
268 | , @expr success $bullet-x $spawn-x-token |
269 | , @expr success $bullet-y $spawn-y-token |
270 | , @expr success $bullet-vx $bullet-vx-token |
271 | , @expr success $bullet-vy $bullet-vy-token: |
272 | , bullet $id |
273 | , $id at x $bullet-x and y $bullet-y |
274 | , $id velocity is x $bullet-vx and y $bullet-vy |
275 | , can update for $id |
276 | , finished mouse-pressed for $self |
277 | . |
278 | |
279 | |
280 | |
281 | tick $dt?, can update for $id: |
282 | , update $id |
283 | . |
284 | |
285 | tick $dt: prepare next tick. |
286 | |
287 | |
288 | |
289 | mouse-pressed $x $y $button, can mouse-pressed for $id: |
290 | , mouse-pressed $id $x $y $button |
291 | . |
292 | |
293 | mouse-pressed $x $y $button: . |
294 | |
295 | |
296 | |
297 | prepare next tick?, finished $event for $id: |
298 | can $event for $id. |
299 | |
300 | prepare next tick: . |
301 | |
302 |