react-simple-game-engine 0.0.25 → 0.0.28
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/lib/classes/animations/animation.d.ts +2 -2
- package/lib/classes/animations/animation.d.ts.map +1 -1
- package/lib/classes/animations/avatar.animation.d.ts.map +1 -1
- package/lib/classes/animations/avatar.animation.js +3 -4
- package/lib/classes/animations/color.animation.d.ts +1 -1
- package/lib/classes/entities/circle.entity.d.ts +2 -2
- package/lib/classes/entities/circle.entity.d.ts.map +1 -1
- package/lib/classes/entities/entity.d.ts +4 -4
- package/lib/classes/entities/entity.d.ts.map +1 -1
- package/lib/classes/entities/entity.js +1 -0
- package/lib/classes/entities/rect.entity.d.ts +2 -2
- package/lib/classes/entities/rect.entity.d.ts.map +1 -1
- package/lib/classes/logic-component.d.ts +1 -2
- package/lib/classes/logic-component.d.ts.map +1 -1
- package/lib/classes/particle-system.d.ts +19 -0
- package/lib/classes/particle-system.d.ts.map +1 -0
- package/lib/classes/particle-system.js +71 -0
- package/lib/classes/particle.d.ts +31 -0
- package/lib/classes/particle.d.ts.map +1 -0
- package/lib/classes/particle.js +112 -0
- package/lib/classes/scene.d.ts +3 -1
- package/lib/classes/scene.d.ts.map +1 -1
- package/lib/classes/scene.js +8 -2
- package/lib/classes/sprites/avatar.sprite.js +7 -7
- package/lib/classes/sprites/color.sprite.js +2 -2
- package/lib/classes/sprites/sprite.d.ts +8 -10
- package/lib/classes/sprites/sprite.d.ts.map +1 -1
- package/lib/classes/sprites/sprite.js +1 -1
- package/lib/classes/world-management.d.ts +4 -2
- package/lib/classes/world-management.d.ts.map +1 -1
- package/lib/classes/world-management.js +28 -8
- package/package.json +1 -1
@@ -1,10 +1,10 @@
|
|
1
1
|
import { Sprite } from "../sprites/sprite";
|
2
|
-
export declare abstract class AnimationSprite<S
|
2
|
+
export declare abstract class AnimationSprite<S extends Sprite<any>> {
|
3
3
|
protected currentFrame: number;
|
4
4
|
protected _isRunning: boolean;
|
5
5
|
protected timeCounter: number;
|
6
6
|
delatime: number;
|
7
|
-
|
7
|
+
sprite: S;
|
8
8
|
set isRunning(_isRunning: boolean);
|
9
9
|
abstract initial(params: any): void;
|
10
10
|
draw(): void;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"animation.d.ts","sourceRoot":"","sources":["../../../src/classes/animations/animation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;
|
1
|
+
{"version":3,"file":"animation.d.ts","sourceRoot":"","sources":["../../../src/classes/animations/animation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,8BAAsB,eAAe,CAAC,CAAC,SAAS,MAAM,CAAC,GAAG,CAAC;IACzD,SAAS,CAAC,YAAY,EAAE,MAAM,CAAK;IACnC,SAAS,CAAC,UAAU,UAAQ;IAC5B,SAAS,CAAC,WAAW,SAAK;IAE1B,QAAQ,SAAU;IAClB,MAAM,EAAG,CAAC,CAAC;IAEX,IAAI,SAAS,CAAC,UAAU,EAAE,OAAO,EAOhC;IAED,QAAQ,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,GAAG,IAAI;IAEnC,IAAI;IAgBJ,SAAS,CAAC,QAAQ,CAAC,aAAa,IAAI,OAAO;IAC3C,SAAS,CAAC,QAAQ,CAAC,MAAM,IAAI,IAAI;CAClC"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"avatar.animation.d.ts","sourceRoot":"","sources":["../../../src/classes/animations/avatar.animation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AACxD,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAE9C,aAAK,MAAM,GAAG;IACZ,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,qBAAa,qBAAsB,SAAQ,eAAe,CAAC,YAAY,CAAC;IACtE,OAAO,CAAC,MAAM,CAAU;IAExB,OAAO,CAAC,EAAE,CAAK,EAAE,CAAK,EAAE,KAAS,EAAE,MAAU,EAAE,EAAE,OAAO,CAAC,MAAM,CAAC;IAShE,SAAS,CAAC,aAAa,IAAI,OAAO;IAKlC,MAAM;
|
1
|
+
{"version":3,"file":"avatar.animation.d.ts","sourceRoot":"","sources":["../../../src/classes/animations/avatar.animation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AACxD,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAE9C,aAAK,MAAM,GAAG;IACZ,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,qBAAa,qBAAsB,SAAQ,eAAe,CAAC,YAAY,CAAC;IACtE,OAAO,CAAC,MAAM,CAAU;IAExB,OAAO,CAAC,EAAE,CAAK,EAAE,CAAK,EAAE,KAAS,EAAE,MAAU,EAAE,EAAE,OAAO,CAAC,MAAM,CAAC;IAShE,SAAS,CAAC,aAAa,IAAI,OAAO;IAKlC,MAAM;CAgBP"}
|
@@ -30,14 +30,13 @@ var AvatarAnimationSprite = /** @class */ (function (_super) {
|
|
30
30
|
};
|
31
31
|
AvatarAnimationSprite.prototype.checkFrameMax = function () {
|
32
32
|
var _a = this.offset, width = _a.width, x = _a.x;
|
33
|
-
return this.currentFrame * width + x >= this.source.
|
33
|
+
return this.currentFrame * width + x >= this.sprite.source.width;
|
34
34
|
};
|
35
35
|
AvatarAnimationSprite.prototype.onDraw = function () {
|
36
|
-
var source = this.source;
|
37
36
|
var _a = this.offset, x = _a.x, y = _a.y, width = _a.width, height = _a.height;
|
38
|
-
Renderer.image(
|
37
|
+
Renderer.image(this.sprite.source,
|
39
38
|
// position on canvas
|
40
|
-
0, 0,
|
39
|
+
0, 0, this.sprite.width, this.sprite.height,
|
41
40
|
//crop on source image
|
42
41
|
this.currentFrame * width + x, y, width, height);
|
43
42
|
};
|
@@ -2,7 +2,7 @@ import { ColorSprite } from "../sprites/color.sprite";
|
|
2
2
|
import { AnimationSprite } from "./animation";
|
3
3
|
export declare class ColorAnimationSprite extends AnimationSprite<ColorSprite> {
|
4
4
|
private colors;
|
5
|
-
initial(colors: ColorSprite["
|
5
|
+
initial(colors: ColorSprite["source"][]): void;
|
6
6
|
protected checkFrameMax(): boolean;
|
7
7
|
protected onDraw(): void;
|
8
8
|
}
|
@@ -1,8 +1,8 @@
|
|
1
1
|
import { Body } from "matter-js";
|
2
2
|
import { CreateBodyDefine, EntityInitial } from "../../export-types";
|
3
|
-
import {
|
3
|
+
import { Sprite } from "../sprites/sprite";
|
4
4
|
import { Entity } from "./entity";
|
5
|
-
export declare class CircleEntity<SpriteType extends
|
5
|
+
export declare class CircleEntity<SpriteType extends Sprite<any> = any> extends Entity<SpriteType> {
|
6
6
|
radius: number;
|
7
7
|
onSpriteWidthHeightBinding(): {
|
8
8
|
width: number;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"circle.entity.d.ts","sourceRoot":"","sources":["../../../src/classes/entities/circle.entity.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAU,MAAM,WAAW,CAAC;AAEzC,OAAO,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACrE,OAAO,EAAE,
|
1
|
+
{"version":3,"file":"circle.entity.d.ts","sourceRoot":"","sources":["../../../src/classes/entities/circle.entity.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAU,MAAM,WAAW,CAAC;AAEzC,OAAO,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACrE,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAElC,qBAAa,YAAY,CACvB,UAAU,SAAS,MAAM,CAAC,GAAG,CAAC,GAAG,GAAG,CACpC,SAAQ,MAAM,CAAC,UAAU,CAAC;IACnB,MAAM,EAAG,MAAM,CAAC;IAEvB,0BAA0B,IAAI;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE;IAO/D,SAAS,CAAC,SAAS,IAAI,aAAa,CAAC,YAAY,CAAC;IAQlD,SAAS,CAAC,YAAY,CACpB,SAAS,EAAE,gBAAgB,CAAC,WAAW,CAAC,GAAG;QAAE,MAAM,EAAE,MAAM,CAAA;KAAE,EAC7D,OAAO,CAAC,EAAE,gBAAgB,CAAC,aAAa,CAAC,GACxC,IAAI;CAIR"}
|
@@ -1,9 +1,9 @@
|
|
1
1
|
import Matter from "matter-js";
|
2
2
|
import { Camera } from "../camera";
|
3
3
|
import { WorldManagement } from "../world-management";
|
4
|
-
import { Sprite
|
4
|
+
import { Sprite } from "../sprites/sprite";
|
5
5
|
import { CreateBodyDefine, EntityInitial, EntityPrepare, MasterBody, Sound } from "../../export-types";
|
6
|
-
export declare abstract class Entity<SpriteType extends
|
6
|
+
export declare abstract class Entity<SpriteType extends Sprite<any> = any> {
|
7
7
|
private _body;
|
8
8
|
private _sprite;
|
9
9
|
private readonly id;
|
@@ -12,8 +12,8 @@ export declare abstract class Entity<SpriteType extends SpriteTypeAble = any> {
|
|
12
12
|
protected worldManagement: WorldManagement;
|
13
13
|
protected sound?: Sound;
|
14
14
|
constructor();
|
15
|
-
set sprite(sprite:
|
16
|
-
get sprite():
|
15
|
+
set sprite(sprite: SpriteType);
|
16
|
+
get sprite(): SpriteType;
|
17
17
|
get position(): Matter.Vector;
|
18
18
|
get body(): MasterBody;
|
19
19
|
active(worldManagement: WorldManagement): void;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"entity.d.ts","sourceRoot":"","sources":["../../../src/classes/entities/entity.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,WAAW,CAAC;AAE/B,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AACnC,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAEtD,OAAO,EAAE,MAAM,EAAE,
|
1
|
+
{"version":3,"file":"entity.d.ts","sourceRoot":"","sources":["../../../src/classes/entities/entity.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,WAAW,CAAC;AAE/B,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AACnC,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAEtD,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAG3C,OAAO,EACL,gBAAgB,EAChB,aAAa,EACb,aAAa,EACb,UAAU,EACV,KAAK,EACN,MAAM,oBAAoB,CAAC;AAE5B,8BAAsB,MAAM,CAAC,UAAU,SAAS,MAAM,CAAC,GAAG,CAAC,GAAG,GAAG;IAC/D,OAAO,CAAC,KAAK,CAAc;IAC3B,OAAO,CAAC,OAAO,CAAc;IAC7B,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAsD;IAEzE,SAAgB,GAAG,EAAG,MAAM,CAAC;IACtB,MAAM,EAAG,MAAM,CAAC;IAEvB,SAAS,CAAC,eAAe,EAAG,eAAe,CAAC;IAC5C,SAAS,CAAC,KAAK,CAAC,EAAE,KAAK,CAAC;;IAMxB,IAAI,MAAM,CAAC,MAAM,EAAE,UAAU,EAG5B;IAED,IAAI,MAAM,IALS,UAAU,CAO5B;IAED,IAAI,QAAQ,kBAEX;IAED,IAAI,IAAI,eAEP;IAED,MAAM,CAAC,eAAe,EAAE,eAAe;IAKvC,QAAQ;IAER,UAAU,CACR,SAAS,EAAE,gBAAgB,CAAC,WAAW,CAAC,EACxC,OAAO,CAAC,EAAE,gBAAgB,CAAC,aAAa,CAAC;IAO3C,SAAS,CAAC,QAAQ,CAAC,YAAY,CAC7B,SAAS,EAAE,gBAAgB,CAAC,WAAW,CAAC,GAAG,SAAS,EACpD,OAAO,CAAC,EAAE,gBAAgB,CAAC,aAAa,CAAC,GACxC,MAAM,CAAC,IAAI;IAEd,OAAO,CAAC,EACN,KAAK,EACL,SAAc,EACd,MAAM,EAAE,eAAe,EACvB,WAAgB,GACjB,EAAE,aAAa,CAAC,IAAI,CAAC;IAgCtB,SAAS,CAAC,QAAQ,CAAC,SAAS,IAAI,aAAa,CAAC,IAAI,CAAC;IACnD,SAAS,CAAC,SAAS,IAAI,aAAa,CAAC,IAAI,CAAC;IAI1C,MAAM;IAGN,QAAQ;IAER,IAAI;IAIJ,QAAQ,CAAC,0BAA0B,IAAI;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE;IAExE,WAAW,CAAC,MAAM,EAAE,MAAM;IAC1B,cAAc,CAAC,MAAM,EAAE,MAAM;IAC7B,iBAAiB,CAAC,MAAM,EAAE,MAAM;CACjC"}
|
@@ -68,6 +68,7 @@ var Entity = /** @class */ (function () {
|
|
68
68
|
var _j = this.onPrepare(), transformAlt = _j.transform, bodyOptionsAlt = _j.bodyOptions, spriteComponentAlt = _j.sprite;
|
69
69
|
this.createBody(__assign(__assign(__assign({ x: x, y: y }, dfTransform), transform), transformAlt), __assign(__assign(__assign({}, dfBodyOptions), bodyOptions), bodyOptionsAlt));
|
70
70
|
this.sound = sound;
|
71
|
+
//@ts-ignore
|
71
72
|
this.sprite =
|
72
73
|
(dfSpriteComponent === null || dfSpriteComponent === void 0 ? void 0 : dfSpriteComponent.output()) ||
|
73
74
|
(spriteComponent === null || spriteComponent === void 0 ? void 0 : spriteComponent.output()) ||
|
@@ -1,8 +1,8 @@
|
|
1
1
|
import { Body } from "matter-js";
|
2
2
|
import { CreateBodyDefine, EntityInitial } from "../../export-types";
|
3
|
-
import {
|
3
|
+
import { Sprite } from "../sprites/sprite";
|
4
4
|
import { Entity } from "./entity";
|
5
|
-
export declare class RectEntity<SpriteType extends
|
5
|
+
export declare class RectEntity<SpriteType extends Sprite<any> = any> extends Entity<SpriteType> {
|
6
6
|
width: number;
|
7
7
|
height: number;
|
8
8
|
onSpriteWidthHeightBinding(): {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"rect.entity.d.ts","sourceRoot":"","sources":["../../../src/classes/entities/rect.entity.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,IAAI,EAAE,MAAM,WAAW,CAAC;AAEzC,OAAO,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACrE,OAAO,EAAE,
|
1
|
+
{"version":3,"file":"rect.entity.d.ts","sourceRoot":"","sources":["../../../src/classes/entities/rect.entity.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,IAAI,EAAE,MAAM,WAAW,CAAC;AAEzC,OAAO,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACrE,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAElC,qBAAa,UAAU,CACrB,UAAU,SAAS,MAAM,CAAC,GAAG,CAAC,GAAG,GAAG,CACpC,SAAQ,MAAM,CAAC,UAAU,CAAC;IACnB,KAAK,EAAG,MAAM,CAAC;IACf,MAAM,EAAG,MAAM,CAAC;IAEvB,0BAA0B,IAAI;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE;IAO/D,SAAS,CAAC,SAAS,IAAI,aAAa,CAAC,UAAU,CAAC;IAShD,SAAS,CAAC,YAAY,CACpB,SAAS,EAAE,gBAAgB,CAAC,WAAW,CAAC,GAAG;QACzC,KAAK,EAAE,MAAM,CAAC;QACd,MAAM,EAAE,MAAM,CAAC;KAChB,EACD,OAAO,CAAC,EAAE,gBAAgB,CAAC,aAAa,CAAC,GACxC,IAAI;CAWR"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"logic-component.d.ts","sourceRoot":"","sources":["../../src/classes/logic-component.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;
|
1
|
+
{"version":3,"file":"logic-component.d.ts","sourceRoot":"","sources":["../../src/classes/logic-component.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAG7C,qBAAa,cAAc,CAAC,CAAC,SAAS;IAAE,OAAO,EAAE,GAAG,CAAA;CAAE;IACpD,OAAO,CAAC,QAAQ,CAAI;gBACR,SAAS,EAAE,UAAU,CAAC,CAAC,CAAC;IAOpC,MAAM;CAGP"}
|
@@ -0,0 +1,19 @@
|
|
1
|
+
import p5 from "p5";
|
2
|
+
import { Particle } from "./particle";
|
3
|
+
export declare class ParticleSystem {
|
4
|
+
private particles;
|
5
|
+
private forces;
|
6
|
+
x: number;
|
7
|
+
y: number;
|
8
|
+
active(): void;
|
9
|
+
initial({ x, y, length, quantity, forces, ...params }: Omit<Parameters<Particle["initial"]>[0], "vec" | "angle"> & {
|
10
|
+
quantity?: number;
|
11
|
+
length?: number;
|
12
|
+
forces?: p5.Vector[];
|
13
|
+
x: number;
|
14
|
+
y: number;
|
15
|
+
}): void;
|
16
|
+
update(): void;
|
17
|
+
draw(): void;
|
18
|
+
}
|
19
|
+
//# sourceMappingURL=particle-system.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"particle-system.d.ts","sourceRoot":"","sources":["../../src/classes/particle-system.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAGtC,qBAAa,cAAc;IACzB,OAAO,CAAC,SAAS,CAAc;IAC/B,OAAO,CAAC,MAAM,CAAmB;IAC1B,CAAC,EAAG,MAAM,CAAC;IACX,CAAC,EAAG,MAAM,CAAC;IAElB,MAAM;IAIN,OAAO,CAAC,EACN,CAAC,EACD,CAAC,EACD,MAAW,EACX,QAAc,EACd,MAAM,EACN,GAAG,MAAM,EACV,EAAE,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,KAAK,GAAG,OAAO,CAAC,GAAG;QAC7D,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,MAAM,CAAC,EAAE,EAAE,CAAC,MAAM,EAAE,CAAC;QACrB,CAAC,EAAE,MAAM,CAAC;QACV,CAAC,EAAE,MAAM,CAAC;KACX;IAmBD,MAAM;IAaN,IAAI;CAKL"}
|
@@ -0,0 +1,71 @@
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
2
|
+
__assign = Object.assign || function(t) {
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
4
|
+
s = arguments[i];
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
6
|
+
t[p] = s[p];
|
7
|
+
}
|
8
|
+
return t;
|
9
|
+
};
|
10
|
+
return __assign.apply(this, arguments);
|
11
|
+
};
|
12
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
13
|
+
var t = {};
|
14
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
15
|
+
t[p] = s[p];
|
16
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
17
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
18
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
19
|
+
t[p[i]] = s[p[i]];
|
20
|
+
}
|
21
|
+
return t;
|
22
|
+
};
|
23
|
+
import p5 from "p5";
|
24
|
+
import { Particle } from "./particle";
|
25
|
+
var ParticleSystem = /** @class */ (function () {
|
26
|
+
function ParticleSystem() {
|
27
|
+
this.forces = [];
|
28
|
+
}
|
29
|
+
ParticleSystem.prototype.active = function () {
|
30
|
+
console.log("Initted particle system");
|
31
|
+
};
|
32
|
+
ParticleSystem.prototype.initial = function (_a) {
|
33
|
+
var _b;
|
34
|
+
var _this = this;
|
35
|
+
var x = _a.x, y = _a.y, _c = _a.length, length = _c === void 0 ? 10 : _c, _d = _a.quantity, quantity = _d === void 0 ? 500 : _d, forces = _a.forces, params = __rest(_a, ["x", "y", "length", "quantity", "forces"]);
|
36
|
+
this.x = x;
|
37
|
+
this.y = y;
|
38
|
+
if (forces) {
|
39
|
+
(_b = this.forces).push.apply(_b, forces);
|
40
|
+
}
|
41
|
+
this.particles = Array.from({ length: quantity }).map(function () {
|
42
|
+
var p = new Particle(_this.x, _this.y);
|
43
|
+
var vec = p5.Vector.random2D();
|
44
|
+
vec.mult(Renderer.random(length));
|
45
|
+
var angle = Renderer.random(Renderer.TWO_PI);
|
46
|
+
p.initial(__assign(__assign({}, params), { vec: vec, angle: angle }));
|
47
|
+
return p;
|
48
|
+
});
|
49
|
+
};
|
50
|
+
ParticleSystem.prototype.update = function () {
|
51
|
+
for (var i = this.particles.length; i > -1; i--) {
|
52
|
+
var p = this.particles[i];
|
53
|
+
for (var _i = 0, _a = this.forces; _i < _a.length; _i++) {
|
54
|
+
var force = _a[_i];
|
55
|
+
p.applyForce(force);
|
56
|
+
}
|
57
|
+
p.update();
|
58
|
+
if (p.isDead()) {
|
59
|
+
this.particles.splice(i, 1);
|
60
|
+
}
|
61
|
+
}
|
62
|
+
};
|
63
|
+
ParticleSystem.prototype.draw = function () {
|
64
|
+
for (var _i = 0, _a = this.particles; _i < _a.length; _i++) {
|
65
|
+
var particle = _a[_i];
|
66
|
+
particle.draw();
|
67
|
+
}
|
68
|
+
};
|
69
|
+
return ParticleSystem;
|
70
|
+
}());
|
71
|
+
export { ParticleSystem };
|
@@ -0,0 +1,31 @@
|
|
1
|
+
import p5 from "p5";
|
2
|
+
import { Avatar, Color } from "../export-types";
|
3
|
+
import { Camera } from "./camera";
|
4
|
+
export declare class Particle extends p5.Vector {
|
5
|
+
private vec;
|
6
|
+
private acc;
|
7
|
+
private angle;
|
8
|
+
camera: Camera;
|
9
|
+
sprite?: Avatar;
|
10
|
+
color: Color;
|
11
|
+
size: number;
|
12
|
+
private _lifetime;
|
13
|
+
lifetimeRemain: number;
|
14
|
+
set lifetime(lifetime: number);
|
15
|
+
get lifetime(): number;
|
16
|
+
initial({ vec, ...params }: {
|
17
|
+
vec?: p5.Vector;
|
18
|
+
angle?: number;
|
19
|
+
sprite?: Avatar;
|
20
|
+
color?: Color;
|
21
|
+
size?: number;
|
22
|
+
lifetime?: number;
|
23
|
+
camera: Camera;
|
24
|
+
}): void;
|
25
|
+
applyForce(force: p5.Vector): void;
|
26
|
+
isDead(): boolean;
|
27
|
+
update(): void;
|
28
|
+
draw(): void;
|
29
|
+
onDraw(): void;
|
30
|
+
}
|
31
|
+
//# sourceMappingURL=particle.d.ts.map
|
@@ -0,0 +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,MAAM,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAEhD,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAElC,qBAAa,QAAS,SAAQ,EAAE,CAAC,MAAM;IACrC,OAAO,CAAC,GAAG,CAAsC;IACjD,OAAO,CAAC,GAAG,CAAsC;IACjD,OAAO,CAAC,KAAK,CAAa;IACnB,MAAM,EAAG,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,KAAK,CAAmB;IAC/B,IAAI,EAAE,MAAM,CAAM;IACzB,OAAO,CAAC,SAAS,CAAa;IACvB,cAAc,EAAE,MAAM,CAAiB;IAE9C,IAAI,QAAQ,CAAC,QAAQ,EAAE,MAAM,EAG5B;IAED,IAAI,QAAQ,IALW,MAAM,CAO5B;IAED,OAAO,CAAC,EACN,GAAG,EACH,GAAG,MAAM,EACV,EAAE;QACD,GAAG,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC;QAChB,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,KAAK,CAAC,EAAE,KAAK,CAAC;QACd,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,MAAM,EAAE,MAAM,CAAC;KAChB;IAOD,UAAU,CAAC,KAAK,EAAE,EAAE,CAAC,MAAM;IAI3B,MAAM;IAIN,MAAM;IAQN,IAAI;IA8BJ,MAAM;CAQP"}
|
@@ -0,0 +1,112 @@
|
|
1
|
+
var __extends = (this && this.__extends) || (function () {
|
2
|
+
var extendStatics = function (d, b) {
|
3
|
+
extendStatics = Object.setPrototypeOf ||
|
4
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
5
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
6
|
+
return extendStatics(d, b);
|
7
|
+
};
|
8
|
+
return function (d, b) {
|
9
|
+
if (typeof b !== "function" && b !== null)
|
10
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
11
|
+
extendStatics(d, b);
|
12
|
+
function __() { this.constructor = d; }
|
13
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
14
|
+
};
|
15
|
+
})();
|
16
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
17
|
+
var t = {};
|
18
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
19
|
+
t[p] = s[p];
|
20
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
21
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
22
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
23
|
+
t[p[i]] = s[p[i]];
|
24
|
+
}
|
25
|
+
return t;
|
26
|
+
};
|
27
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
28
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
29
|
+
if (ar || !(i in from)) {
|
30
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
31
|
+
ar[i] = from[i];
|
32
|
+
}
|
33
|
+
}
|
34
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
35
|
+
};
|
36
|
+
import p5 from "p5";
|
37
|
+
import { copyProperties } from "../utils";
|
38
|
+
var Particle = /** @class */ (function (_super) {
|
39
|
+
__extends(Particle, _super);
|
40
|
+
function Particle() {
|
41
|
+
var _this = _super !== null && _super.apply(this, arguments) || this;
|
42
|
+
_this.vec = Renderer.createVector(); //velocity
|
43
|
+
_this.acc = Renderer.createVector(); //acceleration
|
44
|
+
_this.angle = 0;
|
45
|
+
_this.color = [255, 255, 255];
|
46
|
+
_this.size = 10;
|
47
|
+
_this._lifetime = 2; // in seconds
|
48
|
+
_this.lifetimeRemain = _this.lifetime; // in seconds
|
49
|
+
return _this;
|
50
|
+
}
|
51
|
+
Object.defineProperty(Particle.prototype, "lifetime", {
|
52
|
+
get: function () {
|
53
|
+
return this._lifetime;
|
54
|
+
},
|
55
|
+
set: function (lifetime) {
|
56
|
+
this._lifetime = lifetime;
|
57
|
+
this.lifetimeRemain = lifetime;
|
58
|
+
},
|
59
|
+
enumerable: false,
|
60
|
+
configurable: true
|
61
|
+
});
|
62
|
+
Particle.prototype.initial = function (_a) {
|
63
|
+
var vec = _a.vec, params = __rest(_a, ["vec"]);
|
64
|
+
if (vec) {
|
65
|
+
this.vec.set(vec.x, vec.y);
|
66
|
+
}
|
67
|
+
copyProperties(this, params);
|
68
|
+
};
|
69
|
+
Particle.prototype.applyForce = function (force) {
|
70
|
+
this.acc.add(force);
|
71
|
+
};
|
72
|
+
Particle.prototype.isDead = function () {
|
73
|
+
return this.lifetime <= 0;
|
74
|
+
};
|
75
|
+
Particle.prototype.update = function () {
|
76
|
+
this.vec.add(this.acc);
|
77
|
+
this.add(this.vec);
|
78
|
+
this.acc.set(0);
|
79
|
+
this.lifetime -= Renderer.deltaTime;
|
80
|
+
};
|
81
|
+
Particle.prototype.draw = function () {
|
82
|
+
Renderer.push();
|
83
|
+
Renderer.noStroke();
|
84
|
+
Renderer.translate(this.x - this.camera.x, this.y - this.camera.y);
|
85
|
+
Renderer.rotate(this.angle);
|
86
|
+
if (this.sprite) {
|
87
|
+
var color = __spreadArray([], this.color, true);
|
88
|
+
var alpha = Renderer.map(this.lifetimeRemain, 0, this.lifetime, 0, 255);
|
89
|
+
color[3] = alpha;
|
90
|
+
Renderer.tint.apply(Renderer, color);
|
91
|
+
Renderer.image(this.sprite,
|
92
|
+
// position on canvas
|
93
|
+
0, 0, this.sprite.width, this.sprite.height,
|
94
|
+
//crop on source image
|
95
|
+
0, 0, this.sprite.width, this.sprite.height);
|
96
|
+
}
|
97
|
+
else {
|
98
|
+
this.onDraw();
|
99
|
+
}
|
100
|
+
//
|
101
|
+
Renderer.pop();
|
102
|
+
};
|
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);
|
108
|
+
Renderer.circle(0, 0, this.size);
|
109
|
+
};
|
110
|
+
return Particle;
|
111
|
+
}(p5.Vector));
|
112
|
+
export { Particle };
|
package/lib/classes/scene.d.ts
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
import { ComponentType } from "react";
|
2
|
+
import { Entity } from "./entities/entity";
|
2
3
|
import { Camera } from "./camera";
|
3
4
|
import { LogicComponent } from "./logic-component";
|
4
5
|
import { SceneManagement } from "./scene-management";
|
6
|
+
import { ParticleSystem } from "./particle-system";
|
5
7
|
declare type LoadAssetsListener = (loadedAssets: boolean) => void;
|
6
8
|
export declare abstract class Scene<UIP = any> {
|
7
9
|
private ui;
|
@@ -12,7 +14,7 @@ export declare abstract class Scene<UIP = any> {
|
|
12
14
|
tag: string;
|
13
15
|
manager: SceneManagement;
|
14
16
|
readonly sessionId: string;
|
15
|
-
abstract getComponents(): LogicComponent[];
|
17
|
+
abstract getComponents(): LogicComponent<Entity | ParticleSystem>[];
|
16
18
|
constructor();
|
17
19
|
get UI(): ComponentType<UIP>;
|
18
20
|
get UIProps(): UIP;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"scene.d.ts","sourceRoot":"","sources":["../../src/classes/scene.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;
|
1
|
+
{"version":3,"file":"scene.d.ts","sourceRoot":"","sources":["../../src/classes/scene.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAEtC,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAE3C,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAGrD,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAEnD,aAAK,kBAAkB,GAAG,CAAC,YAAY,EAAE,OAAO,KAAK,IAAI,CAAC;AAE1D,8BAAsB,KAAK,CAAC,GAAG,GAAG,GAAG;IACnC,OAAO,CAAC,EAAE,CAAqB;IAC/B,OAAO,CAAC,eAAe,CAAmB;IAC1C,OAAO,CAAC,aAAa,CAAW;IAChC,OAAO,CAAC,kBAAkB,CAAsB;IAEzC,WAAW,EAAE,MAAM,CAAK;IACxB,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,EAAG,eAAe,CAAC;IACjC,SAAgB,SAAS,EAAE,MAAM,CAA8C;aAC/D,aAAa,IAAI,cAAc,CAAC,MAAM,GAAG,cAAc,CAAC,EAAE;;IAS1E,IAAI,EAAE,uBAGL;IAED,IAAI,OAAO,QAEV;IAED,SAAS,CAAC,MAAM;IAEhB,SAAS,CAAC,UAAU;IAIpB,IAAI,YAAY,YAEf;IAED,iBAAiB,CAAC,IAAI,EAAE,kBAAkB;IAI1C,UAAU;IAIV,kBAAkB,CAAC,YAAY,EAAE,OAAO;IAKxC,aAAa,CAAC,GAAG,EAAE,MAAM;IAInB,UAAU,CAAC,KAAK,CAAC,EAAE,MAAM;IAczB,YAAY;IAElB,SAAS,CAAC,MAAM,EAAE,MAAM;IAcxB,SAAS,CAAC,MAAM;IAChB,SAAS,CAAC,QAAQ;IAElB,MAAM;CAQP"}
|
package/lib/classes/scene.js
CHANGED
@@ -34,6 +34,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
34
34
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
35
35
|
}
|
36
36
|
};
|
37
|
+
import { Entity } from "./entities/entity";
|
37
38
|
import { WorldManagement } from "./world-management";
|
38
39
|
import { tick } from "../utils";
|
39
40
|
var Scene = /** @class */ (function () {
|
@@ -121,8 +122,13 @@ var Scene = /** @class */ (function () {
|
|
121
122
|
for (var _i = 0, components_1 = components; _i < components_1.length; _i++) {
|
122
123
|
var component = components_1[_i];
|
123
124
|
var entity = component.output();
|
124
|
-
entity
|
125
|
-
|
125
|
+
if (entity instanceof Entity) {
|
126
|
+
entity.camera = camera;
|
127
|
+
this.worldManagement.addEntity(entity);
|
128
|
+
}
|
129
|
+
else {
|
130
|
+
this.worldManagement.addEntity(entity);
|
131
|
+
}
|
126
132
|
}
|
127
133
|
};
|
128
134
|
Scene.prototype.onDraw = function () { };
|
@@ -58,13 +58,13 @@ var AvatarSprite = /** @class */ (function (_super) {
|
|
58
58
|
configurable: true
|
59
59
|
});
|
60
60
|
AvatarSprite.prototype.onDraw = function () {
|
61
|
-
if (this.
|
61
|
+
if (this.source) {
|
62
62
|
if (this.animation) {
|
63
63
|
this.animation.draw();
|
64
64
|
}
|
65
65
|
else {
|
66
66
|
var _a = this._offset, x = _a.x, y = _a.y, width = _a.width, height = _a.height, index = _a.index;
|
67
|
-
Renderer.image(this.
|
67
|
+
Renderer.image(this.source,
|
68
68
|
// position on canvas
|
69
69
|
0, 0, this.width, this.height,
|
70
70
|
//crop on source image
|
@@ -74,15 +74,15 @@ var AvatarSprite = /** @class */ (function (_super) {
|
|
74
74
|
};
|
75
75
|
AvatarSprite.prototype.initial = function (params) {
|
76
76
|
var _a = (params ||
|
77
|
-
{}), offset = _a.offset,
|
78
|
-
if (
|
79
|
-
this._offset.width =
|
80
|
-
this._offset.height =
|
77
|
+
{}), offset = _a.offset, source = _a.source, _params = __rest(_a, ["offset", "source"]);
|
78
|
+
if (source) {
|
79
|
+
this._offset.width = source.width;
|
80
|
+
this._offset.height = source.height;
|
81
81
|
}
|
82
82
|
if (offset) {
|
83
83
|
copyProperties(this._offset, offset);
|
84
84
|
}
|
85
|
-
_super.prototype.initial.call(this, __assign(__assign({}, _params), {
|
85
|
+
_super.prototype.initial.call(this, __assign(__assign({}, _params), { source: source }));
|
86
86
|
};
|
87
87
|
return AvatarSprite;
|
88
88
|
}(Sprite));
|
@@ -18,7 +18,7 @@ var ColorSprite = /** @class */ (function (_super) {
|
|
18
18
|
__extends(ColorSprite, _super);
|
19
19
|
function ColorSprite() {
|
20
20
|
var _this = _super.call(this) || this;
|
21
|
-
_this.
|
21
|
+
_this.source = [255, 255, 255];
|
22
22
|
return _this;
|
23
23
|
}
|
24
24
|
ColorSprite.prototype.onDraw = function () {
|
@@ -26,7 +26,7 @@ var ColorSprite = /** @class */ (function (_super) {
|
|
26
26
|
this.animation.draw();
|
27
27
|
}
|
28
28
|
else {
|
29
|
-
Renderer.fill.apply(Renderer, this.
|
29
|
+
Renderer.fill.apply(Renderer, this.source);
|
30
30
|
}
|
31
31
|
if (this.entity.width != null) {
|
32
32
|
Renderer.rect(0, 0, this.width, this.height);
|
@@ -2,21 +2,19 @@ import { Avatar, Color } from "../../export-types";
|
|
2
2
|
import { AnimationSprite } from "../animations/animation";
|
3
3
|
import { Entity } from "../entities/entity";
|
4
4
|
import { LogicComponent } from "../logic-component";
|
5
|
-
export declare type
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
animation?: LogicComponent<AnimationSprite>;
|
5
|
+
export declare type SourceType = Avatar | Color | undefined | null;
|
6
|
+
export declare type GetInitialParams<S extends Sprite<any> = any> = {
|
7
|
+
source?: S["source"];
|
8
|
+
animation?: LogicComponent<AnimationSprite<S>>;
|
10
9
|
};
|
11
|
-
export declare
|
12
|
-
|
13
|
-
sprite: SpriteType;
|
10
|
+
export declare abstract class Sprite<SpriteType extends SourceType> {
|
11
|
+
source: SpriteType;
|
14
12
|
private _entity;
|
15
13
|
private _width;
|
16
14
|
private _height;
|
17
15
|
private _animation;
|
18
|
-
set animation(ani: AnimationSprite);
|
19
|
-
get animation(): AnimationSprite
|
16
|
+
set animation(ani: AnimationSprite<this>);
|
17
|
+
get animation(): AnimationSprite<this>;
|
20
18
|
set entity(entity: Entity);
|
21
19
|
get entity(): Entity;
|
22
20
|
get width(): number;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"sprite.d.ts","sourceRoot":"","sources":["../../../src/classes/sprites/sprite.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5C,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAEpD,oBAAY,gBAAgB,CAAC,CAAC,SAAS
|
1
|
+
{"version":3,"file":"sprite.d.ts","sourceRoot":"","sources":["../../../src/classes/sprites/sprite.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5C,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAEpD,oBAAY,UAAU,GAAG,MAAM,GAAG,KAAK,GAAG,SAAS,GAAG,IAAI,CAAC;AAE3D,oBAAY,gBAAgB,CAAC,CAAC,SAAS,MAAM,CAAC,GAAG,CAAC,GAAG,GAAG,IAAI;IAC1D,MAAM,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC;IACrB,SAAS,CAAC,EAAE,cAAc,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,CAAC;CAChD,CAAC;AAEF,8BAAsB,MAAM,CAAC,UAAU,SAAS,UAAU;IACjD,MAAM,EAAG,UAAU,CAAC;IAC3B,OAAO,CAAC,OAAO,CAAU;IACzB,OAAO,CAAC,MAAM,CAAU;IACxB,OAAO,CAAC,OAAO,CAAU;IAEzB,OAAO,CAAC,UAAU,CAAoC;IAEtD,IAAI,SAAS,CAAC,GAAG,EAAE,eAAe,CAAC,IAAI,CAAC,EAGvC;IAED,IAAI,SAAS,IAAI,eAAe,CAAC,IAAI,CAAC,CAErC;IAED,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,EAKxB;IAED,IAAI,MAAM,IAPS,MAAM,CASxB;IAED,IAAI,KAAK,WAER;IAED,IAAI,MAAM,WAET;IAED,IAAI;IAUJ,QAAQ,CAAC,MAAM,IAAI,IAAI;IAEvB,OAAO,CAAC,MAAM,CAAC,EAAE,gBAAgB,CAAC,IAAI,CAAC;CAexC"}
|
@@ -1,11 +1,13 @@
|
|
1
1
|
import { Entity } from "./entities/entity";
|
2
|
+
import { ParticleSystem } from "./particle-system";
|
2
3
|
export declare class WorldManagement {
|
3
4
|
private entities;
|
5
|
+
private particleSystems;
|
4
6
|
private engine;
|
5
7
|
constructor();
|
6
8
|
destructor(): void;
|
7
|
-
addEntity(entity: Entity): void;
|
8
|
-
removeEntity(entity: Entity): void;
|
9
|
+
addEntity(entity: Entity | ParticleSystem): void;
|
10
|
+
removeEntity(entity: Entity | ParticleSystem): void;
|
9
11
|
update(): void;
|
10
12
|
draw(): void;
|
11
13
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"world-management.d.ts","sourceRoot":"","sources":["../../src/classes/world-management.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;
|
1
|
+
{"version":3,"file":"world-management.d.ts","sourceRoot":"","sources":["../../src/classes/world-management.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAEnD,qBAAa,eAAe;IAC1B,OAAO,CAAC,QAAQ,CAAgB;IAChC,OAAO,CAAC,eAAe,CAAwB;IAE/C,OAAO,CAAC,MAAM,CAAU;;IAsCxB,UAAU;IAKV,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,cAAc;IAUzC,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,cAAc;IAS5C,MAAM;IAWN,IAAI;CAQL"}
|
@@ -1,7 +1,9 @@
|
|
1
1
|
import { Engine, World, Events } from "matter-js";
|
2
|
+
import { Entity } from "./entities/entity";
|
2
3
|
var WorldManagement = /** @class */ (function () {
|
3
4
|
function WorldManagement() {
|
4
5
|
this.entities = [];
|
6
|
+
this.particleSystems = [];
|
5
7
|
this.engine = Engine.create();
|
6
8
|
Events.on(this.engine, "collisionStart", function (event) {
|
7
9
|
var pairs = event.pairs;
|
@@ -36,24 +38,42 @@ var WorldManagement = /** @class */ (function () {
|
|
36
38
|
Engine.clear(this.engine);
|
37
39
|
};
|
38
40
|
WorldManagement.prototype.addEntity = function (entity) {
|
39
|
-
|
40
|
-
|
41
|
+
if (entity instanceof Entity) {
|
42
|
+
this.entities.push(entity);
|
43
|
+
World.add(this.engine.world, entity.body);
|
44
|
+
}
|
45
|
+
else {
|
46
|
+
this.particleSystems.push(entity);
|
47
|
+
}
|
41
48
|
entity.active(this);
|
42
49
|
};
|
43
50
|
WorldManagement.prototype.removeEntity = function (entity) {
|
44
|
-
|
45
|
-
|
51
|
+
if (entity instanceof Entity) {
|
52
|
+
World.remove(this.engine.world, entity.body);
|
53
|
+
this.entities.splice(this.entities.indexOf(entity), 1);
|
54
|
+
}
|
55
|
+
else {
|
56
|
+
this.particleSystems.splice(this.particleSystems.indexOf(entity), 1);
|
57
|
+
}
|
46
58
|
};
|
47
59
|
WorldManagement.prototype.update = function () {
|
48
60
|
Engine.update(this.engine);
|
49
|
-
for (var _i = 0, _a = this.
|
50
|
-
var
|
61
|
+
for (var _i = 0, _a = this.particleSystems; _i < _a.length; _i++) {
|
62
|
+
var particleSystem = _a[_i];
|
63
|
+
particleSystem.update();
|
64
|
+
}
|
65
|
+
for (var _b = 0, _c = this.entities; _b < _c.length; _b++) {
|
66
|
+
var entity = _c[_b];
|
51
67
|
entity.update();
|
52
68
|
}
|
53
69
|
};
|
54
70
|
WorldManagement.prototype.draw = function () {
|
55
|
-
for (var _i = 0, _a = this.
|
56
|
-
var
|
71
|
+
for (var _i = 0, _a = this.particleSystems; _i < _a.length; _i++) {
|
72
|
+
var particleSystem = _a[_i];
|
73
|
+
particleSystem.draw();
|
74
|
+
}
|
75
|
+
for (var _b = 0, _c = this.entities; _b < _c.length; _b++) {
|
76
|
+
var entity = _c[_b];
|
57
77
|
entity.draw();
|
58
78
|
}
|
59
79
|
};
|