react-simple-game-engine 0.1.22 → 0.1.25
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,12 +4,17 @@ import { CreateBodyDefine, EntityInitial, EntityPrepare, MasterBody, Sound } fro
|
|
4
4
|
import { EntitySult } from "./entity-sult";
|
5
5
|
import { LogicComponent } from "../logic-component";
|
6
6
|
declare type TimerJobListener = () => void;
|
7
|
+
declare type DieOptions = {
|
8
|
+
duration?: number;
|
9
|
+
effect: EntitySult | LogicComponent<EntitySult>;
|
10
|
+
};
|
7
11
|
export declare abstract class Entity<P extends Record<string, any> = Record<string, any>> extends EntitySult<EntityInitial<Entity>> {
|
8
12
|
private _body;
|
9
13
|
private _sprite;
|
10
14
|
private _children;
|
11
15
|
private _props;
|
12
16
|
private timerJobListeners;
|
17
|
+
private isLive;
|
13
18
|
enabledGravity: boolean;
|
14
19
|
sound?: Sound;
|
15
20
|
set sprite(sprite: Sprite<any>);
|
@@ -18,6 +23,13 @@ export declare abstract class Entity<P extends Record<string, any> = Record<stri
|
|
18
23
|
get body(): MasterBody;
|
19
24
|
get children(): EntitySult<any>[];
|
20
25
|
get props(): P;
|
26
|
+
/**
|
27
|
+
* @param {DieOptions} options
|
28
|
+
* #duration: time to disappear from the world in seconds, default: 0.2 seconds
|
29
|
+
* #effect: effect to showing on duration time
|
30
|
+
* @void
|
31
|
+
*/
|
32
|
+
die(options?: DieOptions): void;
|
21
33
|
/**
|
22
34
|
* @param {string} name
|
23
35
|
* @param {number} interval in seconds
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"entity.d.ts","sourceRoot":"","sources":["../../../src/classes/entities/entity.ts"],"names":[],"mappings":"AAAA,OAAO,MAAwB,MAAM,WAAW,CAAC;AAEjD,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAG3C,OAAO,EACL,gBAAgB,EAChB,aAAa,EACb,aAAa,EACb,UAAU,EACV,KAAK,EACN,MA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S,IAAI,aAAa,CAAC,IAAI,CAAC;IAI1C,MAAM;IAiBN,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"}
|
@@ -35,6 +35,7 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
35
35
|
}
|
36
36
|
return t;
|
37
37
|
};
|
38
|
+
import { Body } from "matter-js";
|
38
39
|
import { ColorSprite } from "../sprites/color.sprite";
|
39
40
|
import { EntitySult } from "./entity-sult";
|
40
41
|
import { copyProperties } from "../../utils";
|
@@ -45,6 +46,7 @@ var Entity = /** @class */ (function (_super) {
|
|
45
46
|
_this._children = [];
|
46
47
|
_this._props = {};
|
47
48
|
_this.timerJobListeners = {};
|
49
|
+
_this.isLive = true;
|
48
50
|
_this.enabledGravity = true;
|
49
51
|
return _this;
|
50
52
|
}
|
@@ -87,6 +89,32 @@ var Entity = /** @class */ (function (_super) {
|
|
87
89
|
enumerable: false,
|
88
90
|
configurable: true
|
89
91
|
});
|
92
|
+
/**
|
93
|
+
* @param {DieOptions} options
|
94
|
+
* #duration: time to disappear from the world in seconds, default: 0.2 seconds
|
95
|
+
* #effect: effect to showing on duration time
|
96
|
+
* @void
|
97
|
+
*/
|
98
|
+
Entity.prototype.die = function (options) {
|
99
|
+
var _this = this;
|
100
|
+
if (options) {
|
101
|
+
var _a = options.duration, duration = _a === void 0 ? 0.2 : _a, effect = options.effect;
|
102
|
+
this.isLive = false;
|
103
|
+
Body.setVelocity(this.body, {
|
104
|
+
y: 0,
|
105
|
+
x: 0,
|
106
|
+
});
|
107
|
+
this.sprite = new ColorSprite();
|
108
|
+
this.sprite.source = [0, 0, 0, 0];
|
109
|
+
this.addChild(effect);
|
110
|
+
setTimeout(function () {
|
111
|
+
_this.worldManagement.removeEntity(_this);
|
112
|
+
}, duration * 1000);
|
113
|
+
}
|
114
|
+
else {
|
115
|
+
this.worldManagement.removeEntity(this);
|
116
|
+
}
|
117
|
+
};
|
90
118
|
/**
|
91
119
|
* @param {string} name
|
92
120
|
* @param {number} interval in seconds
|
@@ -145,7 +173,9 @@ var Entity = /** @class */ (function (_super) {
|
|
145
173
|
return {};
|
146
174
|
};
|
147
175
|
Entity.prototype.update = function () {
|
148
|
-
this.
|
176
|
+
if (this.isLive) {
|
177
|
+
this.onUpdate();
|
178
|
+
}
|
149
179
|
for (var name_1 in this.timerJobListeners) {
|
150
180
|
var _a = this.timerJobListeners[name_1], timeCounter = _a.timeCounter, interval = _a.interval, job = _a.job, defaultRun = _a.defaultRun;
|
151
181
|
if (defaultRun || timeCounter / 1000 >= interval) {
|
@@ -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;AAErE,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;
|
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;AAErE,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAElC,qBAAa,UAAU,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,GAAG,CAAE,SAAQ,MAAM,CAAC,CAAC,CAAC;IACrE,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,IAAI,CAAC;IAS1C,SAAS,CAAC,YAAY,CACpB,EACE,CAAC,EACD,CAAC,EACD,GAAG,SAAS,EACb,EAAE,WAAW,CACZ,gBAAgB,CAAC;QACf,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,MAAM,CAAC,EAAE,MAAM,CAAC;KACjB,CAAC,CAAC,WAAW,CAAC,CAChB,EACD,OAAO,CAAC,EAAE,gBAAgB,CAAC,aAAa,CAAC,GACxC,IAAI;CAIR"}
|