core2d 2.11.1 → 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.
@@ -4,18 +4,18 @@ import { Color } from "./Color.mjs";
4
4
  import { Sprite } from "./Sprite.mjs";
5
5
 
6
6
  export class Transition extends Sprite {
7
- init() {
8
- this.setColor(Color.Black);
9
- this.setHeight(this.scene.height);
10
- this._increase = this.scene.width / 32;
11
- }
7
+ init() {
8
+ this.setColor(Color.Black);
9
+ this.setHeight(this.scene.height);
10
+ this._increase = this.scene.width / 32;
11
+ }
12
12
 
13
- sync() {
14
- if (this.width > this.scene.width) {
15
- return true;
16
- }
13
+ sync() {
14
+ if (this.width > this.scene.width) {
15
+ return true;
16
+ }
17
17
 
18
- this.width += this._increase;
19
- return Sprite.prototype.sync.call(this);
20
- }
18
+ this.width += this._increase;
19
+ return Sprite.prototype.sync.call(this);
20
+ }
21
21
  }
@@ -3,8 +3,8 @@
3
3
  import { Sprite } from "../Sprite.mjs";
4
4
 
5
5
  export class BaseTile extends Sprite {
6
- constructor(id) {
7
- super();
8
- this.setImage(id);
9
- }
6
+ constructor(id) {
7
+ super();
8
+ this.setImage(id);
9
+ }
10
10
  }
@@ -3,21 +3,21 @@
3
3
  import { Sprite } from "../Sprite.mjs";
4
4
 
5
5
  export class ClickableSprite extends Sprite {
6
- constructor() {
7
- super();
8
- this.addTag("clickable");
9
- this.setSolid();
10
- }
6
+ constructor() {
7
+ super();
8
+ this.addTag("clickable");
9
+ this.setSolid();
10
+ }
11
11
 
12
- onClick() {
13
- // no default behavior
14
- }
12
+ onClick() {
13
+ // no default behavior
14
+ }
15
15
 
16
- onHoverIn() {
17
- // no default behavior
18
- }
16
+ onHoverIn() {
17
+ // no default behavior
18
+ }
19
19
 
20
- onHoverOut() {
21
- // no default behavior
22
- }
20
+ onHoverOut() {
21
+ // no default behavior
22
+ }
23
23
  }
@@ -5,40 +5,40 @@ import { Core2D } from "../Core2D.mjs";
5
5
  import { Sprite } from "../Sprite.mjs";
6
6
 
7
7
  export class ControllableSprite extends Sprite {
8
- constructor() {
9
- super();
10
- this.controller = Core2D.getController();
11
- this.step = 2;
12
- }
13
-
14
- setStep(step) {
15
- this.step = step;
16
- return this;
17
- }
18
-
19
- sync() {
20
- if (this.controller.keyDown(Command.LEFT) && this.left > 0) {
21
- this.x -= this.step;
22
- }
23
-
24
- if (
25
- this.controller.keyDown(Command.RIGHT) &&
26
- this.right < this.scene.width
27
- ) {
28
- this.x += this.step;
29
- }
30
-
31
- if (this.controller.keyDown(Command.UP) && this.top > 0) {
32
- this.y -= this.step;
33
- }
34
-
35
- if (
36
- this.controller.keyDown(Command.DOWN) &&
37
- this.bottom < this.scene.height
38
- ) {
39
- this.y += this.step;
40
- }
41
-
42
- return Sprite.prototype.sync.call(this);
43
- }
8
+ constructor() {
9
+ super();
10
+ this.controller = Core2D.getController();
11
+ this.step = 2;
12
+ }
13
+
14
+ setStep(step) {
15
+ this.step = step;
16
+ return this;
17
+ }
18
+
19
+ sync() {
20
+ if (this.controller.keyDown(Command.LEFT) && this.left > 0) {
21
+ this.x -= this.step;
22
+ }
23
+
24
+ if (
25
+ this.controller.keyDown(Command.RIGHT) &&
26
+ this.right < this.scene.width
27
+ ) {
28
+ this.x += this.step;
29
+ }
30
+
31
+ if (this.controller.keyDown(Command.UP) && this.top > 0) {
32
+ this.y -= this.step;
33
+ }
34
+
35
+ if (
36
+ this.controller.keyDown(Command.DOWN) &&
37
+ this.bottom < this.scene.height
38
+ ) {
39
+ this.y += this.step;
40
+ }
41
+
42
+ return Sprite.prototype.sync.call(this);
43
+ }
44
44
  }
@@ -5,41 +5,41 @@ import { Rect } from "../Rect.mjs";
5
5
  import { Sprite } from "../Sprite.mjs";
6
6
 
7
7
  export class CursorSprite extends Sprite {
8
- constructor() {
9
- super();
10
- this.hovering = null;
11
- this.pointer = Core2D.getPointer();
12
- this.setSolid();
13
- }
8
+ constructor() {
9
+ super();
10
+ this.hovering = null;
11
+ this.pointer = Core2D.getPointer();
12
+ this.setSolid();
13
+ }
14
14
 
15
- check(sprite) {
16
- const FOCUS = new Rect(this.getLeft(), this.getTop(), 1, 1);
17
- return sprite.hasCollision(FOCUS);
18
- }
15
+ check(sprite) {
16
+ const FOCUS = new Rect(this.getLeft(), this.getTop(), 1, 1);
17
+ return sprite.hasCollision(FOCUS);
18
+ }
19
19
 
20
- onCollision(sprite) {
21
- if (sprite.hasTag("clickable") && this.check(sprite)) {
22
- if (this.hovering != sprite) {
23
- if (this.hovering) {
24
- this.hovering.onHoverOut();
25
- }
20
+ onCollision(sprite) {
21
+ if (sprite.hasTag("clickable") && this.check(sprite)) {
22
+ if (this.hovering != sprite) {
23
+ if (this.hovering) {
24
+ this.hovering.onHoverOut();
25
+ }
26
26
 
27
- this.hovering = sprite;
28
- sprite.onHoverIn();
29
- }
30
- }
31
- }
27
+ this.hovering = sprite;
28
+ sprite.onHoverIn();
29
+ }
30
+ }
31
+ }
32
32
 
33
- update() {
34
- this.setPosition(this.pointer);
33
+ update() {
34
+ this.setPosition(this.pointer);
35
35
 
36
- if (this.hovering) {
37
- if (!this.hasCollision(this.hovering)) {
38
- this.hovering.onHoverOut();
39
- this.hovering = null;
40
- } else if (this.pointer.getPush()) {
41
- this.hovering.onClick();
42
- }
43
- }
44
- }
36
+ if (this.hovering) {
37
+ if (!this.hasCollision(this.hovering)) {
38
+ this.hovering.onHoverOut();
39
+ this.hovering = null;
40
+ } else if (this.pointer.getPush()) {
41
+ this.hovering.onClick();
42
+ }
43
+ }
44
+ }
45
45
  }
@@ -3,32 +3,32 @@
3
3
  import { Sprite } from "../Sprite.mjs";
4
4
 
5
5
  export class Fog extends Sprite {
6
- init() {
7
- this.scene.add(new FogLayer().setImageId("fogSprite0").setSpeedX(-1));
6
+ init() {
7
+ this.scene.add(new FogLayer().setImageId("fogSprite0").setSpeedX(-1));
8
8
 
9
- this.scene.add(
10
- new FogLayer()
11
- .setImageId("fogSprite1")
12
- .setSpeedX(1)
13
- .setRight(this.scene.right)
14
- );
15
- }
9
+ this.scene.add(
10
+ new FogLayer()
11
+ .setImageId("fogSprite1")
12
+ .setSpeedX(1)
13
+ .setRight(this.scene.right)
14
+ );
15
+ }
16
16
  }
17
17
 
18
18
  class FogLayer extends Sprite {
19
- init() {
20
- this.setLayerIndex(2)
21
- .setHeight(this.scene.height)
22
- .setWidth(this.scene.width * 2);
23
- }
19
+ init() {
20
+ this.setLayerIndex(2)
21
+ .setHeight(this.scene.height)
22
+ .setWidth(this.scene.width * 2);
23
+ }
24
24
 
25
- update() {
26
- if (
27
- (this.speedX < 0 && this.right == this.scene.right) ||
28
- (this.speedX > 0 && this.left == this.scene.left)
29
- ) {
30
- const SIGNAL = this.speedX / Math.abs(this.speedX);
31
- this.x -= this.scene.width * SIGNAL;
32
- }
33
- }
25
+ update() {
26
+ if (
27
+ (this.speedX < 0 && this.right == this.scene.right) ||
28
+ (this.speedX > 0 && this.left == this.scene.left)
29
+ ) {
30
+ const SIGNAL = this.speedX / Math.abs(this.speedX);
31
+ this.x -= this.scene.width * SIGNAL;
32
+ }
33
+ }
34
34
  }
@@ -4,76 +4,76 @@ import { Core2D } from "../Core2D.mjs";
4
4
  import { Sprite } from "../Sprite.mjs";
5
5
 
6
6
  export class FontSprite extends Sprite {
7
- constructor(text = "") {
8
- super();
9
- this.font = "";
10
- this.text = text;
11
- }
7
+ constructor(text = "") {
8
+ super();
9
+ this.font = "";
10
+ this.text = text;
11
+ }
12
12
 
13
- render(context) {
14
- Sprite.prototype.render.call(this, context) && this._parse(context);
15
- }
13
+ render(context) {
14
+ Sprite.prototype.render.call(this, context) && this._parse(context);
15
+ }
16
16
 
17
- setFont(font) {
18
- this.font = font;
19
- }
17
+ setFont(font) {
18
+ this.font = font;
19
+ }
20
20
 
21
- setText(text) {
22
- this._text = text;
23
- this._parse();
24
- return this;
25
- }
21
+ setText(text) {
22
+ this._text = text;
23
+ this._parse();
24
+ return this;
25
+ }
26
26
 
27
- get text() {
28
- return this._text;
29
- }
27
+ get text() {
28
+ return this._text;
29
+ }
30
30
 
31
- set text(text) {
32
- this.setText(text);
33
- }
31
+ set text(text) {
32
+ this.setText(text);
33
+ }
34
34
 
35
- _parse(context) {
36
- const SPACE = 4;
37
- const SPACING = 0;
38
- let height = 0;
39
- let width = 0;
40
- let x = 0;
41
- let y = 0;
35
+ _parse(context) {
36
+ const SPACE = 4;
37
+ const SPACING = 0;
38
+ let height = 0;
39
+ let width = 0;
40
+ let x = 0;
41
+ let y = 0;
42
42
 
43
- for (let i = 0; i < this._text.length; ++i) {
44
- let character = this._text[i];
43
+ for (let i = 0; i < this._text.length; ++i) {
44
+ let character = this._text[i];
45
45
 
46
- if (character == " ") {
47
- x += SPACE + SPACING;
48
- } else if (character == "\n") {
49
- x = 0;
50
- y += height + SPACING;
51
- } else {
52
- const IMAGE = Core2D.image(character + this.font + "Font");
46
+ if (character == " ") {
47
+ x += SPACE + SPACING;
48
+ } else if (character == "\n") {
49
+ x = 0;
50
+ y += height + SPACING;
51
+ } else {
52
+ const IMAGE = Core2D.image(character + this.font + "Font");
53
53
 
54
- if (context) {
55
- context.drawImage(
56
- IMAGE,
57
- this.x + this.scene.x + x,
58
- this.y + this.scene.y + y,
59
- IMAGE.width,
60
- IMAGE.height
61
- );
62
- }
54
+ if (context) {
55
+ context.drawImage(
56
+ IMAGE,
57
+ this.x + this.scene.x + x,
58
+ this.y + this.scene.y + y,
59
+ IMAGE.width,
60
+ IMAGE.height
61
+ );
62
+ }
63
63
 
64
- x += IMAGE.width + SPACING;
64
+ x += IMAGE.width + SPACING;
65
65
 
66
- if (x > width) {
67
- width = x;
68
- }
66
+ if (x > width) {
67
+ width = x;
68
+ }
69
69
 
70
- if (IMAGE.height > height) {
71
- height = IMAGE.height;
72
- }
73
- }
74
- }
70
+ if (IMAGE.height > height) {
71
+ height = IMAGE.height;
72
+ }
73
+ }
74
+ }
75
75
 
76
- this.setWidth(width);
77
- this.setHeight(y + height);
78
- }
76
+ this.setWidth(width);
77
+ this.setHeight(y + height);
78
+ }
79
79
  }