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.
- package/README.md +0 -1
- package/package.json +53 -53
- package/src/ACL.mjs +54 -54
- package/src/Animation.mjs +73 -73
- package/src/ButtonLayout.mjs +36 -36
- package/src/ButtonLayoutMap.mjs +1 -1
- package/src/Color.mjs +148 -148
- package/src/Command.mjs +10 -10
- package/src/CompositeOperations.mjs +11 -11
- package/src/Controller.mjs +82 -82
- package/src/Core2D.mjs +269 -269
- package/src/Direction.mjs +22 -22
- package/src/Engine.mjs +448 -448
- package/src/FontFamily.mjs +5 -5
- package/src/Frame.mjs +37 -37
- package/src/GamePad.mjs +43 -43
- package/src/Input.mjs +114 -114
- package/src/Key.mjs +18 -18
- package/src/KeyMap.mjs +18 -18
- package/src/Keyboard.mjs +28 -28
- package/src/Mouse.mjs +35 -35
- package/src/Point.mjs +61 -61
- package/src/Pointer.mjs +48 -48
- package/src/Rect.mjs +239 -239
- package/src/RenderableList.mjs +12 -12
- package/src/Scene.mjs +137 -137
- package/src/Sound.mjs +134 -134
- package/src/Sprite.mjs +686 -680
- package/src/Static.mjs +54 -54
- package/src/TextSprite.mjs +228 -228
- package/src/Touch.mjs +41 -41
- package/src/Transition.mjs +12 -12
- package/src/plugin/BaseTile.mjs +4 -4
- package/src/plugin/ClickableSprite.mjs +14 -14
- package/src/plugin/ControllableSprite.mjs +36 -36
- package/src/plugin/CursorSprite.mjs +32 -32
- package/src/plugin/Fog.mjs +23 -23
- package/src/plugin/FontSprite.mjs +59 -59
- package/src/plugin/JumperSprite.mjs +132 -132
- package/src/plugin/RandomRectTransition.mjs +22 -22
- package/src/plugin/Starfield.mjs +47 -47
package/src/Transition.mjs
CHANGED
|
@@ -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
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
sync() {
|
|
14
|
+
if (this.width > this.scene.width) {
|
|
15
|
+
return true;
|
|
16
|
+
}
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
this.width += this._increase;
|
|
19
|
+
return Sprite.prototype.sync.call(this);
|
|
20
|
+
}
|
|
21
21
|
}
|
package/src/plugin/BaseTile.mjs
CHANGED
|
@@ -3,21 +3,21 @@
|
|
|
3
3
|
import { Sprite } from "../Sprite.mjs";
|
|
4
4
|
|
|
5
5
|
export class ClickableSprite extends Sprite {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
6
|
+
constructor() {
|
|
7
|
+
super();
|
|
8
|
+
this.addTag("clickable");
|
|
9
|
+
this.setSolid();
|
|
10
|
+
}
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
onClick() {
|
|
13
|
+
// no default behavior
|
|
14
|
+
}
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
onHoverIn() {
|
|
17
|
+
// no default behavior
|
|
18
|
+
}
|
|
19
19
|
|
|
20
|
-
|
|
21
|
-
|
|
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
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
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
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
8
|
+
constructor() {
|
|
9
|
+
super();
|
|
10
|
+
this.hovering = null;
|
|
11
|
+
this.pointer = Core2D.getPointer();
|
|
12
|
+
this.setSolid();
|
|
13
|
+
}
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
15
|
+
check(sprite) {
|
|
16
|
+
const FOCUS = new Rect(this.getLeft(), this.getTop(), 1, 1);
|
|
17
|
+
return sprite.hasCollision(FOCUS);
|
|
18
|
+
}
|
|
19
19
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
27
|
+
this.hovering = sprite;
|
|
28
|
+
sprite.onHoverIn();
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
32
|
|
|
33
|
-
|
|
34
|
-
|
|
33
|
+
update() {
|
|
34
|
+
this.setPosition(this.pointer);
|
|
35
35
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
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
|
}
|
package/src/plugin/Fog.mjs
CHANGED
|
@@ -3,32 +3,32 @@
|
|
|
3
3
|
import { Sprite } from "../Sprite.mjs";
|
|
4
4
|
|
|
5
5
|
export class Fog extends Sprite {
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
init() {
|
|
7
|
+
this.scene.add(new FogLayer().setImageId("fogSprite0").setSpeedX(-1));
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
19
|
+
init() {
|
|
20
|
+
this.setLayerIndex(2)
|
|
21
|
+
.setHeight(this.scene.height)
|
|
22
|
+
.setWidth(this.scene.width * 2);
|
|
23
|
+
}
|
|
24
24
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
constructor(text = "") {
|
|
8
|
+
super();
|
|
9
|
+
this.font = "";
|
|
10
|
+
this.text = text;
|
|
11
|
+
}
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
render(context) {
|
|
14
|
+
Sprite.prototype.render.call(this, context) && this._parse(context);
|
|
15
|
+
}
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
setFont(font) {
|
|
18
|
+
this.font = font;
|
|
19
|
+
}
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
21
|
+
setText(text) {
|
|
22
|
+
this._text = text;
|
|
23
|
+
this._parse();
|
|
24
|
+
return this;
|
|
25
|
+
}
|
|
26
26
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
27
|
+
get text() {
|
|
28
|
+
return this._text;
|
|
29
|
+
}
|
|
30
30
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
31
|
+
set text(text) {
|
|
32
|
+
this.setText(text);
|
|
33
|
+
}
|
|
34
34
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
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
|
-
|
|
44
|
-
|
|
43
|
+
for (let i = 0; i < this._text.length; ++i) {
|
|
44
|
+
let character = this._text[i];
|
|
45
45
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
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
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
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
|
-
|
|
64
|
+
x += IMAGE.width + SPACING;
|
|
65
65
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
66
|
+
if (x > width) {
|
|
67
|
+
width = x;
|
|
68
|
+
}
|
|
69
69
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
70
|
+
if (IMAGE.height > height) {
|
|
71
|
+
height = IMAGE.height;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
75
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
76
|
+
this.setWidth(width);
|
|
77
|
+
this.setHeight(y + height);
|
|
78
|
+
}
|
|
79
79
|
}
|