pixie_dust 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +18 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README +16 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/game.js +9200 -0
- data/lib/corelib.js +3331 -0
- data/lib/pixie_dust/version.rb +3 -0
- data/lib/pixie_dust.rb +14 -0
- data/pixie.json +15 -0
- data/pixie_dust.gemspec +29 -0
- data/source/active_bounds.coffee +48 -0
- data/source/ageable.coffee +23 -0
- data/source/bounded.coffee +282 -0
- data/source/camera.coffee +138 -0
- data/source/camera.fade.coffee +69 -0
- data/source/camera.flash.coffee +69 -0
- data/source/camera.rotate.coffee +11 -0
- data/source/camera.shake.coffee +27 -0
- data/source/camera.zoom.coffee +25 -0
- data/source/camera.zsort.coffee +13 -0
- data/source/clampable.coffee +61 -0
- data/source/collidable.coffee +126 -0
- data/source/collision.coffee +272 -0
- data/source/collision_response.coffee +28 -0
- data/source/color.coffee +1113 -0
- data/source/color_table.coffee +2534 -0
- data/source/controllable.coffee +66 -0
- data/source/cooldown.coffee +82 -0
- data/source/debuggable.coffee +253 -0
- data/source/drawable.coffee +167 -0
- data/source/dust_emitter.coffee +36 -0
- data/source/easing.coffee +38 -0
- data/source/emitter.coffee +7 -0
- data/source/emitterable.coffee +68 -0
- data/source/engine.coffee +274 -0
- data/source/engine.collision.coffee +77 -0
- data/source/engine.data.coffee +23 -0
- data/source/engine.delay.coffee +41 -0
- data/source/engine.fps_counter.coffee +32 -0
- data/source/engine.game_state.coffee +86 -0
- data/source/engine.joysticks.coffee +47 -0
- data/source/engine.keyboard.coffee +17 -0
- data/source/engine.levels.coffee +69 -0
- data/source/engine.mouse.coffee +16 -0
- data/source/engine.selector.coffee +166 -0
- data/source/engine.stats.coffee +16 -0
- data/source/engine.tilemap.coffee +41 -0
- data/source/engine_background.coffee +32 -0
- data/source/expirable.coffee +47 -0
- data/source/flickerable.coffee +78 -0
- data/source/follow.coffee +65 -0
- data/source/framerate.coffee +42 -0
- data/source/game_object.coffee +181 -0
- data/source/game_object.effect.coffee +33 -0
- data/source/game_object.meter.coffee +191 -0
- data/source/game_over.coffee +40 -0
- data/source/game_state.coffee +67 -0
- data/source/game_state.save_state.coffee +76 -0
- data/source/game_state.single_camera.coffee +40 -0
- data/source/game_state_cameras.coffee +33 -0
- data/source/level_state.coffee +32 -0
- data/source/movable.coffee +57 -0
- data/source/oscillator.coffee +18 -0
- data/source/pixie_dust.coffee +2 -0
- data/source/resource_loader.coffee +35 -0
- data/source/rotatable.coffee +38 -0
- data/source/sprite.coffee +181 -0
- data/source/text_effect.coffee +74 -0
- data/source/text_effect.floating.coffee +22 -0
- data/source/text_screen.coffee +38 -0
- data/source/tilemap.coffee +56 -0
- data/source/timed_events.coffee +78 -0
- data/source/title_screen.coffee +38 -0
- data/source/tween.coffee +70 -0
- data/test/active_bounds.coffee +67 -0
- data/test/bounded.coffee +98 -0
- data/test/camera.coffee +29 -0
- data/test/clampable.coffee +18 -0
- data/test/collidable.coffee +51 -0
- data/test/collision.coffee +70 -0
- data/test/color.coffee +533 -0
- data/test/controllable.coffee +108 -0
- data/test/cooldown.coffee +116 -0
- data/test/debuggable.coffee +71 -0
- data/test/drawable.coffee +31 -0
- data/test/emitter.coffee +0 -0
- data/test/emitterable.coffee +15 -0
- data/test/engine.coffee +228 -0
- data/test/engine_data.coffee +12 -0
- data/test/engine_delay.coffee +14 -0
- data/test/engine_selector.coffee +100 -0
- data/test/expirable.coffee +35 -0
- data/test/flickerable.coffee +51 -0
- data/test/follow.coffee +34 -0
- data/test/game_object.coffee +78 -0
- data/test/game_object_effect.coffee +17 -0
- data/test/metered.coffee +33 -0
- data/test/movable.coffee +46 -0
- data/test/oscillator.coffee +28 -0
- data/test/resource_loader.coffee +7 -0
- data/test/rotatable.coffee +20 -0
- data/test/sprite.coffee +21 -0
- data/test/text.coffee +25 -0
- data/test/timed_events.coffee +23 -0
- data/test/tweening.coffee +18 -0
- metadata +233 -0
data/test/color.coffee
ADDED
@@ -0,0 +1,533 @@
|
|
1
|
+
equalEnough = (actual, expected, tolerance=3, message) ->
|
2
|
+
message ||= "" + expected + " within " + tolerance + " of " + actual
|
3
|
+
ok(expected + tolerance >= actual && expected - tolerance <= actual, message)
|
4
|
+
|
5
|
+
module "Color"
|
6
|
+
|
7
|
+
test "r, g, b default to 0, a defaults to 1", ->
|
8
|
+
color = Color()
|
9
|
+
|
10
|
+
equal color.r, 0
|
11
|
+
equal color.g, 0
|
12
|
+
equal color.b, 0
|
13
|
+
equal color.a, 0
|
14
|
+
|
15
|
+
test "accepts a single array of length 3", ->
|
16
|
+
color = Color([255, 1, 2])
|
17
|
+
|
18
|
+
equalEnough color.r, 255
|
19
|
+
equalEnough color.g, 1
|
20
|
+
equalEnough color.b, 2
|
21
|
+
|
22
|
+
test "accepts a single array of length 4", ->
|
23
|
+
color = Color([255, 4, 3, 0.8])
|
24
|
+
|
25
|
+
equalEnough color.r, 255
|
26
|
+
equalEnough color.g, 4
|
27
|
+
equalEnough color.b, 3
|
28
|
+
equalEnough color.a, 0.8
|
29
|
+
|
30
|
+
test "accepts an array of length 3 as the first argument and an alpha value as the second", ->
|
31
|
+
color = Color([100, 5, 3], 0.4)
|
32
|
+
|
33
|
+
equalEnough color.r, 100
|
34
|
+
equalEnough color.g, 5
|
35
|
+
equalEnough color.b, 3
|
36
|
+
equalEnough color.a, 0.4
|
37
|
+
|
38
|
+
test "accepts an array of length 4 as the first argument and an alpha value. The alpha value passed as the second argument overrides the alpha in the array", ->
|
39
|
+
color = Color([4, 20, 90, 0.1], 0.6)
|
40
|
+
|
41
|
+
equalEnough color.r, 4
|
42
|
+
equalEnough color.g, 20
|
43
|
+
equalEnough color.b, 90
|
44
|
+
equalEnough color.a, 0.6
|
45
|
+
|
46
|
+
test "accepts an rgb string as the first argument and an alpha value as the second", ->
|
47
|
+
color = Color('rgb(255, 40, 30)', 0.4)
|
48
|
+
|
49
|
+
equalEnough color.r, 255
|
50
|
+
equalEnough color.g, 40
|
51
|
+
equalEnough color.b, 30
|
52
|
+
equalEnough color.a, 0.4
|
53
|
+
|
54
|
+
test "accepts an rgba string as the first argument and an alpha value as the second. The alpha value takes precedence over the alpha from the rgba string", ->
|
55
|
+
color = Color('rgba(30, 20, 15, 0.8)', 0.35)
|
56
|
+
|
57
|
+
equal color.r, 30
|
58
|
+
equal color.g, 20
|
59
|
+
equal color.b, 15
|
60
|
+
equal color.a, 0.35
|
61
|
+
|
62
|
+
test "parses rgba(0, 0, 0, 0) correctly", ->
|
63
|
+
color = Color('rgba(0, 0, 0, 0)')
|
64
|
+
|
65
|
+
equal color.r, 0
|
66
|
+
equal color.g, 0
|
67
|
+
equal color.b, 0
|
68
|
+
equal color.a, 0
|
69
|
+
|
70
|
+
test "parses rgb(0, 0, 0) correctly", ->
|
71
|
+
color = Color('rgba(0, 0, 0)')
|
72
|
+
|
73
|
+
equal color.r, 0
|
74
|
+
equal color.g, 0
|
75
|
+
equal color.b, 0
|
76
|
+
equal color.a, 1
|
77
|
+
|
78
|
+
test "parses hsla(60, 1, 0.5, 0) correctly", ->
|
79
|
+
color = Color('hsla(60, 1, 0.5, 0)')
|
80
|
+
|
81
|
+
equal color.r, 255
|
82
|
+
equal color.g, 255
|
83
|
+
equal color.b, 0
|
84
|
+
equal color.a, 0
|
85
|
+
|
86
|
+
test "parses hsl(60, 1, 0.5) correctly", ->
|
87
|
+
color = Color('hsl(60, 1, 0.5)')
|
88
|
+
|
89
|
+
equal color.r, 255
|
90
|
+
equal color.g, 255
|
91
|
+
equal color.b, 0
|
92
|
+
equal color.a, 1
|
93
|
+
|
94
|
+
test "accepts an hsl string as the first argument and an alpha value as the second", ->
|
95
|
+
color = Color('hsl(63, 0.4, 0.3)', 0.21)
|
96
|
+
|
97
|
+
equalEnough color.r, 104
|
98
|
+
equalEnough color.g, 107
|
99
|
+
equalEnough color.b, 46
|
100
|
+
equalEnough color.a, 0.21
|
101
|
+
|
102
|
+
test "accepts an hsla string as the first argument and an alpha value as the second. The alpha value takes precedence over the hsla string alpha value", ->
|
103
|
+
color = Color('hsla(45, 0.3, 0.5, 0.1)', 0.47)
|
104
|
+
|
105
|
+
equalEnough color.r, 166
|
106
|
+
equalEnough color.g, 147
|
107
|
+
equalEnough color.b, 89
|
108
|
+
equalEnough color.a, 0.47
|
109
|
+
|
110
|
+
test "should have peridot", ->
|
111
|
+
color = Color('peridot')
|
112
|
+
|
113
|
+
equals color.toHex(), '#87b84a'
|
114
|
+
|
115
|
+
test "accepts hex value of length 3 as first argument and alpha value as second argument", ->
|
116
|
+
color = Color('#ff0', 0.5)
|
117
|
+
|
118
|
+
equalEnough color.r, 255
|
119
|
+
equalEnough color.g, 255
|
120
|
+
equalEnough color.b, 0
|
121
|
+
equalEnough color.a, 0.5
|
122
|
+
|
123
|
+
test "accepts hex value of length 4 as first argument and alpha value as second argument. The alpha value takes precedence over the alpha from the hex string.", ->
|
124
|
+
color = Color('#ef3c', 0.3)
|
125
|
+
|
126
|
+
equalEnough color.r, 238
|
127
|
+
equalEnough color.g, 255
|
128
|
+
equalEnough color.b, 51
|
129
|
+
equalEnough color.a, 0.3
|
130
|
+
|
131
|
+
test "accepts hex value of length 6 as first argument and alpha value as second argument", ->
|
132
|
+
color = Color('#de34ab', 0.27)
|
133
|
+
|
134
|
+
equalEnough color.r, 222
|
135
|
+
equalEnough color.g, 52
|
136
|
+
equalEnough color.b, 171
|
137
|
+
equalEnough color.a, 0.27
|
138
|
+
|
139
|
+
test "accepts hex value of length 8 as first argument and alpha value as second argument. Alpha value takes precedence over hex alpha.", ->
|
140
|
+
color = Color('#ab45cd', 0.59)
|
141
|
+
|
142
|
+
equalEnough color.r, 171
|
143
|
+
equalEnough color.g, 69
|
144
|
+
equalEnough color.b, 205
|
145
|
+
equalEnough color.a, 0.59
|
146
|
+
|
147
|
+
test "accepts hex string of length 3", ->
|
148
|
+
color = Color('#df2')
|
149
|
+
|
150
|
+
equalEnough color.r, 221
|
151
|
+
equalEnough color.g, 255
|
152
|
+
equalEnough color.b, 34
|
153
|
+
equalEnough color.a, 1.0
|
154
|
+
|
155
|
+
test "accepts hex string of length 4", ->
|
156
|
+
color = Color('#c987')
|
157
|
+
|
158
|
+
equalEnough color.r, 204
|
159
|
+
equalEnough color.g, 153
|
160
|
+
equalEnough color.b, 136
|
161
|
+
equalEnough color.a.toFixed(2), 0.47
|
162
|
+
|
163
|
+
test "accepts hex string of length 6", ->
|
164
|
+
color = Color('#cdef12')
|
165
|
+
|
166
|
+
equalEnough color.r, 205
|
167
|
+
equalEnough color.g, 239
|
168
|
+
equalEnough color.b, 18
|
169
|
+
equalEnough color.a, 1.0
|
170
|
+
|
171
|
+
test "accepts hex string of length 8", ->
|
172
|
+
color = Color('#ef1234af')
|
173
|
+
|
174
|
+
equalEnough color.r, 239
|
175
|
+
equalEnough color.g, 18
|
176
|
+
equalEnough color.b, 52
|
177
|
+
equalEnough color.a.toFixed(2), 0.69
|
178
|
+
|
179
|
+
test "accepts 3 numeric values", ->
|
180
|
+
color = Color(34, 54, 39)
|
181
|
+
|
182
|
+
equalEnough color.r, 34
|
183
|
+
equalEnough color.g, 54
|
184
|
+
equalEnough color.b, 39
|
185
|
+
equalEnough color.a, 1.0
|
186
|
+
|
187
|
+
test "accepts 4 numeric values", ->
|
188
|
+
color = Color(23, 43, 100, 0.32)
|
189
|
+
|
190
|
+
equalEnough color.r, 23
|
191
|
+
equalEnough color.g, 43
|
192
|
+
equalEnough color.b, 100
|
193
|
+
equalEnough color.a, 0.32
|
194
|
+
|
195
|
+
test "accepts a color object", ->
|
196
|
+
color = Color(23, 54, 49, 1)
|
197
|
+
|
198
|
+
newColor = Color(color)
|
199
|
+
|
200
|
+
equal newColor.r, 23
|
201
|
+
equal newColor.g, 54
|
202
|
+
equal newColor.b, 49
|
203
|
+
equal newColor.a, 1
|
204
|
+
|
205
|
+
test "invalid color throws error", ->
|
206
|
+
raises ->
|
207
|
+
Color("A Fake Color")
|
208
|
+
|
209
|
+
test "#copy", ->
|
210
|
+
color = Color(123, 231, 2)
|
211
|
+
copiedColor = color.copy()
|
212
|
+
|
213
|
+
ok color.equal(copiedColor)
|
214
|
+
ok color != copiedColor
|
215
|
+
|
216
|
+
test "#equal", ->
|
217
|
+
color1 = Color(255, 255, 255, 1)
|
218
|
+
color2 = Color([255, 255, 255])
|
219
|
+
|
220
|
+
ok color1.equal(color2)
|
221
|
+
|
222
|
+
test "#toString", ->
|
223
|
+
noAlpha = Color(30, 40, 23)
|
224
|
+
withAlpha = Color(29, 49, 50, 0.45)
|
225
|
+
decimalValues = Color(34.7, 52.2, 50.1, 0.45)
|
226
|
+
|
227
|
+
equal noAlpha.toString(), "rgba(30, 40, 23, 1)"
|
228
|
+
equal withAlpha.toString(), "rgba(29, 49, 50, 0.45)"
|
229
|
+
equal decimalValues.toString(), "rgba(35, 52, 50, 0.45)"
|
230
|
+
|
231
|
+
test "#toHex", ->
|
232
|
+
color = Color(23, 45, 100)
|
233
|
+
|
234
|
+
equal color.toHex(), "#172d64"
|
235
|
+
equal color.toHex(false), "172d64"
|
236
|
+
|
237
|
+
test "#toHsl", ->
|
238
|
+
color = Color(45, 29, 20)
|
239
|
+
|
240
|
+
hsl = color.toHsl()
|
241
|
+
|
242
|
+
equalEnough hsl[0].round(), 22
|
243
|
+
equalEnough hsl[1].toFixed(2), 0.38
|
244
|
+
equalEnough hsl[2].toFixed(2), 0.13
|
245
|
+
equalEnough hsl[3], 1.0
|
246
|
+
|
247
|
+
test "#hue", ->
|
248
|
+
color = Color(20, 45, 49)
|
249
|
+
color.hue(60)
|
250
|
+
|
251
|
+
equalEnough color.r, 51
|
252
|
+
equalEnough color.g, 51
|
253
|
+
equalEnough color.b, 21
|
254
|
+
equalEnough color.a, 1.0
|
255
|
+
|
256
|
+
test "#saturation", ->
|
257
|
+
color = Color(40, 39, 29)
|
258
|
+
color.saturation(0.3)
|
259
|
+
|
260
|
+
equalEnough color.r, 46
|
261
|
+
equalEnough color.g, 45
|
262
|
+
equalEnough color.b, 25
|
263
|
+
equalEnough color.a, 1.0
|
264
|
+
|
265
|
+
test "#lightness", ->
|
266
|
+
color = Color(4, 200, 49)
|
267
|
+
color.lightness(0.47)
|
268
|
+
|
269
|
+
equalEnough color.r, 5
|
270
|
+
equalEnough color.g, 235
|
271
|
+
equalEnough color.b, 58
|
272
|
+
equalEnough color.a, 1.0
|
273
|
+
|
274
|
+
test "#shiftHue", ->
|
275
|
+
color = Color(34, 54, 239).shiftHue(20)
|
276
|
+
|
277
|
+
equalEnough color.r, 84
|
278
|
+
equalEnough color.g, 37
|
279
|
+
equalEnough color.b, 239
|
280
|
+
equalEnough color.a, 1.0
|
281
|
+
|
282
|
+
test "#shiftHue$", ->
|
283
|
+
color = Color(34, 54, 239)
|
284
|
+
|
285
|
+
color.shiftHue$(60)
|
286
|
+
|
287
|
+
equalEnough color.r, 218
|
288
|
+
equalEnough color.g, 37
|
289
|
+
equalEnough color.b, 239
|
290
|
+
equalEnough color.a, 1.0
|
291
|
+
|
292
|
+
test "#channels", ->
|
293
|
+
no_alpha = Color(128, 2, 50)
|
294
|
+
|
295
|
+
no_alpha_channels = no_alpha.channels()
|
296
|
+
|
297
|
+
equal no_alpha_channels[0], 128
|
298
|
+
equal no_alpha_channels[1], 2
|
299
|
+
equal no_alpha_channels[2], 50
|
300
|
+
equal no_alpha_channels[3], 1
|
301
|
+
|
302
|
+
alpha = Color(128, 2, 50, 0.3)
|
303
|
+
|
304
|
+
alpha_channels = alpha.channels()
|
305
|
+
|
306
|
+
equal alpha_channels[0], 128
|
307
|
+
equal alpha_channels[1], 2
|
308
|
+
equal alpha_channels[2], 50
|
309
|
+
equal alpha_channels[3], 0.3
|
310
|
+
|
311
|
+
test "#complement", ->
|
312
|
+
color = Color(10, 30, 50).complement()
|
313
|
+
|
314
|
+
equalEnough color.r, 51
|
315
|
+
equalEnough color.g, 31
|
316
|
+
equalEnough color.b, 10
|
317
|
+
equalEnough color.a, 1.0
|
318
|
+
|
319
|
+
test "#complement$", ->
|
320
|
+
color = Color(10, 30, 50)
|
321
|
+
|
322
|
+
color.complement$()
|
323
|
+
|
324
|
+
equalEnough color.r, 51
|
325
|
+
equalEnough color.g, 31
|
326
|
+
equalEnough color.b, 10
|
327
|
+
equalEnough color.a, 1.0
|
328
|
+
|
329
|
+
test "#grayscale", ->
|
330
|
+
color = Color(30, 40, 29).grayscale()
|
331
|
+
|
332
|
+
equalEnough color.r, 35
|
333
|
+
equalEnough color.g, 35
|
334
|
+
equalEnough color.b, 35
|
335
|
+
equalEnough color.a, 1.0
|
336
|
+
|
337
|
+
test "#grayscale$", ->
|
338
|
+
color = Color(30, 40, 29)
|
339
|
+
|
340
|
+
color.grayscale$()
|
341
|
+
|
342
|
+
equalEnough color.r, 35
|
343
|
+
equalEnough color.g, 35
|
344
|
+
equalEnough color.b, 35
|
345
|
+
equalEnough color.a, 1.0
|
346
|
+
|
347
|
+
test "#saturate", ->
|
348
|
+
color = Color(100, 200, 150).saturate(0.3)
|
349
|
+
|
350
|
+
equalEnough color.r, 69
|
351
|
+
equalEnough color.g, 232
|
352
|
+
equalEnough color.b, 150
|
353
|
+
equalEnough color.a, 1.0
|
354
|
+
|
355
|
+
test "#saturate$", ->
|
356
|
+
color = Color(100, 200, 150)
|
357
|
+
|
358
|
+
color.saturate$(0.3)
|
359
|
+
|
360
|
+
equalEnough color.r, 69
|
361
|
+
equalEnough color.g, 232
|
362
|
+
equalEnough color.b, 150
|
363
|
+
equalEnough color.a, 1.0
|
364
|
+
|
365
|
+
test "#desaturate", ->
|
366
|
+
color = Color(69, 232, 150).desaturate(0.3)
|
367
|
+
|
368
|
+
equalEnough color.r, 100
|
369
|
+
equalEnough color.g, 200
|
370
|
+
equalEnough color.b, 150
|
371
|
+
equalEnough color.a, 1.0
|
372
|
+
|
373
|
+
test "#desaturate$", ->
|
374
|
+
color = Color(69, 232, 150)
|
375
|
+
|
376
|
+
color.desaturate$(0.3)
|
377
|
+
|
378
|
+
equalEnough color.r, 100
|
379
|
+
equalEnough color.g, 200
|
380
|
+
equalEnough color.b, 150
|
381
|
+
equalEnough color.a, 1.0
|
382
|
+
|
383
|
+
test "#darken", ->
|
384
|
+
color = Color(45, 64, 39).darken(0.1)
|
385
|
+
|
386
|
+
equalEnough color.r, 22
|
387
|
+
equalEnough color.g, 32
|
388
|
+
equalEnough color.b, 19
|
389
|
+
equalEnough color.a, 1.0
|
390
|
+
|
391
|
+
test "#darken$", ->
|
392
|
+
color = Color(45, 64, 39)
|
393
|
+
|
394
|
+
color.darken$(0.1)
|
395
|
+
|
396
|
+
equalEnough color.r, 22
|
397
|
+
equalEnough color.g, 32
|
398
|
+
equalEnough color.b, 19
|
399
|
+
equalEnough color.a, 1.0
|
400
|
+
|
401
|
+
test "#lighten", ->
|
402
|
+
color = Color(22, 32, 19).lighten(0.1)
|
403
|
+
|
404
|
+
equalEnough color.r, 45
|
405
|
+
equalEnough color.g, 64
|
406
|
+
equalEnough color.b, 39
|
407
|
+
equalEnough color.a, 1.0
|
408
|
+
|
409
|
+
test "#lighten$", ->
|
410
|
+
color = Color(22, 32, 19)
|
411
|
+
|
412
|
+
color.lighten$(0.1)
|
413
|
+
|
414
|
+
equalEnough color.r, 45
|
415
|
+
equalEnough color.g, 64
|
416
|
+
equalEnough color.b, 39
|
417
|
+
equalEnough color.a, 1.0
|
418
|
+
|
419
|
+
test "#mixWith", ->
|
420
|
+
color1 = Color(50, 40, 60, 0.3)
|
421
|
+
color2 = Color(10, 5, 16, 0.2)
|
422
|
+
|
423
|
+
mixedColor = color1.mixWith(color2)
|
424
|
+
|
425
|
+
equalEnough mixedColor.r, 30
|
426
|
+
equalEnough mixedColor.g, (45 / 2).round()
|
427
|
+
equalEnough mixedColor.b, (76 / 2).round()
|
428
|
+
equalEnough mixedColor.a, 0.5 / 2
|
429
|
+
|
430
|
+
weightedMixedColor = color1.mixWith(color2, 0.1)
|
431
|
+
|
432
|
+
equalEnough weightedMixedColor.r, ((50 * 0.1) + (10 * 0.9)).round()
|
433
|
+
equalEnough weightedMixedColor.g, ((40 * 0.1) + (5 * 0.9)).round()
|
434
|
+
equalEnough weightedMixedColor.b, ((60 * 0.1) + (16 * 0.9)).round()
|
435
|
+
equalEnough weightedMixedColor.a, (0.3 * 0.1) + (0.2 * 0.9)
|
436
|
+
|
437
|
+
test "#mixWith$", ->
|
438
|
+
color1 = Color(50, 40, 60, 0.3)
|
439
|
+
color2 = Color(10, 5, 16, 0.2)
|
440
|
+
|
441
|
+
color3 = Color(50, 40, 60, 0.3)
|
442
|
+
|
443
|
+
color1.mixWith$(color2)
|
444
|
+
|
445
|
+
equalEnough color1.r, 30
|
446
|
+
equalEnough color1.g, (45 / 2).round()
|
447
|
+
equalEnough color1.b, (76 / 2).round()
|
448
|
+
equalEnough color1.a, 0.5 / 2
|
449
|
+
|
450
|
+
color3.mixWith$(color2, 0.1)
|
451
|
+
|
452
|
+
equalEnough color3.r, ((50 * 0.1) + (10 * 0.9)).round()
|
453
|
+
equalEnough color3.g, ((40 * 0.1) + (5 * 0.9)).round()
|
454
|
+
equalEnough color3.b, ((60 * 0.1) + (16 * 0.9)).round()
|
455
|
+
equalEnough color3.a, (0.3 * 0.1) + (0.2 * 0.9)
|
456
|
+
|
457
|
+
test "Color.random", ->
|
458
|
+
color = Color.random()
|
459
|
+
|
460
|
+
ok 0 <= color.r <= 255
|
461
|
+
ok 0 <= color.g <= 255
|
462
|
+
ok 0 <= color.b <= 255
|
463
|
+
equalEnough color.a, 1.0
|
464
|
+
|
465
|
+
test "Color.mix", ->
|
466
|
+
mixedColor = Color.mix(
|
467
|
+
Color("red"),
|
468
|
+
Color("sky blue")
|
469
|
+
)
|
470
|
+
|
471
|
+
equalEnough mixedColor.r, 173
|
472
|
+
equalEnough mixedColor.g, 94
|
473
|
+
equalEnough mixedColor.b, 127
|
474
|
+
equalEnough mixedColor.a, 1
|
475
|
+
|
476
|
+
weightedMixedColor = Color.mix(Color(0, 255, 0, 1), Color(255, 0, 255, 0.6), 0.1)
|
477
|
+
|
478
|
+
equalEnough weightedMixedColor.r, ((0 * 0.1) + (255 * 0.9)).round()
|
479
|
+
equalEnough weightedMixedColor.g, ((255 * 0.1) + (0 * 0.9)).round()
|
480
|
+
equalEnough weightedMixedColor.b, ((0 * 0.1) + (255 * 0.9)).round()
|
481
|
+
equalEnough weightedMixedColor.a, (1 * 0.1) + (0.6 * 0.9)
|
482
|
+
|
483
|
+
test "accepts named colors", ->
|
484
|
+
white = Color("white")
|
485
|
+
|
486
|
+
equalEnough white.r, 255
|
487
|
+
equalEnough white.g, 255
|
488
|
+
equalEnough white.b, 255
|
489
|
+
equalEnough white.a, 1.0
|
490
|
+
|
491
|
+
piPink = Color("Paul Irish Pink")
|
492
|
+
|
493
|
+
equalEnough piPink.r, 255
|
494
|
+
equalEnough piPink.g, 94
|
495
|
+
equalEnough piPink.b, 153
|
496
|
+
equalEnough piPink.a, 1.0
|
497
|
+
|
498
|
+
test "#transparentize", ->
|
499
|
+
color = Color(0, 0, 0, 1)
|
500
|
+
|
501
|
+
transparentColor = color.transparentize(0.5)
|
502
|
+
|
503
|
+
equal color.a, 1
|
504
|
+
equal transparentColor.a, 0.5
|
505
|
+
|
506
|
+
test "#transparentize$", ->
|
507
|
+
color = Color(0, 0, 0, 1)
|
508
|
+
|
509
|
+
equal color.a, 1
|
510
|
+
|
511
|
+
color.transparentize$(0.5)
|
512
|
+
|
513
|
+
equal color.a, 0.5
|
514
|
+
|
515
|
+
test "#opacify", ->
|
516
|
+
color = Color(0, 0, 0, 0)
|
517
|
+
|
518
|
+
opaqueColor = color.opacify(0.5)
|
519
|
+
|
520
|
+
equal color.a, 0
|
521
|
+
equal opaqueColor.a, 0.5
|
522
|
+
|
523
|
+
test "#opacify$", ->
|
524
|
+
color = Color(0, 0, 0, 0)
|
525
|
+
|
526
|
+
equal color.a, 0
|
527
|
+
|
528
|
+
color.opacify$(0.5)
|
529
|
+
|
530
|
+
equal color.a, 0.5
|
531
|
+
|
532
|
+
module()
|
533
|
+
|
@@ -0,0 +1,108 @@
|
|
1
|
+
module "Controllable"
|
2
|
+
|
3
|
+
# sets up player object before each test
|
4
|
+
QUnit.testStart = ->
|
5
|
+
window.player = GameObject
|
6
|
+
x: 10
|
7
|
+
y: 20
|
8
|
+
width: 10
|
9
|
+
height: 20
|
10
|
+
speed: 3
|
11
|
+
|
12
|
+
player.include Controllable
|
13
|
+
|
14
|
+
# Mock the keydown object
|
15
|
+
window.keydown = {}
|
16
|
+
|
17
|
+
test "should update velocity while left is held", ->
|
18
|
+
window.keydown.left = true
|
19
|
+
|
20
|
+
player.update()
|
21
|
+
|
22
|
+
equals player.I.velocity.x, -3
|
23
|
+
|
24
|
+
window.keydown.left = false
|
25
|
+
|
26
|
+
player.update()
|
27
|
+
|
28
|
+
equals player.I.velocity.x, 0
|
29
|
+
|
30
|
+
test "should move player right while key is pressed", ->
|
31
|
+
window.keydown.right = true
|
32
|
+
|
33
|
+
player.update()
|
34
|
+
|
35
|
+
equals player.I.velocity.x, 3
|
36
|
+
|
37
|
+
window.keydown.right = false
|
38
|
+
|
39
|
+
player.update()
|
40
|
+
|
41
|
+
equals player.I.velocity.x, 0
|
42
|
+
|
43
|
+
test "should move player up while key is pressed", ->
|
44
|
+
window.keydown.up = true
|
45
|
+
|
46
|
+
player.update()
|
47
|
+
|
48
|
+
equals player.I.velocity.y, -3
|
49
|
+
|
50
|
+
window.keydown.up = false
|
51
|
+
|
52
|
+
player.update()
|
53
|
+
|
54
|
+
equals player.I.velocity.y, 0
|
55
|
+
|
56
|
+
test "should move player down while key is pressed", ->
|
57
|
+
window.keydown.down = true
|
58
|
+
|
59
|
+
player.update()
|
60
|
+
|
61
|
+
equals player.I.velocity.y, 3
|
62
|
+
|
63
|
+
window.keydown.down = false
|
64
|
+
|
65
|
+
player.update()
|
66
|
+
|
67
|
+
equals player.I.velocity.y, 0
|
68
|
+
|
69
|
+
test "should handle moving diagonally", ->
|
70
|
+
window.keydown.left = true
|
71
|
+
window.keydown.up = true
|
72
|
+
|
73
|
+
player.update()
|
74
|
+
|
75
|
+
equals player.I.velocity.x, Point(-1, -1).norm().x * player.I.speed
|
76
|
+
equals player.I.velocity.y, Point(-1, -1).norm().y * player.I.speed
|
77
|
+
|
78
|
+
test "should handle tracking facing direction diagonally", ->
|
79
|
+
window.keydown.left = true
|
80
|
+
window.keydown.up = true
|
81
|
+
|
82
|
+
player.update()
|
83
|
+
|
84
|
+
equals player.I.facing.x, Point(-1, -1).norm().x
|
85
|
+
equals player.I.facing.y, Point(-1, -1).norm().y
|
86
|
+
|
87
|
+
window.keydown.left = false
|
88
|
+
window.keydown.up = false
|
89
|
+
|
90
|
+
equals player.I.facing.x, Point(-1, -1).norm().x
|
91
|
+
equals player.I.facing.y, Point(-1, -1).norm().y
|
92
|
+
|
93
|
+
test "should correctly track facing direction", ->
|
94
|
+
ok player.I.facing.equal(Point(1, 0))
|
95
|
+
|
96
|
+
window.keydown.left = true
|
97
|
+
|
98
|
+
player.update()
|
99
|
+
|
100
|
+
ok player.I.facing.equal(Point(-1, 0))
|
101
|
+
|
102
|
+
window.keydown.left = false
|
103
|
+
|
104
|
+
player.update()
|
105
|
+
|
106
|
+
ok player.I.facing.equal(Point(-1, 0))
|
107
|
+
|
108
|
+
module()
|