@turbowarp/paper 0.12.202407161743

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (139) hide show
  1. package/AUTHORS.md +18 -0
  2. package/CHANGELOG.md +701 -0
  3. package/LICENSE.txt +23 -0
  4. package/README.md +381 -0
  5. package/dist/node/canvas.js +66 -0
  6. package/dist/node/extend.js +156 -0
  7. package/dist/node/self.js +58 -0
  8. package/dist/node/xml.js +40 -0
  9. package/dist/paper-core.js +15805 -0
  10. package/dist/paper-full.js +17574 -0
  11. package/examples/Animated/AnimatedStar.html +53 -0
  12. package/examples/Animated/BooleanOperations.html +115 -0
  13. package/examples/Animated/CandyCrash.html +151 -0
  14. package/examples/Animated/Extruded.html +50 -0
  15. package/examples/Animated/Lines.html +53 -0
  16. package/examples/Animated/Smoothing.html +70 -0
  17. package/examples/Animated/Space.html +86 -0
  18. package/examples/Animated/SpaceUsingShapes.html +79 -0
  19. package/examples/Games/Paperoids.html +569 -0
  20. package/examples/JSON/Circle Testing.html +34 -0
  21. package/examples/JSON/Compound Path.html +25 -0
  22. package/examples/JSON/Empty Path Testing.html +31 -0
  23. package/examples/JSON/Gradients.html +34 -0
  24. package/examples/JSON/Group Transform.html +28 -0
  25. package/examples/JSON/Line Testing.html +44 -0
  26. package/examples/JSON/Random Path Testing.html +42 -0
  27. package/examples/JSON/Raster.html +29 -0
  28. package/examples/JSON/Rect and Attribute Testing.html +56 -0
  29. package/examples/JSON/Rotated Primitives.html +55 -0
  30. package/examples/JSON/Selection.html +43 -0
  31. package/examples/JSON/Shapes.html +54 -0
  32. package/examples/JSON/Symbols.html +30 -0
  33. package/examples/JSON/Text Testing.html +38 -0
  34. package/examples/JSON/Tiger.html +19 -0
  35. package/examples/JSON/Transform Test 1.html +32 -0
  36. package/examples/JSON/Transform Test 2.html +30 -0
  37. package/examples/Node.js/AnimatedStar.js +52 -0
  38. package/examples/Node.js/BooleanOperations.js +36 -0
  39. package/examples/Node.js/JSONtoPDF.js +20 -0
  40. package/examples/Node.js/Raster.js +32 -0
  41. package/examples/Node.js/RasterRemote.js +33 -0
  42. package/examples/Node.js/SvgExport.js +52 -0
  43. package/examples/Node.js/SvgImport.js +23 -0
  44. package/examples/Node.js/Tadpoles.js +16 -0
  45. package/examples/Node.js/Tadpoles.pjs +278 -0
  46. package/examples/Node.js/in.json +1 -0
  47. package/examples/Node.js/in.svg +16 -0
  48. package/examples/Paperjs.org/BooleanOperattions.html +115 -0
  49. package/examples/Paperjs.org/BouncingBalls.html +103 -0
  50. package/examples/Paperjs.org/Chain.html +54 -0
  51. package/examples/Paperjs.org/DivisionRaster.html +72 -0
  52. package/examples/Paperjs.org/FutureSplash.html +122 -0
  53. package/examples/Paperjs.org/HitTesting.html +103 -0
  54. package/examples/Paperjs.org/InteractiveTiger.html +777 -0
  55. package/examples/Paperjs.org/MetaBalls.html +132 -0
  56. package/examples/Paperjs.org/NyanRainbow.html +202 -0
  57. package/examples/Paperjs.org/PathIntersections.html +76 -0
  58. package/examples/Paperjs.org/Qbertify.html +146 -0
  59. package/examples/Paperjs.org/RadialRainbows.html +80 -0
  60. package/examples/Paperjs.org/RoundedRectangles.html +41 -0
  61. package/examples/Paperjs.org/SatieLikedToDraw.html +140 -0
  62. package/examples/Paperjs.org/Simplify.html +63 -0
  63. package/examples/Paperjs.org/SpiralRaster.html +120 -0
  64. package/examples/Paperjs.org/Tadpoles.html +283 -0
  65. package/examples/Paperjs.org/Voronoi.html +134 -0
  66. package/examples/Rasters/PhyllotaxisRaster.html +96 -0
  67. package/examples/Rasters/Raster.html +34 -0
  68. package/examples/Rasters/RotationRaster.html +44 -0
  69. package/examples/Rasters/Smoothing.html +48 -0
  70. package/examples/SVG Export/Circle Testing.html +32 -0
  71. package/examples/SVG Export/Clipping.html +17 -0
  72. package/examples/SVG Export/Compound Path.html +22 -0
  73. package/examples/SVG Export/Empty Path Testing.html +28 -0
  74. package/examples/SVG Export/Gradients.html +52 -0
  75. package/examples/SVG Export/Group Transform.html +25 -0
  76. package/examples/SVG Export/Line Testing.html +41 -0
  77. package/examples/SVG Export/Random Path Testing.html +39 -0
  78. package/examples/SVG Export/Raster.html +21 -0
  79. package/examples/SVG Export/Rect and Attribute Testing.html +53 -0
  80. package/examples/SVG Export/Rotated Primitives.html +80 -0
  81. package/examples/SVG Export/Shapes.html +58 -0
  82. package/examples/SVG Export/Symbols.html +27 -0
  83. package/examples/SVG Export/Text Testing.html +45 -0
  84. package/examples/SVG Export/Tiger.html +23 -0
  85. package/examples/SVG Export/Transform Test 1.html +29 -0
  86. package/examples/SVG Export/Transform Test 2.html +27 -0
  87. package/examples/SVG Import/Arcs.html +78 -0
  88. package/examples/SVG Import/Butterfly.html +223 -0
  89. package/examples/SVG Import/Circle and Ellipse Testing.html +26 -0
  90. package/examples/SVG Import/Clipping.html +100 -0
  91. package/examples/SVG Import/From File.html +30 -0
  92. package/examples/SVG Import/Gradient.html +138 -0
  93. package/examples/SVG Import/Gradients.html +30 -0
  94. package/examples/SVG Import/Inkscape Pivot.html +52 -0
  95. package/examples/SVG Import/Inkscape.html +88 -0
  96. package/examples/SVG Import/Line Testing.html +24 -0
  97. package/examples/SVG Import/MoreGradients.html +107 -0
  98. package/examples/SVG Import/Multiple Paths Test 1.html +42 -0
  99. package/examples/SVG Import/Multiple Paths Test 2.html +33 -0
  100. package/examples/SVG Import/Nested Groups Test.html +78 -0
  101. package/examples/SVG Import/Polybezier.html +43 -0
  102. package/examples/SVG Import/Rect Testing.html +25 -0
  103. package/examples/SVG Import/Symbols.html +24 -0
  104. package/examples/SVG Import/Testing.html +40 -0
  105. package/examples/SVG Import/Text Testing.html +19 -0
  106. package/examples/SVG Import/Tiger.html +742 -0
  107. package/examples/SVG Import/Transform Testing.html +22 -0
  108. package/examples/SVG Import/Viewbox.html +38 -0
  109. package/examples/Scripts/Arcs.html +39 -0
  110. package/examples/Scripts/BlendModes.html +77 -0
  111. package/examples/Scripts/BooleanOperations.html +937 -0
  112. package/examples/Scripts/CompoundPath.html +19 -0
  113. package/examples/Scripts/CurveTimeParameterization.html +61 -0
  114. package/examples/Scripts/HslColor.html +53 -0
  115. package/examples/Scripts/PathStructure.html +82 -0
  116. package/examples/Scripts/PathTangents.html +73 -0
  117. package/examples/Scripts/Resize.html +42 -0
  118. package/examples/Scripts/RoundRectangle.html +28 -0
  119. package/examples/Scripts/Shapes.html +54 -0
  120. package/examples/Scripts/StrokeBounds.html +101 -0
  121. package/examples/Scripts/StrokeScaling.html +65 -0
  122. package/examples/Tools/BezierTool.html +90 -0
  123. package/examples/Tools/Circles.html +28 -0
  124. package/examples/Tools/Clouds.html +35 -0
  125. package/examples/Tools/DrippingBrush.html +73 -0
  126. package/examples/Tools/FancyBrush.html +82 -0
  127. package/examples/Tools/Grid.html +44 -0
  128. package/examples/Tools/MultiLines.html +44 -0
  129. package/examples/Tools/MultipleTools.html +44 -0
  130. package/examples/Tools/PathEditing.html +95 -0
  131. package/examples/Tools/SquareRounded.html +76 -0
  132. package/examples/Tools/Stars.html +38 -0
  133. package/examples/Tools/Vektor.html +200 -0
  134. package/examples/Tools/Wave.html +50 -0
  135. package/examples/Tools/WormFarm.html +88 -0
  136. package/examples/Worker/Main.html +53 -0
  137. package/examples/Worker/Worker.js +14 -0
  138. package/examples/css/style.css +12 -0
  139. package/package.json +109 -0
@@ -0,0 +1,569 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
6
+ <title>Paperoids</title>
7
+ <script type="text/javascript" src="../../dist/paper-full.js"></script>
8
+ <script type="text/paperscript" canvas="canvas">
9
+
10
+ //
11
+ //
12
+ // Paperoids - an Asteroids clone for paper.js
13
+ //
14
+ // Sorry nerds, no enemy ships or sound just yet.
15
+ //
16
+ // Version: 1.2.1
17
+ // Author: David Hirmes (@hirmes)
18
+ // Date: 2011-08-09
19
+ //
20
+ // Revision History:
21
+ // 1.0 - 2011-07-13 - Initial release
22
+ // 1.1 - 2011-07-13 - Optimizations by Jonathan Puckey (@jonathanpuckey)
23
+ // 1.2 - 2011-07-16 - Refactored with closures (@jonathanpuckey)
24
+ // 1.2.1- 2011-08-09 - bug fixes
25
+ //
26
+
27
+ var presets = {
28
+ speed: 0.2,
29
+ maxRockSpeed: 4.5,
30
+ rockCount: 6,
31
+ lives: 3,
32
+ freeShipScore: 10000,
33
+ freeShipIncrement: 10000
34
+ };
35
+
36
+ function initialize() {
37
+ Rocks.add(presets.rockCount);
38
+ Score.update();
39
+ Lives.initialize();
40
+ }
41
+
42
+ function onKeyUp(event) {
43
+ if (event.key == 'space') {
44
+ Ship.moveTo(Point.random() * view.size);
45
+ Ship.stop();
46
+ }
47
+ if (event.key == 'z') {
48
+ Ship.fire();
49
+ }
50
+ // Show stats:
51
+ if (event.key == 'f') {
52
+ var stats = document.getElementById('stats');
53
+ if (stats) {
54
+ stats.style.display = (stats.style.display == 'block')
55
+ ? 'none' : 'block';
56
+ }
57
+ }
58
+ }
59
+
60
+ function onFrame() {
61
+ Bullets.move();
62
+ Rocks.iterateExplosions();
63
+ Ship.checkCollisions();
64
+ if (Key.isDown('left')) {
65
+ Ship.turnLeft();
66
+ }
67
+ if (Key.isDown('right')) {
68
+ Ship.turnRight();
69
+ }
70
+ if (Key.isDown('up')) {
71
+ Ship.thrust();
72
+ } else {
73
+ Ship.coast();
74
+ }
75
+ Ship.move();
76
+ }
77
+
78
+ project.currentStyle.strokeColor = 'white';
79
+
80
+ var Game = {
81
+ roundDelay: false,
82
+ over: function() {
83
+ document.getElementById('gameover').style.display = 'block';
84
+ },
85
+ newRound: function() {
86
+ Game.roundDelay = false;
87
+ Rocks.add(presets.rockCount);
88
+ },
89
+ // Stats.js by Mr. Doob - https://github.com/mrdoob/stats.js
90
+ };
91
+
92
+ var assets = {
93
+ destroyedShip: new function() {
94
+ var group = new Group(
95
+ new Path([-10, -8], [10, 0]),
96
+ new Path([10, 0], [-10, 8]),
97
+ new Path([-8, 4], [-8, -4])
98
+ );
99
+ group.visible = false;
100
+ return group;
101
+ },
102
+ explosion: new function() {
103
+ var explosionPath = new Path.Circle(new Point(), 1);
104
+ explosionPath.fillColor = 'white';
105
+ explosionPath.strokeColor = null;
106
+ return new SymbolDefinition(explosionPath);
107
+ }
108
+ };
109
+
110
+ var Ship = new function() {
111
+ var path = new Path([-10, -8], [10, 0], [-10, 8], [-8, 4], [-8, -4]);
112
+ path.closed = true;
113
+ var thrust = new Path([-8, -4], [-14, 0], [-8, 4]);
114
+ var group = new Group(path, thrust);
115
+ group.position = view.bounds.center;
116
+ return {
117
+ item: group,
118
+
119
+ angle: 0,
120
+
121
+ vector: new Point({
122
+ angle: 0.2,
123
+ length: 1
124
+ }),
125
+
126
+ turnLeft: function() {
127
+ group.rotate(-3);
128
+ this.angle -= 3;
129
+ },
130
+
131
+ turnRight: function() {
132
+ group.rotate(3);
133
+ this.angle += 3;
134
+ },
135
+
136
+ thrust: function() {
137
+ thrust.visible = true;
138
+ this.vector += new Point({
139
+ angle: this.angle,
140
+ length: presets.speed
141
+ });
142
+ if (this.vector.length > 8) {
143
+ this.vector.length = 8;
144
+ }
145
+ },
146
+
147
+ stop: function() {
148
+ this.vector.length = 0;
149
+ },
150
+
151
+ fire: function() {
152
+ if (!this.dying)
153
+ Bullets.fire(this.item.position, this.angle);
154
+ },
155
+
156
+ coast: function() {
157
+ thrust.visible = false;
158
+ this.vector *= .992;
159
+ },
160
+
161
+ move: function() {
162
+ group.position += this.vector;
163
+ keepInView(group);
164
+ },
165
+
166
+ moveTo: function(position) {
167
+ group.position = position;
168
+ keepInView(group);
169
+ },
170
+
171
+ destroy: function() {
172
+ this.destroyedShip = assets.destroyedShip.clone();
173
+ this.destroyedShip.position = this.item.position;
174
+ this.destroyedShip.visible = true;
175
+ this.item.visible = false;
176
+ this.stop();
177
+ this.item.position = view.center;
178
+ this.dying = true;
179
+ },
180
+
181
+ destroyed: function() {
182
+ this.item.visible = true;
183
+ this.stop();
184
+ this.item.position = view.center;
185
+ this.dying = false;
186
+ this.destroyedShip.visible = false;
187
+ },
188
+
189
+ checkCollisions: function() {
190
+ var crashRock;
191
+
192
+ // move rocks and do a hit-test
193
+ // between bounding rect of rocks and ship
194
+ for (var i = 0; i < Rocks.children.length; i++) {
195
+ var rock = Rocks.children[i];
196
+ rock.position += rock.vector;
197
+ if (rock.bounds.intersects(this.item.bounds))
198
+ crashRock = rock;
199
+ keepInView(rock);
200
+ }
201
+
202
+ if (this.dying) {
203
+ var children = this.destroyedShip.children;
204
+ children[0].position.x++;
205
+ children[1].position.x--;
206
+ children[2].position.x--;
207
+ children[2].position.y++;
208
+ children[0].rotate(1);
209
+ children[1].rotate(-1);
210
+ children[2].rotate(1);
211
+ this.destroyedShip.opacity *= 0.98;
212
+
213
+ // don't update anything else if the ship is already dead.
214
+ return;
215
+ }
216
+
217
+
218
+ // if bounding rect collision, do a line intersection test
219
+ if (crashRock) {
220
+ var tempRock = crashRock.symbol.definition.clone();
221
+ tempRock.transform(crashRock.matrix);
222
+ tempRock.remove();
223
+ var intersections = this.item.firstChild.getIntersections(tempRock);
224
+ if (intersections.length > 0)
225
+ Lives.remove();
226
+ }
227
+ }
228
+ };
229
+ };
230
+
231
+ var Bullets = new function() {
232
+ var group = new Group();
233
+ var children = group.children;
234
+
235
+ function checkHits(bullet) {
236
+ for (var r = 0; r < Rocks.children.length; r++) {
237
+ var rock = Rocks.children[r];
238
+ if (rock.bounds.contains(bullet.position) ) {
239
+ Score.update(rock.shapeType);
240
+ Rocks.explode(rock);
241
+ if (rock.shapeType < Rocks.TYPE_SMALL ) {
242
+ for (var j = 0; j < 2; j++) {
243
+ Rocks.add(1, rock.shapeType + 4, rock.position);
244
+ }
245
+ }
246
+ rock.remove();
247
+ bullet.remove();
248
+ }
249
+ }
250
+ }
251
+
252
+ return {
253
+ fire: function(position, angle) {
254
+ // We can only fire 5 bullets at a time:
255
+ if (children.length == 5)
256
+ return;
257
+ var vector = new Point({
258
+ angle: angle,
259
+ length: 10
260
+ });
261
+ var bullet = new Path.Circle({
262
+ center: position + vector,
263
+ radius: 0.5,
264
+ parent: group,
265
+ fillColor: 'white',
266
+ strokeWidth: 'white',
267
+ strokeWidth: 0,
268
+ data: {
269
+ vector: vector,
270
+ timeToDie: 58
271
+ }
272
+ });
273
+ },
274
+ move: function() {
275
+ for (var i = 0; i < children.length; i++) {
276
+ var bullet = children[i];
277
+ bullet.data.timeToDie--;
278
+ if (bullet.data.timeToDie < 1) {
279
+ bullet.remove();
280
+ } else {
281
+ bullet.position += bullet.data.vector;
282
+ checkHits(bullet);
283
+ keepInView(bullet);
284
+ }
285
+ }
286
+ }
287
+ };
288
+ };
289
+
290
+ var Rocks = new function() {
291
+ var group = new Group();
292
+ var shapes = [
293
+ new Path(
294
+ [-23, -40.5], [0, -30.5], [24, -40.5], [45, -21.5], [25, -12.5],
295
+ [46, 9.5], [22, 38.5], [-10, 30.5], [-22, 40.5], [-46, 18.5],
296
+ [-33, 0.5], [-44, -21.5], [-23, -40.5]),
297
+ new Path(
298
+ [-45, -9.5], [-12, -40.5], [24, -40.5], [46, -11.5], [45, 10.5],
299
+ [24, 40.5], [0, 40.5], [0, 10.5], [-23, 38.5], [-46, 9.5], [-25, 0.5],
300
+ [-45, -9.5]),
301
+ new Path([-21.5, -39.5], [11.5, -39.5], [45.5, -20.5],
302
+ [45.5, -8.5], [9.5, 0.5], [44.5, 21.5], [22.5, 39.5], [9.5, 31.5],
303
+ [-20.5, 39.5], [-45.5, 10.5], [-45.5, -20.5], [-11.5, -21.5],
304
+ [-21.5, -39.5]),
305
+ new Path(
306
+ [-22.5, -40.5], [-0.5, -19.5], [23.5, -39.5], [44.5, -21.5],
307
+ [33.5, 0.5], [46.5, 19.5], [13.5, 40.5], [-22.5, 39.5], [-46.5, 18.5],
308
+ [-46.5, -18.5], [-22.5, -40.5])
309
+ ];
310
+
311
+ // medium rocks
312
+ for (var i = 4; i < 8; i++) {
313
+ shapes[i] = shapes[i - 4].clone();
314
+ shapes[i].scale(0.5);
315
+ }
316
+
317
+ // small rocks
318
+ for (var i = 8; i < 12; i++) {
319
+ shapes[i] = shapes[i - 4].clone();
320
+ shapes[i].scale(0.4);
321
+ }
322
+
323
+ var rockSymbols = [];
324
+ for (var i = 0; i < shapes.length; i++) {
325
+ rockSymbols[i] = new SymbolDefinition(shapes[i]);
326
+ }
327
+
328
+ var explosions = new Group();
329
+
330
+ return {
331
+ shapes: shapes,
332
+ children: group.children,
333
+ make: function(type, pos) {
334
+ var randomRock = type + Math.floor(4 * Math.random());
335
+ var rock = rockSymbols[randomRock].place();
336
+ rock.position = pos ? pos : Point.random() * view.size;
337
+ rock.vector = new Point({
338
+ angle: 360 * Math.random(),
339
+ length: presets.maxRockSpeed * Math.random() + 0.1
340
+ });
341
+ rock.shapeType = type;
342
+ return rock;
343
+ },
344
+ add: function(amount, type, position) {
345
+ for (var i = 0; i < amount; i++) {
346
+ var rock = this.make(type || this.TYPE_BIG, position);
347
+ group.addChild(rock);
348
+ }
349
+ },
350
+ explode: function(rock) {
351
+ var boomRock = rock.symbol.definition.clone();
352
+ boomRock.position = rock.position;
353
+ for (var i = 0; i < boomRock.segments.length; i++) {
354
+ var segmentPoint = boomRock.segments[i].point;
355
+ var placed = assets.explosion.place(segmentPoint);
356
+ placed.vector = (placed.position - rock.position) * 0.1;
357
+ explosions.addChild(placed);
358
+ }
359
+ boomRock.remove();
360
+ },
361
+ iterateExplosions: function() {
362
+ for (var i = 0; i < explosions.children.length; i++) {
363
+ var explosion = explosions.children[i];
364
+ explosion.vector.length *= .7;
365
+ explosion.position += explosion.vector;
366
+ explosion.opacity = explosion.vector.length;
367
+ if (explosion.vector.length < 0.05 ) {
368
+ explosion.remove();
369
+ // if no more rocks, wait a second and start a new round
370
+ if (this.children.length < 1 && !Game.roundDelay) {
371
+ Game.roundDelay = true;
372
+ presets.rockCount += 2;
373
+ setTimeout(Game.newRound, 1000);
374
+ }
375
+ }
376
+ }
377
+ },
378
+ TYPE_BIG: 0,
379
+ TYPE_MEDIUM: 4,
380
+ TYPE_SMALL: 8
381
+ };
382
+ };
383
+
384
+ var Score = new function() {
385
+ var numberGroup = new Group(
386
+ new Path([0, 0], [20, 0], [20, 27], [0, 27], [0, 0]),
387
+ new Path([10, 0], [10, 27]),
388
+ new Path([0, 0], [20, 0], [20, 14], [0, 14], [0, 27], [20, 27]),
389
+ new Path([0, 0], [20, 0], [20, 14], [0, 14], [20, 14], [20, 27], [0, 27]),
390
+ new Path([0, 0], [0, 14], [20, 14], [20, 0], [20, 27]),
391
+ new Path([20, 0], [0, 0], [0, 14], [20, 14], [20, 27], [0, 27]),
392
+ new Path([20, 0], [0, 0], [0, 27], [20, 27], [20, 14], [0, 14]),
393
+ new Path([0, 0], [20, 0], [0, 27]),
394
+ new Path([0, 0], [20, 0], [20, 27], [0, 27], [0, 0], [0, 14], [20, 14]),
395
+ new Path([20, 14], [0, 14], [0, 0], [20, 0], [20, 27])
396
+ );
397
+ numberGroup.visible = false;
398
+ var scoreDisplay = new Group();
399
+ var score = 0;
400
+ return {
401
+ update: function(type) {
402
+ if (type == Rocks.TYPE_BIG) score += 20;
403
+ if (type == Rocks.TYPE_MEDIUM) score += 50;
404
+ if (type == Rocks.TYPE_SMALL) score += 100;
405
+ if (score >= presets.freeShipScore) {
406
+ Lives.add(1);
407
+ presets.freeShipScore += presets.freeShipIncrement;
408
+ }
409
+ scoreDisplay.removeChildren();
410
+
411
+ var scoreString = score + '';
412
+ for (var i = 0; i < scoreString.length; i++) {
413
+ var n = parseInt(scoreString[i], 10);
414
+ scoreDisplay.addChild(numberGroup.children[n].clone());
415
+ scoreDisplay.lastChild.position = [22 + i * 24, 22];
416
+ }
417
+ }
418
+ };
419
+ };
420
+
421
+ var Lives = new function() {
422
+ var currentLives;
423
+ var shipPath = Ship.item.firstChild.clone();
424
+ project.activeLayer.addChild(shipPath);
425
+ shipPath.visible = false;
426
+ Ship.visible = false;
427
+ var group = new Group();
428
+ return {
429
+ initialize: function() {
430
+ currentLives = presets.lives;
431
+ this.display();
432
+ },
433
+ add: function() {
434
+ currentLives++;
435
+ this.display();
436
+ },
437
+ remove: function() {
438
+ currentLives--;
439
+ this.display();
440
+ Ship.destroy();
441
+ setTimeout(function() {
442
+ if (currentLives == 0) {
443
+ Game.over();
444
+ } else {
445
+ Ship.destroyed();
446
+ }
447
+ }, 1200);
448
+ },
449
+ display: function() {
450
+ group.removeChildren();
451
+ for (var i = 0;i < currentLives - 1; i++) {
452
+ var copy = shipPath.clone();
453
+ copy.rotate(-90);
454
+ copy.visible = true;
455
+ group.addChild(copy);
456
+ copy.position = [22+ i * copy.bounds.width, 53];
457
+ }
458
+ }
459
+ };
460
+ };
461
+
462
+ initialize();
463
+
464
+ // Stop left and right keyboard events from propagating.
465
+ function onKeyDown(event) {
466
+ if (event.key == 'left' || event.key == 'right') {
467
+ return false;
468
+ }
469
+ }
470
+
471
+ function keepInView(item) {
472
+ var position = item.position;
473
+ var itemBounds = item.bounds;
474
+ var bounds = view.bounds;
475
+
476
+ if (itemBounds.left > bounds.width) {
477
+ position.x = -item.bounds.width;
478
+ }
479
+
480
+ if (position.x < -itemBounds.width) {
481
+ position.x = bounds.width;
482
+ }
483
+
484
+ if (itemBounds.top > view.size.height) {
485
+ position.y = -itemBounds.height;
486
+ }
487
+
488
+ if (position.y < -itemBounds.height) {
489
+ position.y = bounds.height + itemBounds.height / 2;
490
+ }
491
+ }
492
+ </script>
493
+ <style type="text/css">
494
+ html,
495
+ body {
496
+ margin: 0;
497
+ overflow: hidden;
498
+ height: 100%;
499
+ }
500
+
501
+ canvas {
502
+ width: 100%;
503
+ height: 100%;
504
+ }
505
+
506
+ body {
507
+ background: #000;
508
+ font-family:Helvetica,Arial;
509
+ }
510
+
511
+ .footer {
512
+ position:absolute;
513
+ bottom:0;
514
+ color:#ff0000;
515
+ background-color: rgba(60,60,60,0.8);
516
+ font-size:0.75em;
517
+ padding:0.5em;
518
+ color:#ddd;
519
+ width: 100%
520
+ }
521
+
522
+ .footer a {
523
+ color: #fff;
524
+ font-weight:
525
+ bold; text-decoration: none;
526
+ border-bottom: 1px solid #555;
527
+ }
528
+
529
+ .footer b {
530
+ background-color: #660000;
531
+ padding-left: 0.25em;
532
+ padding-right: 0.25em;
533
+ }
534
+
535
+ .gameover {
536
+ display: none;
537
+ position: absolute;
538
+ left: 40%;
539
+ top: 40%;
540
+ color: #fff;
541
+ background-color: rgba(60,60,60,0.8);
542
+ padding: 32px;
543
+ -moz-border-radius: 12px;
544
+ -webkit-border-radius: 12px;
545
+ border-radius: 12px;
546
+ -moz-background-clip: padding;
547
+ -webkit-background-clip: padding-box;
548
+ background-clip: padding-box;
549
+ }
550
+
551
+ .gameover a {
552
+ color: #fff;
553
+ font-weight: bold;
554
+ }
555
+
556
+ #stats {
557
+ position: absolute;
558
+ left: auto !important;
559
+ right: 0px;
560
+ }
561
+ </style>
562
+ </head>
563
+ <body>
564
+ <canvas id="canvas" resize stats></canvas>
565
+ <div id="footer" class="footer"><a href=#">Paperoids</a>. To Play: <b>&#8592;</b> and <b>&#8594;</b> to rotate. <b>&#8593;</b> for thrust. <b>Z</b> to fire. <b>F</b> to show FPS. Follow @<a href="http://twitter.com/#/hirmes">hirmes</a> for updates. Made with the amazing <a href="http://paperjs.org">Paper.js</a></div>
566
+
567
+ <div id="gameover" class="gameover">Game Over. <a href="Paperoids.html">Play again</a>?</div>
568
+ </body>
569
+ </html>
@@ -0,0 +1,34 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <title>Circle Testing</title>
6
+ <link rel="stylesheet" href="../css/style.css">
7
+ <script type="text/javascript" src="../../dist/paper-full.js"></script>
8
+ <script type="text/paperscript" canvas="canvas1">
9
+ var topLeft = new Point(200, 200);
10
+ var size = new Size(150, 100);
11
+ var rectangle = new Rectangle(topLeft, size);
12
+ var path = new Path.Ellipse(rectangle);
13
+ path.fillColor = 'black';
14
+
15
+ var topLeft = new Point(5, 400);
16
+ var size = new Size(100, 50);
17
+ var rectangle = new Rectangle(topLeft, size);
18
+ var path = new Path.Ellipse(rectangle);
19
+ path.fillColor = 'yellow';
20
+
21
+ var path = new Path.Circle(new Point(50, 50), 25);
22
+ path.fillColor = 'red';
23
+ window._json = project.exportJSON();
24
+ console.log(window._json);
25
+ </script>
26
+ <script type="text/paperscript" canvas="canvas2">
27
+ project.importJSON(window._json);
28
+ </script>
29
+ </head>
30
+ <body>
31
+ <canvas id="canvas1" width="500" height="500"></canvas>
32
+ <canvas id="canvas2" width="500" height="500"></canvas>
33
+ </body>
34
+ </html>
@@ -0,0 +1,25 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <title>Compound Path</title>
6
+ <link rel="stylesheet" href="../css/style.css">
7
+ <script type="text/javascript" src="../../dist/paper-full.js"></script>
8
+ <script type="text/paperscript" canvas="canvas1">
9
+ project.currentStyle.fillColor = 'black';
10
+ var path1 = new Path.Rectangle([200, 200], [100, 100]);
11
+ var path2 = new Path.Rectangle([50, 50], [200, 200]);
12
+ var path3 = new Path.Rectangle([0, 0], [400, 400]);
13
+ new CompoundPath(path1, path2, path3);
14
+ window._json = project.exportJSON();
15
+ console.log(window._json);
16
+ </script>
17
+ <script type="text/paperscript" canvas="canvas2">
18
+ project.importJSON(window._json);
19
+ </script>
20
+ </head>
21
+ <body>
22
+ <canvas id="canvas1" width="500" height="500"></canvas>
23
+ <canvas id="canvas2" width="500" height="500"></canvas>
24
+ </body>
25
+ </html>
@@ -0,0 +1,31 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <title>Empty Path Testing</title>
6
+ <link rel="stylesheet" href="../css/style.css">
7
+ <script type="text/javascript" src="../../dist/paper-full.js"></script>
8
+ <script type="text/paperscript" canvas="canvas1">
9
+ var path = new Path();
10
+ path.strokeColor = 'black';
11
+ path.add(new Point(30, 30));
12
+ path.add(new Point(100, 100));
13
+
14
+ var segments = [new Point(30, 90), new Point(100, 150)];
15
+ var path2 = new Path(segments);
16
+ path2.strokeColor = 'yellow';
17
+
18
+ var path3 = new Path();
19
+
20
+ window._json = project.exportJSON();
21
+ console.log(window._json);
22
+ </script>
23
+ <script type="text/paperscript" canvas="canvas2">
24
+ project.importJSON(window._json);
25
+ </script>
26
+ </head>
27
+ <body>
28
+ <canvas id="canvas1" width="500" height="500"></canvas>
29
+ <canvas id="canvas2" width="500" height="500"></canvas>
30
+ </body>
31
+ </html>
@@ -0,0 +1,34 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <title>Gradients</title>
6
+ <link rel="stylesheet" href="../css/style.css">
7
+ <script type="text/javascript" src="../../dist/paper-full.js"></script>
8
+ <script type="text/paperscript" canvas="canvas1">
9
+ var path = new Path.Circle({
10
+ center: view.center,
11
+ radius: view.bounds.height * 0.4
12
+ });
13
+ path.fillColor = {
14
+ stops: ['yellow', 'red', 'black'],
15
+ radial: true,
16
+ origin: path.position,
17
+ destination: path.bounds.rightCenter
18
+ }
19
+
20
+ var symbol = new SymbolDefinition(path);
21
+ symbol.place(view.center);
22
+
23
+ window._json = project.exportJSON();
24
+ console.log(window._json);
25
+ </script>
26
+ <script type="text/paperscript" canvas="canvas2">
27
+ project.importJSON(window._json);
28
+ </script>
29
+ </head>
30
+ <body>
31
+ <canvas id="canvas1" width="500" height="500"></canvas>
32
+ <canvas id="canvas2" width="500" height="500"></canvas>
33
+ </body>
34
+ </html>