react-simple-game-engine 0.0.40 → 0.0.43
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.
@@ -1,12 +1,17 @@
|
|
1
1
|
import p5 from "p5";
|
2
2
|
import { Camera } from "./camera";
|
3
3
|
import { EntitySult } from "./entities/entity-sult";
|
4
|
-
import { ParticleInitialParams } from "./particle";
|
4
|
+
import { Particle, ParticleInitialParams } from "./particle";
|
5
|
+
declare type ParticleClass = {
|
6
|
+
new (...args: ConstructorParameters<typeof Particle>): Particle;
|
7
|
+
};
|
5
8
|
declare type ParticleOptions = Omit<ParticleInitialParams, "vec" | "angle" | "camera"> & {
|
6
9
|
x?: number;
|
7
10
|
y?: number;
|
11
|
+
particleClass?: ParticleClass;
|
8
12
|
};
|
9
|
-
declare type ParticleSystemInitialParams =
|
13
|
+
declare type ParticleSystemInitialParams = {
|
14
|
+
particleOptions?: ParticleOptions;
|
10
15
|
quantityPerFrame?: number;
|
11
16
|
vecWeight?: number;
|
12
17
|
forces?: p5.Vector[];
|
@@ -15,11 +20,12 @@ export declare class ParticleSystem extends EntitySult<ParticleSystemInitialPara
|
|
15
20
|
private particles;
|
16
21
|
private forces;
|
17
22
|
private particleOptions;
|
23
|
+
private particleClass;
|
18
24
|
quantityPerFrame: number;
|
19
25
|
vecWeight: number;
|
20
26
|
camera: Camera;
|
21
27
|
active(): void;
|
22
|
-
initial({
|
28
|
+
initial({ forces, particleOptions, ...params }: ParticleSystemInitialParams): void;
|
23
29
|
update(): void;
|
24
30
|
draw(): void;
|
25
31
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"particle-system.d.ts","sourceRoot":"","sources":["../../src/classes/particle-system.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AAEpB,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACpD,OAAO,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49,9 @@ var ParticleSystem = /** @class */ (function (_super) {
|
|
49
49
|
x: 0,
|
50
50
|
y: 0,
|
51
51
|
};
|
52
|
-
_this.
|
53
|
-
_this.
|
52
|
+
_this.particleClass = Particle;
|
53
|
+
_this.quantityPerFrame = 50;
|
54
|
+
_this.vecWeight = 5;
|
54
55
|
return _this;
|
55
56
|
}
|
56
57
|
ParticleSystem.prototype.active = function () {
|
@@ -58,23 +59,19 @@ var ParticleSystem = /** @class */ (function (_super) {
|
|
58
59
|
};
|
59
60
|
ParticleSystem.prototype.initial = function (_a) {
|
60
61
|
var _b;
|
61
|
-
var
|
62
|
-
copyProperties(this.particleOptions,
|
63
|
-
|
64
|
-
this.quantityPerFrame = quantityPerFrame;
|
65
|
-
}
|
66
|
-
if (vecWeight != null) {
|
67
|
-
this.vecWeight = vecWeight;
|
68
|
-
}
|
62
|
+
var forces = _a.forces, _c = _a.particleOptions, particleOptions = _c === void 0 ? {} : _c, params = __rest(_a, ["forces", "particleOptions"]);
|
63
|
+
copyProperties(this.particleOptions, particleOptions);
|
64
|
+
copyProperties(this, params);
|
69
65
|
if (forces) {
|
70
66
|
(_b = this.forces).push.apply(_b, forces);
|
71
67
|
}
|
72
68
|
};
|
73
69
|
ParticleSystem.prototype.update = function () {
|
70
|
+
var ParticleClass = this.particleClass;
|
74
71
|
var _a = this.particleOptions, x = _a.x, y = _a.y, particleOptions = __rest(_a, ["x", "y"]);
|
75
72
|
for (var _i = 0, _b = Array.from({ length: this.quantityPerFrame }); _i < _b.length; _i++) {
|
76
73
|
var _ = _b[_i];
|
77
|
-
var p = new
|
74
|
+
var p = new ParticleClass(x, y);
|
78
75
|
var vec = p5.Vector.random2D();
|
79
76
|
vec.mult(Renderer.random(this.vecWeight));
|
80
77
|
var angle = Renderer.random(Renderer.TWO_PI);
|
@@ -10,6 +10,7 @@ export declare type ParticleInitialParams = {
|
|
10
10
|
size?: number;
|
11
11
|
lifetime?: number;
|
12
12
|
camera: Camera;
|
13
|
+
forceSpriteSize?: boolean;
|
13
14
|
};
|
14
15
|
export declare class Particle extends p5.Vector implements Initialler<ParticleInitialParams> {
|
15
16
|
private vec;
|
@@ -19,8 +20,9 @@ export declare class Particle extends p5.Vector implements Initialler<ParticleIn
|
|
19
20
|
sprite?: Avatar;
|
20
21
|
color: Color;
|
21
22
|
size: number;
|
22
|
-
private _lifetime;
|
23
23
|
lifetimeRemain: number;
|
24
|
+
private forceSpriteSize;
|
25
|
+
private _lifetime;
|
24
26
|
set lifetime(lifetime: number);
|
25
27
|
get lifetime(): number;
|
26
28
|
initial({ vec, ...params }: ParticleInitialParams): void;
|
@@ -28,6 +30,6 @@ export declare class Particle extends p5.Vector implements Initialler<ParticleIn
|
|
28
30
|
isDead(): boolean;
|
29
31
|
update(): void;
|
30
32
|
draw(): void;
|
31
|
-
onDraw(): void;
|
33
|
+
onDraw(_: Color): void;
|
32
34
|
}
|
33
35
|
//# sourceMappingURL=particle.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"particle.d.ts","sourceRoot":"","sources":["../../src/classes/particle.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAClD,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAEhD,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAElC,oBAAY,qBAAqB,GAAG;IAClC,GAAG,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,KAAK,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;
|
1
|
+
{"version":3,"file":"particle.d.ts","sourceRoot":"","sources":["../../src/classes/particle.ts"],"names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classes/particle.js
CHANGED
@@ -43,9 +43,10 @@ var Particle = /** @class */ (function (_super) {
|
|
43
43
|
_this.acc = Renderer.createVector(); //acceleration
|
44
44
|
_this.angle = 0;
|
45
45
|
_this.color = [255, 255, 255];
|
46
|
-
_this.size =
|
47
|
-
_this._lifetime = 2; // in seconds
|
46
|
+
_this.size = 5;
|
48
47
|
_this.lifetimeRemain = _this.lifetime; // in seconds
|
48
|
+
_this.forceSpriteSize = false;
|
49
|
+
_this._lifetime = 2; // in seconds
|
49
50
|
return _this;
|
50
51
|
}
|
51
52
|
Object.defineProperty(Particle.prototype, "lifetime", {
|
@@ -83,28 +84,32 @@ var Particle = /** @class */ (function (_super) {
|
|
83
84
|
Renderer.noStroke();
|
84
85
|
Renderer.translate(this.x - this.camera.x, this.y - this.camera.y);
|
85
86
|
Renderer.rotate(this.angle);
|
87
|
+
var color = __spreadArray([], this.color, true);
|
88
|
+
var alpha = Renderer.map(this.lifetimeRemain, 0, this.lifetime, 0, 255);
|
89
|
+
color[3] = alpha;
|
86
90
|
if (this.sprite) {
|
87
|
-
var
|
88
|
-
|
89
|
-
|
91
|
+
var size = this.forceSpriteSize
|
92
|
+
? [this.size, this.size]
|
93
|
+
: [this.sprite.width, this.sprite.height];
|
90
94
|
Renderer.tint.apply(Renderer, color);
|
91
|
-
Renderer.image(this.sprite,
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
95
|
+
Renderer.image.apply(Renderer, __spreadArray(__spreadArray([this.sprite,
|
96
|
+
// position on canvas
|
97
|
+
0,
|
98
|
+
0], size, false), [
|
99
|
+
//crop on source image
|
100
|
+
0,
|
101
|
+
0,
|
102
|
+
this.sprite.width,
|
103
|
+
this.sprite.height], false));
|
96
104
|
}
|
97
105
|
else {
|
98
|
-
|
106
|
+
Renderer.fill.apply(Renderer, color);
|
107
|
+
this.onDraw(color);
|
99
108
|
}
|
100
109
|
//
|
101
110
|
Renderer.pop();
|
102
111
|
};
|
103
|
-
Particle.prototype.onDraw = function () {
|
104
|
-
var color = __spreadArray([], this.color, true);
|
105
|
-
var alpha = Renderer.map(this.lifetimeRemain, 0, this.lifetime, 0, 255);
|
106
|
-
color[3] = alpha;
|
107
|
-
Renderer.fill.apply(Renderer, color);
|
112
|
+
Particle.prototype.onDraw = function (_) {
|
108
113
|
Renderer.circle(0, 0, this.size);
|
109
114
|
};
|
110
115
|
return Particle;
|