Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 | 35x 158x 158x 158x 158x 158x 158x 158x 158x 158x 158x 158x 158x 158x 158x 158x 4x 154x 154x 212x 212x 1442x 1442x 1442x 1442x 1442x 1442x 1442x 1442x 1392x 1392x 1392x 557x 332x 332x 332x 332x 332x 332x 332x 332x 332x 332x 225x 225x 225x 225x 225x 835x 835x 50x 50x 37x 37x 37x 37x 13x 50x 1442x 1442x 20x 20x 1442x 1442x 250x 250x 250x 250x 250x 250x 250x 156x 250x 78x 1478x 3x 3x 20x 20x 20x 20x 20x 1x 1x 1x 1x 60x 2x 58x 58x 7x 17x | /**
* Physics-based movement system for realistic combat movement.
*
* **Korean**: 이동 물리 시스템 (Movement Physics System)
*
* This module implements realistic physics-based player movement with proper
* acceleration/deceleration, foot-wide step precision, and stance-based speed
* modifiers for authentic Korean martial arts combat feel.
*
* ## Features
*
* - **Realistic Acceleration**: 0 to 2m/s in 0.5 seconds (4.0 m/s²)
* - **Realistic Deceleration**: 2m/s to 0 in 0.3 seconds (6.67 m/s²)
* - **Foot-wide Steps**: Discrete 30cm movement increments for tactical positioning
* - **Stance Modifiers**: 8 trigram stances with different speed characteristics
* - **Injury Integration**: Movement speed reduced by leg damage (10-50%)
*
* @module systems/physics/MovementPhysics
* @category Physics System
* @korean 이동물리
*/
import { TrigramStance } from "@/types/common";
import { BASE_MOVEMENT_ACCELERATION } from "@/types/physicsConstants";
import type { MovementArenaBounds } from "@/types/PhysicsTypes";
import * as THREE from "three";
/**
* Movement input from keyboard/gamepad controls.
*
* **Korean**: 이동 입력 (Movement Input)
*
* @public
* @category Physics System
* @korean 이동입력
*/
export interface MovementInput {
/** Forward/backward input (-1 to 1, where 1 is forward) */
readonly forward: number;
/** Lateral left/right input (-1 to 1, where 1 is right) */
readonly lateral: number;
/** Whether sprint/run key is held */
readonly isRunning: boolean;
/** Whether any movement input is active */
readonly isMoving: boolean;
/** Whether to use tactical step mode (30cm grid) */
readonly useTacticalSteps: boolean;
}
/**
* Complete movement state for physics calculations.
*
* **Korean**: 이동 상태 (Movement State)
*
* Contains position, velocity, and current movement parameters.
* All vectors are mutable for performance (updated in-place during physics loop).
*
* @public
* @category Physics System
* @korean 이동상태
*/
export interface MovementState {
/**
* Current position in 3D space (meters).
*
* NOTE: This is a readonly reference to a mutable THREE.Vector3.
* The physics engine intentionally mutates the vector in-place
* (e.g. via position.add(...)) for performance. The readonly
* modifier prevents reassignment of the Vector3 instance, not
* mutation of its components.
*/
readonly position: THREE.Vector3;
/**
* Current velocity vector (m/s).
*
* NOTE: This is a readonly reference to a mutable THREE.Vector3.
* The physics engine updates this vector in-place each frame.
* Callers must not reassign the velocity reference, but may pass
* it to APIs that read or modify its components.
*/
readonly velocity: THREE.Vector3;
/** Current acceleration magnitude (m/s²) */
acceleration: number;
/** Maximum speed for current state (m/s) */
maxSpeed: number;
/** Current Eight Trigram stance */
readonly currentStance: TrigramStance;
/** Leg injury percentage (0-1, where 1 is fully injured) */
legInjuryFactor: number;
}
/**
* Stance-based speed modifiers for Eight Trigram system.
*
* **Korean**: 팔괘 속도 배수 (Eight Trigram Speed Multipliers)
*
* Each trigram stance has unique movement characteristics based on
* traditional Korean martial arts philosophy:
*
* - ☰ 건 (Geon/Heaven): 100% - Balanced, standard speed
* - ☱ 태 (Tae/Lake): 110% - Fluid movement, flowing techniques
* - ☲ 리 (Li/Fire): 120% - Aggressive, fast attacks
* - ☳ 진 (Jin/Thunder): 115% - Explosive power
* - ☴ 손 (Son/Wind): 125% - Continuous motion, fastest stance
* - ☵ 감 (Gam/Water): 105% - Adaptive, slightly faster than neutral
* - ☶ 간 (Gan/Mountain): 80% - Solid defense, slower movement
* - ☷ 곤 (Gon/Earth): 85% - Grounded, stable but slower
*
* @korean 자세속도배수
*/
export const STANCE_SPEED_MODIFIERS: Record<TrigramStance, number> = {
[TrigramStance.GEON]: 1.0, // Heaven: balanced
[TrigramStance.TAE]: 1.1, // Lake: fluid
[TrigramStance.LI]: 1.2, // Fire: aggressive
[TrigramStance.JIN]: 1.15, // Thunder: explosive
[TrigramStance.SON]: 1.25, // Wind: fastest
[TrigramStance.GAM]: 1.05, // Water: adaptive
[TrigramStance.GAN]: 0.8, // Mountain: defensive
[TrigramStance.GON]: 0.85, // Earth: grounded
};
/**
* Physics-based movement engine for combat.
*
* **Korean**: 이동 물리 엔진 (Movement Physics Engine)
*
* Implements realistic acceleration, deceleration, and stance-based movement
* for authentic Korean martial arts combat. Supports both continuous movement
* and tactical foot-wide steps for precise positioning.
*
* @example
* ```typescript
* const physics = new MovementPhysics();
*
* const state: MovementState = {
* position: new THREE.Vector3(0, 0, 0),
* velocity: new THREE.Vector3(0, 0, 0),
* acceleration: 0,
* maxSpeed: 2.0,
* currentStance: TrigramStance.GEON,
* legInjuryFactor: 0,
* };
*
* const input: MovementInput = {
* forward: 1.0,
* lateral: 0,
* isRunning: false,
* isMoving: true,
* useTacticalSteps: false,
* };
*
* // In game loop at 60fps
* physics.updateMovement(state, input, deltaTime);
* ```
*
* @public
* @category Physics System
* @korean 이동물리엔진
*/
export class MovementPhysics {
/**
* Base acceleration rate (m/s²)
* Achieves 0 to 6m/s in 0.2 seconds (instant-response combat movement)
* Increased from 12.0 to 30.0 for arcade-style responsiveness
*
* Imported from physicsConstants.ts to maintain consistency across systems.
*
* **Korean**: 기본 가속도 (Base Acceleration)
*/
private readonly BASE_ACCELERATION = BASE_MOVEMENT_ACCELERATION;
/**
* Base deceleration rate (m/s²)
* Achieves 6m/s to 0 in 0.3 seconds (responsive combat stopping)
*
* **Korean**: 기본 감속도 (Base Deceleration)
*/
private readonly BASE_DECELERATION = 20.0;
/**
* Foot-wide step size (meters)
* Standard Korean martial arts step is approximately 30cm
*
* **Korean**: 보법 거리 (Step Distance)
*/
private readonly STEP_SIZE = 0.3;
/**
* Base walking speed (m/s)
* Optimized for responsive combat movement - crosses 14m arena in ~2.3s
*
* **Korean**: 기본 걷기 속도 (Base Walking Speed)
*/
private readonly BASE_WALK_SPEED = 6.0;
/**
* Base running speed (m/s)
* Sprint speed for rapid repositioning - crosses 14m arena in ~1.4s
*
* **Korean**: 기본 달리기 속도 (Base Running Speed)
*/
private readonly BASE_RUN_SPEED = 10.0;
/**
* Reference arena size for speed calibration (meters).
* All speeds are calibrated for a 10m arena.
*
* **Korean**: 기준 경기장 크기 (Reference Arena Size)
*/
private readonly REFERENCE_ARENA_SIZE = 10.0;
/**
* Current arena width in meters for arena-aware speed scaling.
*
* **Korean**: 현재 경기장 너비 (Current Arena Width)
*/
private _arenaWidthMeters: number = 10.0;
// LATERAL_SPEED removed - now using state.maxSpeed for all directions
// This ensures speed override applies to lateral movement too
/**
* Override for max speed from external speed modifier systems.
*
* **Korean**: 최대속도 재정의 (Max Speed Override)
*/
private _overrideMaxSpeed: number | null = null;
/**
* Override for acceleration from external speed modifier systems.
*
* **Korean**: 가속도 재정의 (Acceleration Override)
*/
private _overrideAcceleration: number | null = null;
/**
* Cached arena speed scale to avoid repeated calculations.
*
* **Korean**: 캐시된 경기장 속도 배수 (Cached Arena Speed Scale)
*/
private _cachedArenaSpeedScale: number = 1.0;
// Temporary vectors to avoid allocations in update loop
private readonly tempTargetVelocity = new THREE.Vector3();
private readonly tempMovement = new THREE.Vector3();
private readonly tempDirection = new THREE.Vector3();
private readonly tempTargetDirection = new THREE.Vector3();
/**
* Create a new MovementPhysics instance.
*
* **Korean**: 이동 물리 생성 (Create Movement Physics)
*
* @param arenaWidthMeters - Width of the arena in meters (default: 10m, min: 1m)
* @throws {Error} If arenaWidthMeters is not a positive number
*
* @example
* ```typescript
* // Default 10m arena (1.0x speed scale)
* const physics = new MovementPhysics();
*
* // Small 6m arena (0.7x speed scale)
* const smallPhysics = new MovementPhysics(6.0);
*
* // Large 14m arena (1.3x speed scale)
* const largePhysics = new MovementPhysics(14.0);
* ```
*
* @public
*/
constructor(arenaWidthMeters: number = 10.0) {
if (arenaWidthMeters <= 0 || !Number.isFinite(arenaWidthMeters)) {
throw new Error(
`Arena width must be a positive finite number, got: ${arenaWidthMeters}`,
);
}
this._arenaWidthMeters = arenaWidthMeters;
this._cachedArenaSpeedScale = this.calculateArenaSpeedScale();
}
/**
* Calculate arena-aware speed scaling factor.
*
* **Korean**: 경기장 크기 기반 속도 배수 (Arena-Based Speed Multiplier)
*
* Scales movement speed proportionally to arena size to maintain consistent
* gameplay feel across different screen resolutions. Smaller arenas get
* slightly slower speeds, larger arenas get slightly faster speeds.
*
* Formula: scaleFactor = arenaWidth / referenceArenaSize
* Clamped to [0.7, 1.3] range for balanced gameplay
*
* Examples:
* - 6m arena: 0.7x speed (70% of base)
* - 10m arena: 1.0x speed (baseline)
* - 14m arena: 1.3x speed (130% of base)
*
* @returns Speed multiplier (0.7 to 1.3)
*
* @korean 경기장속도배수
*/
private calculateArenaSpeedScale(): number {
const rawScale = this._arenaWidthMeters / this.REFERENCE_ARENA_SIZE;
// Clamp to reasonable range to maintain gameplay balance
return Math.max(0.7, Math.min(1.3, rawScale));
}
/**
* Update player movement based on input and physics.
*
* **Korean**: 이동 업데이트 (Update Movement)
*
* Called every frame (60fps) to update player position based on
* current velocity, acceleration, and input. Applies stance modifiers
* and injury penalties automatically.
*
* @param state - Current movement state (modified in-place)
* @param input - Current movement input from controls
* @param deltaTime - Time since last update (seconds)
* @param bounds - Optional arena bounds for clamping position (meters)
*
* @korean 이동업데이트
*/
public updateMovement(
state: MovementState,
input: MovementInput,
deltaTime: number,
bounds?: MovementArenaBounds,
): void {
// Use cached arena-aware speed scaling
const arenaSpeedScale = this._cachedArenaSpeedScale;
// Calculate stance speed modifier
const stanceModifier = this.getStanceSpeedModifier(state.currentStance);
// Calculate injury penalty (0-50% speed reduction)
const injuryPenalty = 1.0 - state.legInjuryFactor * 0.5;
// Calculate base target speed (walking or running)
const baseSpeed = input.isRunning
? this.BASE_RUN_SPEED
: this.BASE_WALK_SPEED;
// Apply all modifiers including arena scaling to get final max speed (or use override)
state.maxSpeed =
this._overrideMaxSpeed ??
baseSpeed * arenaSpeedScale * stanceModifier * injuryPenalty;
// Use override acceleration if set, otherwise use base
const currentAcceleration =
this._overrideAcceleration ?? this.BASE_ACCELERATION;
// Calculate target velocity based on input direction
// forward > 0 = moving in positive Z direction (toward bottom of screen)
// forward < 0 = moving in negative Z direction (toward top of screen)
// ✅ REMOVED backward multiplier: All directions use full speed for responsive gameplay
// The backward penalty should be applied contextually by the combat system
// based on player facing direction vs movement direction
// ✅ FIX: Both lateral and forward now use state.maxSpeed (which includes all modifiers)
// This ensures consistent speed in all movement directions and includes arena scaling
this.tempTargetVelocity.set(
input.lateral * state.maxSpeed,
0,
input.forward * state.maxSpeed,
);
// Apply acceleration or deceleration
if (input.isMoving) {
// Accelerate toward target velocity with realistic direction changes
const currentSpeed = state.velocity.length();
const targetSpeed = this.tempTargetVelocity.length();
if (currentSpeed < targetSpeed) {
// Check if direction change is needed
if (currentSpeed > 0.001 && targetSpeed > 0.001) {
// Current movement direction
this.tempDirection.copy(state.velocity).normalize();
// Desired movement direction (reuse temp vector to avoid allocation)
this.tempTargetDirection.copy(this.tempTargetVelocity).normalize();
const directionDot = this.tempDirection.dot(this.tempTargetDirection);
Iif (directionDot < 0) {
// Moving in opposite direction: decelerate first before reversing
const velocityDelta = this.BASE_DECELERATION * deltaTime;
const newSpeed = Math.max(currentSpeed - velocityDelta, 0);
if (newSpeed > 0.001) {
state.velocity.copy(this.tempDirection.multiplyScalar(newSpeed));
} else {
// Fully stopped; can now start accelerating in new direction
state.velocity.set(0, 0, 0);
}
state.acceleration = -this.BASE_DECELERATION;
I} else if (directionDot < 0.7) {
// Perpendicular direction change (e.g., forward to strafe): moderate deceleration
const blendedAccel = currentAcceleration * 0.6; // Reduced acceleration for sharp turns
const velocityDelta = blendedAccel * deltaTime;
const newSpeed = Math.min(
currentSpeed + velocityDelta,
targetSpeed,
);
this.tempDirection.copy(this.tempTargetVelocity).normalize();
state.velocity.copy(this.tempDirection.multiplyScalar(newSpeed));
state.acceleration = blendedAccel;
} else {
// Same or similar direction: full acceleration
this.tempDirection.copy(this.tempTargetVelocity).normalize();
const velocityDelta = currentAcceleration * deltaTime;
const newSpeed = Math.min(
currentSpeed + velocityDelta,
targetSpeed,
);
state.velocity.copy(this.tempDirection.multiplyScalar(newSpeed));
state.acceleration = currentAcceleration;
}
} else {
// Very low speed: safe to accelerate directly toward target
this.tempDirection.copy(this.tempTargetVelocity).normalize();
const velocityDelta = currentAcceleration * deltaTime;
const newSpeed = Math.min(currentSpeed + velocityDelta, targetSpeed);
state.velocity.copy(this.tempDirection.multiplyScalar(newSpeed));
state.acceleration = currentAcceleration;
}
} else {
// Already at or above target speed: snap to target velocity
state.velocity.copy(this.tempTargetVelocity);
state.acceleration = 0;
}
} else {
// Decelerate to stop
const currentSpeed = state.velocity.length();
if (currentSpeed > 0.01) {
this.tempDirection.copy(state.velocity).normalize();
const velocityDelta = this.BASE_DECELERATION * deltaTime;
const newSpeed = Math.max(currentSpeed - velocityDelta, 0);
state.velocity.copy(this.tempDirection.multiplyScalar(newSpeed));
} else {
state.velocity.set(0, 0, 0);
}
state.acceleration = -this.BASE_DECELERATION;
}
// Calculate movement delta for this frame
this.tempMovement.copy(state.velocity).multiplyScalar(deltaTime);
// Apply tactical step quantization if enabled
if (input.useTacticalSteps) {
// Quantize to 30cm grid steps
this.tempMovement.x =
Math.round(this.tempMovement.x / this.STEP_SIZE) * this.STEP_SIZE;
this.tempMovement.z =
Math.round(this.tempMovement.z / this.STEP_SIZE) * this.STEP_SIZE;
}
// Update position
state.position.add(this.tempMovement);
// Apply arena bounds clamping if bounds provided
if (bounds) {
// Check if position exceeded boundaries
const exceededMinX = state.position.x < bounds.minX;
const exceededMaxX = state.position.x > bounds.maxX;
const exceededMinZ = state.position.z < bounds.minZ;
const exceededMaxZ = state.position.z > bounds.maxZ;
// Clamp position to arena boundaries
state.position.x = Math.max(bounds.minX, Math.min(bounds.maxX, state.position.x));
state.position.z = Math.max(bounds.minZ, Math.min(bounds.maxZ, state.position.z));
// Zero velocity component if exceeded boundary (smooth stopping)
if (exceededMinX || exceededMaxX) {
state.velocity.x = 0;
}
if (exceededMinZ || exceededMaxZ) {
state.velocity.z = 0;
}
}
}
/**
* Get speed modifier for a specific trigram stance.
*
* **Korean**: 자세 속도 배수 가져오기 (Get Stance Speed Modifier)
*
* @param stance - Eight Trigram stance
* @returns Speed multiplier (0.8 to 1.25)
*
* @korean 자세속도배수
*/
public getStanceSpeedModifier(stance: TrigramStance): number {
return STANCE_SPEED_MODIFIERS[stance];
}
/**
* Calculate movement penalty from leg injury.
*
* **Korean**: 부상 이동 페널티 (Injury Movement Penalty)
*
* Leg damage reduces movement speed by 10-50% based on injury severity.
*
* @param legHealthPercentage - Remaining leg health (0-1)
* @returns Injury factor (0 = no injury, 1 = maximum injury)
*
* @korean 부상페널티
*/
public calculateInjuryPenalty(legHealthPercentage: number): number {
// Injury penalty scales from 0% (healthy) to 50% (critical)
// Clamp between 0 and 1
const healthFactor = Math.max(0, Math.min(1, legHealthPercentage));
return 1.0 - healthFactor;
}
/**
* Get maximum speed for current state configuration.
*
* **Korean**: 최대 속도 계산 (Calculate Maximum Speed)
*
* @param isRunning - Whether running (vs walking)
* @param stance - Current trigram stance
* @param legInjuryFactor - Leg injury severity (0-1)
* @returns Maximum speed in m/s (includes arena scaling)
*
* @korean 최대속도
*/
public getMaxSpeed(
isRunning: boolean,
stance: TrigramStance,
legInjuryFactor: number,
): number {
const arenaSpeedScale = this._cachedArenaSpeedScale;
const baseSpeed = isRunning ? this.BASE_RUN_SPEED : this.BASE_WALK_SPEED;
const stanceModifier = this.getStanceSpeedModifier(stance);
const injuryPenalty = 1.0 - legInjuryFactor * 0.5;
return baseSpeed * arenaSpeedScale * stanceModifier * injuryPenalty;
}
/**
* Calculate time required to reach target speed from current velocity.
*
* **Korean**: 가속 시간 (Acceleration Time)
*
* @param currentSpeed - Current speed magnitude (m/s)
* @param targetSpeed - Desired speed magnitude (m/s)
* @returns Time in seconds to reach target speed
*
* @korean 가속시간
*/
public getAccelerationTime(
currentSpeed: number,
targetSpeed: number,
): number {
const speedDiff = Math.abs(targetSpeed - currentSpeed);
return speedDiff / this.BASE_ACCELERATION;
}
/**
* Calculate stopping distance from current velocity.
*
* **Korean**: 제동 거리 (Braking Distance)
*
* @param currentSpeed - Current speed magnitude (m/s)
* @returns Distance in meters required to stop
*
* @korean 제동거리
*/
public getStoppingDistance(currentSpeed: number): number {
// Using kinematic equation: d = v² / (2a)
return (currentSpeed * currentSpeed) / (2 * this.BASE_DECELERATION);
}
/**
* Get tactical step size.
*
* **Korean**: 보법 거리 (Step Distance)
*
* @returns Step size in meters (0.3m = 30cm)
*
* @korean 보법거리
*/
public getStepSize(): number {
return this.STEP_SIZE;
}
/**
* Override maximum speed for external speed modifier systems.
*
* **Korean**: 최대 속도 설정 (Set Maximum Speed)
*
* Allows external systems (like SpeedModifierSystem) to override
* the calculated maximum speed. This is applied in the next
* updateMovement call.
*
* @param speed - Maximum speed in m/s
*
* @public
*/
public setMaxSpeed(speed: number): void {
this._overrideMaxSpeed = speed;
}
/**
* Override acceleration for external speed modifier systems.
*
* **Korean**: 가속도 설정 (Set Acceleration)
*
* Allows external systems (like SpeedModifierSystem) to override
* the base acceleration rate. This is applied in the next
* updateMovement call.
*
* @param acceleration - Acceleration in m/s²
*
* @public
*/
public setAcceleration(acceleration: number): void {
this._overrideAcceleration = acceleration;
}
/**
* Clear speed and acceleration overrides.
*
* **Korean**: 속도 재정의 해제 (Clear Speed Overrides)
*
* Resets movement to use default calculations without external
* override values.
*
* @public
*/
public clearOverrides(): void {
this._overrideMaxSpeed = null;
this._overrideAcceleration = null;
}
/**
* Set arena width for arena-aware speed scaling.
*
* **Korean**: 경기장 너비 설정 (Set Arena Width)
*
* Updates the arena width used for speed scaling calculations.
* Call this when the arena size changes (e.g., screen resize).
* Recalculates and caches the arena speed scale.
*
* @param widthMeters - Arena width in meters (must be positive)
* @throws {Error} If widthMeters is not a positive number
*
* @public
*/
public setArenaWidth(widthMeters: number): void {
if (widthMeters <= 0 || !Number.isFinite(widthMeters)) {
throw new Error(
`Arena width must be a positive finite number, got: ${widthMeters}`,
);
}
this._arenaWidthMeters = widthMeters;
this._cachedArenaSpeedScale = this.calculateArenaSpeedScale();
}
/**
* Get current arena width.
*
* **Korean**: 경기장 너비 가져오기 (Get Arena Width)
*
* @returns Arena width in meters
*
* @public
*/
public getArenaWidth(): number {
return this._arenaWidthMeters;
}
/**
* Get current arena speed scale factor.
*
* **Korean**: 경기장 속도 배수 가져오기 (Get Arena Speed Scale)
*
* Returns the cached arena speed scale value.
*
* @returns Arena-based speed multiplier (0.7 to 1.3)
*
* @public
*/
public getArenaSpeedScale(): number {
return this._cachedArenaSpeedScale;
}
}
|