react-simple-game-engine 0.3.11 → 0.3.13
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/sensor.d.ts
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
/// <reference types="matter-js" />
|
1
2
|
import { Color, Point, SensorBody, Size } from "../export-types";
|
2
3
|
import { Entity } from "./entities/entity";
|
3
4
|
export declare class Sensor {
|
@@ -10,5 +11,6 @@ export declare class Sensor {
|
|
10
11
|
readonly debug: boolean;
|
11
12
|
readonly debugColor: Color;
|
12
13
|
constructor(entity: Entity, name: string, relativePosition: Point, size: Size, shape: "rect" | "circle", body: SensorBody, debug?: boolean, debugColor?: Color);
|
14
|
+
get position(): import("matter-js").Vector;
|
13
15
|
}
|
14
16
|
//# sourceMappingURL=sensor.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"sensor.d.ts","sourceRoot":"","sources":["../../src/classes/sensor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AACjE,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAE3C,qBAAa,MAAM;aAEC,MAAM,EAAE,MAAM;aACd,IAAI,EAAE,MAAM;aACZ,gBAAgB,EAAE,KAAK;aACvB,IAAI,EAAE,IAAI;aACV,KAAK,EAAE,MAAM,GAAG,QAAQ;aACxB,IAAI,EAAE,UAAU;aAChB,KAAK,EAAE,OAAO;aACd,UAAU,EAAE,KAAK;gBAPjB,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,EACZ,gBAAgB,EAAE,KAAK,EACvB,IAAI,EAAE,IAAI,EACV,KAAK,EAAE,MAAM,GAAG,QAAQ,EACxB,IAAI,EAAE,UAAU,EAChB,KAAK,GAAE,OAAe,EACtB,UAAU,GAAE,KAA4B;
|
1
|
+
{"version":3,"file":"sensor.d.ts","sourceRoot":"","sources":["../../src/classes/sensor.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AACjE,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAE3C,qBAAa,MAAM;aAEC,MAAM,EAAE,MAAM;aACd,IAAI,EAAE,MAAM;aACZ,gBAAgB,EAAE,KAAK;aACvB,IAAI,EAAE,IAAI;aACV,KAAK,EAAE,MAAM,GAAG,QAAQ;aACxB,IAAI,EAAE,UAAU;aAChB,KAAK,EAAE,OAAO;aACd,UAAU,EAAE,KAAK;gBAPjB,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,EACZ,gBAAgB,EAAE,KAAK,EACvB,IAAI,EAAE,IAAI,EACV,KAAK,EAAE,MAAM,GAAG,QAAQ,EACxB,IAAI,EAAE,UAAU,EAChB,KAAK,GAAE,OAAe,EACtB,UAAU,GAAE,KAA4B;IAM1D,IAAI,QAAQ,+BAEX;CACF"}
|
package/lib/classes/sensor.js
CHANGED
@@ -13,6 +13,13 @@ var Sensor = /** @class */ (function () {
|
|
13
13
|
this.body.sensor = this;
|
14
14
|
this.body.entity = this.entity;
|
15
15
|
}
|
16
|
+
Object.defineProperty(Sensor.prototype, "position", {
|
17
|
+
get: function () {
|
18
|
+
return this.body.position;
|
19
|
+
},
|
20
|
+
enumerable: false,
|
21
|
+
configurable: true
|
22
|
+
});
|
16
23
|
return Sensor;
|
17
24
|
}());
|
18
25
|
export { Sensor };
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"world-management.d.ts","sourceRoot":"","sources":["../../src/classes/world-management.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAiB,IAAI,EAAE,MAAM,WAAW,CAAC;AAIxD,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC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,OAAO,CAAC,OAAO;IAWf,UAAU;IAKV,sBAAsB,CAAC,MAAM,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM;IAK3D,gBAAgB,CAAC,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM;IAKpD,kBAAkB;IAMlB,SAAS,CAAC,CAAC,SAAS,UAAU,GAAG,UAAU,EACzC,IAAI,EAAE,MAAM,GAAG;QAAE,QAAQ,CAAC,CAAA;KAAE,GAC3B,CAAC;IAgBJ,OAAO,CAAC,IAAI,EAAE,IAAI;IAIlB,UAAU,CAAC,IAAI,EAAE,IAAI;IAIrB,SAAS,CAAC,MAAM,EAAE,UAAU,GAAG,cAAc,CAAC,UAAU,CAAC;IAczD,YAAY,CAAC,MAAM,EAAE,UAAU;IAoB/B,MAAM;IAON,IAAI;CAqBL"}
|
@@ -12,14 +12,31 @@ var WorldManagement = /** @class */ (function () {
|
|
12
12
|
this._engine = Engine.create();
|
13
13
|
Events.on(this.engine, "beforeUpdate", function () {
|
14
14
|
var gravity = _this.engine.gravity;
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
15
|
+
var negativeGravityScale = {
|
16
|
+
x: -gravity.x * gravity.scale,
|
17
|
+
y: -gravity.y * gravity.scale,
|
18
|
+
};
|
19
|
+
_this.iterateEntities(function (target) {
|
20
|
+
if (target instanceof Entity) {
|
21
|
+
if (target.havePhysicBody && !target.enabledGravity) {
|
22
|
+
var targetBody = target.body;
|
23
|
+
Body.applyForce(targetBody, targetBody.position, {
|
24
|
+
x: negativeGravityScale.x * targetBody.mass,
|
25
|
+
y: negativeGravityScale.y * targetBody.mass,
|
26
|
+
});
|
27
|
+
}
|
28
|
+
var _a = target.position, entityX = _a.x, entityY = _a.y;
|
29
|
+
for (var _i = 0, _b = target.sensors; _i < _b.length; _i++) {
|
30
|
+
var _c = _b[_i], body = _c.body, relativePosition = _c.relativePosition;
|
31
|
+
Body.setPosition(body, {
|
32
|
+
x: entityX + relativePosition.x,
|
33
|
+
y: entityY + relativePosition.y,
|
34
|
+
});
|
35
|
+
Body.applyForce(body, body.position, {
|
36
|
+
x: negativeGravityScale.x * body.mass,
|
37
|
+
y: negativeGravityScale.y * body.mass,
|
38
|
+
});
|
39
|
+
}
|
23
40
|
}
|
24
41
|
});
|
25
42
|
});
|
@@ -195,16 +212,6 @@ var WorldManagement = /** @class */ (function () {
|
|
195
212
|
Engine.update(this.engine);
|
196
213
|
this.iterateEntities(function (entity) {
|
197
214
|
entity.update();
|
198
|
-
if (entity instanceof Entity) {
|
199
|
-
var _a = entity.position, entityX = _a.x, entityY = _a.y;
|
200
|
-
for (var _i = 0, _b = entity.sensors; _i < _b.length; _i++) {
|
201
|
-
var _c = _b[_i], body = _c.body, relativePosition = _c.relativePosition;
|
202
|
-
Body.setPosition(body, {
|
203
|
-
x: entityX + relativePosition.x,
|
204
|
-
y: entityY + relativePosition.y,
|
205
|
-
});
|
206
|
-
}
|
207
|
-
}
|
208
215
|
});
|
209
216
|
};
|
210
217
|
WorldManagement.prototype.draw = function () {
|