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
|
@@ -7,136 +7,136 @@ import { Sprite } from "../Sprite.mjs";
|
|
|
7
7
|
const PUSHABLE_TAG = "pushable";
|
|
8
8
|
|
|
9
9
|
export class JumperSprite extends Sprite {
|
|
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
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
10
|
+
constructor(scene) {
|
|
11
|
+
super(scene);
|
|
12
|
+
this.accelerationY = 0.5;
|
|
13
|
+
this.canGoLeft = true;
|
|
14
|
+
this.canGoRight = true;
|
|
15
|
+
this.canJump = false;
|
|
16
|
+
this.controller = Core2D.getController();
|
|
17
|
+
this.jumpCommand = Command.A;
|
|
18
|
+
this.jumpSpeed = -8;
|
|
19
|
+
this.solid = true;
|
|
20
|
+
this.step = 2;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
setJumpCommand(jumpCommand) {
|
|
24
|
+
this.jumpCommand = jumpCommand;
|
|
25
|
+
return this;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
setJumpSpeed(jumpSpeed) {
|
|
29
|
+
this.jumpSpeed = jumpSpeed;
|
|
30
|
+
return this;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
setStep(step) {
|
|
34
|
+
this.step = step;
|
|
35
|
+
return this;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
jump() {
|
|
39
|
+
this.canJump = false;
|
|
40
|
+
this.setSpeedY(this.jumpSpeed);
|
|
41
|
+
this.onJump();
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
onCollision(sprite) {
|
|
45
|
+
const collision = this.getCollision(sprite);
|
|
46
|
+
|
|
47
|
+
if (collision.bottom) {
|
|
48
|
+
if (this.speedY > 0) {
|
|
49
|
+
this.setSpeedY(0);
|
|
50
|
+
this.setBottom(sprite.top - 1);
|
|
51
|
+
this.canJump = true;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
this.onBottomCollision(sprite);
|
|
55
|
+
} else if (collision.top) {
|
|
56
|
+
if (this.speedY < 0) {
|
|
57
|
+
this.setSpeedY(0);
|
|
58
|
+
this.setTop(sprite.bottom + 1);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
this.onTopCollision(sprite);
|
|
62
|
+
} else if (collision.left) {
|
|
63
|
+
if (!sprite.hasTag(PUSHABLE_TAG)) {
|
|
64
|
+
this.canGoLeft = false;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
this.setLeft(sprite.right + 1);
|
|
68
|
+
this.onLeftCollision(sprite);
|
|
69
|
+
} else if (collision.right) {
|
|
70
|
+
if (!sprite.hasTag(PUSHABLE_TAG)) {
|
|
71
|
+
this.canGoRight = false;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
this.setRight(sprite.left - 1);
|
|
75
|
+
this.onRightCollision(sprite);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
sync() {
|
|
80
|
+
if (this.solid) {
|
|
81
|
+
if (this.canJump && this.controller.keyPush(this.jumpCommand)) {
|
|
82
|
+
this.jump();
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if (this.canGoLeft && this.controller.keyDown(Command.LEFT)) {
|
|
86
|
+
this.x -= this.step;
|
|
87
|
+
this.canGoRight = true;
|
|
88
|
+
this.onLeft();
|
|
89
|
+
} else if (this.canGoRight && this.controller.keyDown(Command.RIGHT)) {
|
|
90
|
+
this.x += this.step;
|
|
91
|
+
this.canGoLeft = true;
|
|
92
|
+
this.onRight();
|
|
93
|
+
} else {
|
|
94
|
+
this.onIdle();
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
if (!this.collided) {
|
|
98
|
+
this.canGoLeft = true;
|
|
99
|
+
this.canGoRight = true;
|
|
100
|
+
this.canJump = false;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
return Sprite.prototype.sync.call(this);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
onJump() {
|
|
108
|
+
// no default behavior
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
onIdle() {
|
|
112
|
+
// no default behavior
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
onLeft() {
|
|
116
|
+
// no default behavior
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
onRight() {
|
|
120
|
+
// no default behavior
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
onLeftCollision(sprite) {
|
|
124
|
+
// no default behavior
|
|
125
|
+
return sprite;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
onRightCollision(sprite) {
|
|
129
|
+
// no default behavior
|
|
130
|
+
return sprite;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
onTopCollision(sprite) {
|
|
134
|
+
// no default behavior
|
|
135
|
+
return sprite;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
onBottomCollision(sprite) {
|
|
139
|
+
// no default behavior
|
|
140
|
+
return sprite;
|
|
141
|
+
}
|
|
142
142
|
}
|
|
@@ -5,29 +5,29 @@ import { Core2D } from "../Core2D.mjs";
|
|
|
5
5
|
import { Sprite } from "../Sprite.mjs";
|
|
6
6
|
|
|
7
7
|
export class RandomRectTransition extends Sprite {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
8
|
+
init() {
|
|
9
|
+
this.columns = 16;
|
|
10
|
+
this.rows = 8;
|
|
11
|
+
this.setColor(Color.Black);
|
|
12
|
+
this.setWidth(this.scene.width / this.columns);
|
|
13
|
+
this.setHeight(this.scene.height / this.rows);
|
|
14
|
+
this.rects = [];
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
for (let i = 0; i < this.columns * this.rows; ++i) {
|
|
17
|
+
this.rects.push(i);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
21
|
+
sync() {
|
|
22
|
+
if (!this.rects.length) {
|
|
23
|
+
return true;
|
|
24
|
+
}
|
|
25
25
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
26
|
+
const number = this.rects.splice(Core2D.random(this.rects.length - 1), 1);
|
|
27
|
+
const column = number % this.columns;
|
|
28
|
+
const row = Math.floor(number / this.columns);
|
|
29
|
+
this.x = column * this.width;
|
|
30
|
+
this.y = row * this.height;
|
|
31
|
+
return Sprite.prototype.sync.call(this);
|
|
32
|
+
}
|
|
33
33
|
}
|
package/src/plugin/Starfield.mjs
CHANGED
|
@@ -9,54 +9,54 @@ const STAR_BLINK_CHANCE = 10;
|
|
|
9
9
|
const STAR_DENSITY = 100;
|
|
10
10
|
|
|
11
11
|
class Star extends Sprite {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
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
|
+
}
|
|
62
62
|
}
|