fix: position clamp

This commit is contained in:
cha0s 2024-06-13 17:49:39 -05:00
parent 566e9175c3
commit 962f867ed9
2 changed files with 29 additions and 0 deletions

View File

@ -0,0 +1,27 @@
import {System} from '@/ecs/index.js';
export default class ClampPositions extends System {
tick() {
const {diff} = this.ecs;
const {AreaSize} = this.ecs.get(1);
for (const id in diff) {
if (diff[id].Position) {
const {Position} = this.ecs.get(id);
if (Position.x < 0) {
Position.x = 0;
}
if (Position.y < 0) {
Position.y = 0;
}
if (Position.x >= AreaSize.x) {
Position.x = AreaSize.x - 0.0001;
}
if (Position.y >= AreaSize.y) {
Position.y = AreaSize.y - 0.0001;
}
}
}
}
}

View File

@ -6,6 +6,7 @@ import {
import ControlMovement from '@/ecs-systems/control-movement.js';
import ApplyMomentum from '@/ecs-systems/apply-momentum.js';
import CalculateAabbs from '@/ecs-systems/calculate-aabbs.js';
import ClampPositions from '@/ecs-systems/clamp-positions.js';
import FollowCamera from '@/ecs-systems/follow-camera.js';
import UpdateSpatialHash from '@/ecs-systems/update-spatial-hash.js';
import RunAnimations from '@/ecs-systems/run-animations.js';
@ -71,6 +72,7 @@ export default class Engine {
});
ecs.addSystem(ControlMovement);
ecs.addSystem(ApplyMomentum);
ecs.addSystem(ClampPositions);
ecs.addSystem(FollowCamera);
ecs.addSystem(CalculateAabbs);
ecs.addSystem(UpdateSpatialHash);