react-simple-game-engine 0.3.12 → 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.
@@ -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,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAGnD,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;
|
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,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAGnD,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAEpD,qBAAa,eAAe;IAWd,OAAO,CAAC,OAAO;IAAgB,OAAO,CAAC,MAAM;IAVzD,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAkC;IAC/D,OAAO,CAAC,QAAQ,CAAC,YAAY,CAGtB;IACP,OAAO,CAAC,QAAQ,CAAC,YAAY,CACxB;IAEL,OAAO,CAAC,OAAO,CAAS;gBAEJ,OAAO,EAAE,YAAY,EAAU,MAAM,EAAE,KAAK;IAoEhE,OAAO,CAAC,mBAAmB;IAiB3B,IAAI,MAAM,WAET;IAED,IAAI,MAAM,iBAET;IAED,IAAI,KAAK,eAER;IAED,eAAe,CAAC,MAAM,EAAE,CAAC,MAAM,EAAE,UAAU,KAAK,OAAO,GAAG,SAAS,GAAG,IAAI;IAqB1E,OAAO,CAAC,QAAQ;IAKhB,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"}
|
@@ -1,7 +1,6 @@
|
|
1
1
|
import { Engine, World, Events, Body } from "matter-js";
|
2
2
|
import { Entity } from "./entities/entity";
|
3
3
|
import { EntitySuit } from "./entities/entity-suit";
|
4
|
-
import { Sensor } from "./sensor";
|
5
4
|
var WorldManagement = /** @class */ (function () {
|
6
5
|
function WorldManagement(_camera, _scene) {
|
7
6
|
var _this = this;
|
@@ -13,15 +12,31 @@ var WorldManagement = /** @class */ (function () {
|
|
13
12
|
this._engine = Engine.create();
|
14
13
|
Events.on(this.engine, "beforeUpdate", function () {
|
15
14
|
var gravity = _this.engine.gravity;
|
15
|
+
var negativeGravityScale = {
|
16
|
+
x: -gravity.x * gravity.scale,
|
17
|
+
y: -gravity.y * gravity.scale,
|
18
|
+
};
|
16
19
|
_this.iterateEntities(function (target) {
|
17
|
-
if (
|
18
|
-
target.havePhysicBody &&
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
}
|
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
|
+
}
|
25
40
|
}
|
26
41
|
});
|
27
42
|
});
|
@@ -197,16 +212,6 @@ var WorldManagement = /** @class */ (function () {
|
|
197
212
|
Engine.update(this.engine);
|
198
213
|
this.iterateEntities(function (entity) {
|
199
214
|
entity.update();
|
200
|
-
if (entity instanceof Entity) {
|
201
|
-
var _a = entity.position, entityX = _a.x, entityY = _a.y;
|
202
|
-
for (var _i = 0, _b = entity.sensors; _i < _b.length; _i++) {
|
203
|
-
var _c = _b[_i], body = _c.body, relativePosition = _c.relativePosition;
|
204
|
-
Body.setPosition(body, {
|
205
|
-
x: entityX + relativePosition.x,
|
206
|
-
y: entityY + relativePosition.y,
|
207
|
-
});
|
208
|
-
}
|
209
|
-
}
|
210
215
|
});
|
211
216
|
};
|
212
217
|
WorldManagement.prototype.draw = function () {
|