fix: position clamp
This commit is contained in:
parent
566e9175c3
commit
962f867ed9
27
app/ecs-systems/clamp-positions.js
Normal file
27
app/ecs-systems/clamp-positions.js
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue
Block a user