feat: migrate JavaScript files to TypeScript, enhancing type safety and maintainability across the codebase
This commit is contained in:
parent
3db2bb9160
commit
c582f2004e
107 changed files with 5876 additions and 3588 deletions
|
|
@ -1,78 +0,0 @@
|
|||
import { System } from '../core/System.js';
|
||||
import { SystemName, ComponentType } from '../core/Constants.js';
|
||||
|
||||
export class MovementSystem extends System {
|
||||
constructor() {
|
||||
super(SystemName.MOVEMENT);
|
||||
this.requiredComponents = [ComponentType.POSITION, ComponentType.VELOCITY];
|
||||
this.priority = 10;
|
||||
}
|
||||
|
||||
process(deltaTime, entities) {
|
||||
entities.forEach(entity => {
|
||||
const position = entity.getComponent(ComponentType.POSITION);
|
||||
const velocity = entity.getComponent(ComponentType.VELOCITY);
|
||||
const health = entity.getComponent(ComponentType.HEALTH);
|
||||
|
||||
if (!position || !velocity) return;
|
||||
|
||||
// Check if this is a projectile
|
||||
const isProjectile = health && health.isProjectile;
|
||||
|
||||
// Apply velocity with max speed limit (skip for projectiles)
|
||||
if (!isProjectile) {
|
||||
const speed = Math.sqrt(velocity.vx * velocity.vx + velocity.vy * velocity.vy);
|
||||
if (speed > velocity.maxSpeed) {
|
||||
const factor = velocity.maxSpeed / speed;
|
||||
velocity.vx *= factor;
|
||||
velocity.vy *= factor;
|
||||
}
|
||||
}
|
||||
|
||||
// Update position with collision detection
|
||||
const tileMap = this.engine.tileMap;
|
||||
|
||||
// X Axis
|
||||
const nextX = position.x + velocity.vx * deltaTime;
|
||||
if (tileMap && tileMap.isSolid(nextX, position.y)) {
|
||||
velocity.vx = 0;
|
||||
} else {
|
||||
position.x = nextX;
|
||||
}
|
||||
|
||||
// Y Axis
|
||||
const nextY = position.y + velocity.vy * deltaTime;
|
||||
if (tileMap && tileMap.isSolid(position.x, nextY)) {
|
||||
velocity.vy = 0;
|
||||
} else {
|
||||
position.y = nextY;
|
||||
}
|
||||
|
||||
// Apply friction (skip for projectiles - they should maintain speed)
|
||||
if (!isProjectile) {
|
||||
const friction = 0.9;
|
||||
velocity.vx *= Math.pow(friction, deltaTime * 60);
|
||||
velocity.vy *= Math.pow(friction, deltaTime * 60);
|
||||
}
|
||||
|
||||
// Boundary checking
|
||||
const canvas = this.engine.canvas;
|
||||
if (position.x < 0) {
|
||||
position.x = 0;
|
||||
velocity.vx = 0;
|
||||
} else if (position.x > canvas.width) {
|
||||
position.x = canvas.width;
|
||||
velocity.vx = 0;
|
||||
}
|
||||
|
||||
if (position.y < 0) {
|
||||
position.y = 0;
|
||||
velocity.vy = 0;
|
||||
} else if (position.y > canvas.height) {
|
||||
position.y = canvas.height;
|
||||
velocity.vy = 0;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue