core2d 2.10.4 → 2.11.2

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.
@@ -9,52 +9,54 @@ const STAR_BLINK_CHANCE = 10;
9
9
  const STAR_DENSITY = 100;
10
10
 
11
11
  class Star extends Sprite {
12
- init() {
13
- this.addTag("star").setBoundary();
14
- }
15
-
16
- offBoundary() {
17
- if (this.right < this.scene.left) {
18
- this.setLeft(this.scene.right);
19
- } else if (this.left > this.scene.right) {
20
- this.setRight(this.scene.left);
21
- }
22
-
23
- if (this.bottom < this.scene.top) {
24
- this.setTop(this.scene.bottom);
25
- } else if (this.top > this.scene.bottom) {
26
- this.setBottom(this.scene.top);
27
- }
28
- }
29
-
30
- update() {
31
- this.setVisible(Core2D.random(STAR_BLINK_CHANCE * this.width) > 0);
32
- }
12
+ init() {
13
+ this.addTag("star").setBoundary();
14
+ }
15
+
16
+ offBoundary() {
17
+ if (this.right < this.scene.left) {
18
+ this.setLeft(this.scene.right);
19
+ } else if (this.left > this.scene.right) {
20
+ this.setRight(this.scene.left);
21
+ }
22
+
23
+ if (this.bottom < this.scene.top) {
24
+ this.setTop(this.scene.bottom);
25
+ } else if (this.top > this.scene.bottom) {
26
+ this.setBottom(this.scene.top);
27
+ }
28
+ }
29
+
30
+ update() {
31
+ this.setVisible(Core2D.random(STAR_BLINK_CHANCE * this.width) > 0);
32
+ }
33
33
  }
34
34
 
35
35
  export class Starfield extends Sprite {
36
- constructor() {
37
- super();
38
- this.colors = [Color.White];
39
- }
40
-
41
- init() {
42
- for (let i = 0; i < STAR_DENSITY; ++i) {
43
- const SIZE = 1 + Core2D.random(1);
44
-
45
- this.scene.add(new Star()
46
- .setColor(this.colors[Core2D.random(this.colors.length - 1)])
47
- .setX(Core2D.random(this.scene.width))
48
- .setY(Core2D.random(this.scene.height))
49
- .setWidth(SIZE)
50
- .setHeight(SIZE)
51
- .setSpeedX(this.speedX * SIZE * SPEED_SIZE_RATIO)
52
- .setSpeedY(this.speedY * SIZE * SPEED_SIZE_RATIO));
53
- }
54
- }
55
-
56
- setColors(colors) {
57
- this.colors = colors;
58
- return this;
59
- }
36
+ constructor() {
37
+ super();
38
+ this.colors = [Color.White];
39
+ }
40
+
41
+ init() {
42
+ for (let i = 0; i < STAR_DENSITY; ++i) {
43
+ const SIZE = 1 + Core2D.random(1);
44
+
45
+ this.scene.add(
46
+ new Star()
47
+ .setColor(this.colors[Core2D.random(this.colors.length - 1)])
48
+ .setX(Core2D.random(this.scene.width))
49
+ .setY(Core2D.random(this.scene.height))
50
+ .setWidth(SIZE)
51
+ .setHeight(SIZE)
52
+ .setSpeedX(this.speedX * SIZE * SPEED_SIZE_RATIO)
53
+ .setSpeedY(this.speedY * SIZE * SPEED_SIZE_RATIO)
54
+ );
55
+ }
56
+ }
57
+
58
+ setColors(colors) {
59
+ this.colors = colors;
60
+ return this;
61
+ }
60
62
  }