Ensure projectiles dont get embedded in walls or blocking tiles
This commit is contained in:
50
src/engine/__tests__/throwing.test.ts
Normal file
50
src/engine/__tests__/throwing.test.ts
Normal file
@@ -0,0 +1,50 @@
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { traceProjectile } from '../gameplay/CombatLogic';
|
||||
import { EntityManager } from '../EntityManager';
|
||||
import { type World, type Actor, type EntityId } from '../../core/types';
|
||||
|
||||
const createTestWorld = (actors: Map<EntityId, Actor>): World => {
|
||||
return {
|
||||
width: 10,
|
||||
height: 10,
|
||||
tiles: new Array(100).fill(0), // 0 = Floor
|
||||
actors,
|
||||
exit: { x: 9, y: 9 }
|
||||
};
|
||||
};
|
||||
|
||||
describe('Throwing Mechanics', () => {
|
||||
it('should land ON the wall currently (demonstrating the bug)', () => {
|
||||
const actors = new Map<EntityId, Actor>();
|
||||
const world = createTestWorld(actors);
|
||||
const entityManager = new EntityManager(world);
|
||||
|
||||
// Wall at (5, 0)
|
||||
world.tiles[5] = 4; // Wall
|
||||
|
||||
const start = { x: 0, y: 0 };
|
||||
const target = { x: 5, y: 0 }; // Target the wall directly
|
||||
|
||||
const result = traceProjectile(world, start, target, entityManager);
|
||||
|
||||
// NEW BEHAVIOR: blockedPos is the tile BEFORE the wall (4, 0)
|
||||
expect(result.blockedPos).toEqual({ x: 4, y: 0 });
|
||||
});
|
||||
|
||||
it('should land ON the wall when throwing PAST a wall (demonstrating the bug)', () => {
|
||||
const actors = new Map<EntityId, Actor>();
|
||||
const world = createTestWorld(actors);
|
||||
const entityManager = new EntityManager(world);
|
||||
|
||||
// Wall at (3, 0)
|
||||
world.tiles[3] = 4; // Wall
|
||||
|
||||
const start = { x: 0, y: 0 };
|
||||
const target = { x: 5, y: 0 }; // Target past the wall
|
||||
|
||||
const result = traceProjectile(world, start, target, entityManager);
|
||||
|
||||
// NEW BEHAVIOR: Hits the wall at 3,0, stops at 2,0
|
||||
expect(result.blockedPos).toEqual({ x: 2, y: 0 });
|
||||
});
|
||||
});
|
||||
@@ -38,7 +38,7 @@ export function traceProjectile(
|
||||
blockedPos = p;
|
||||
} else {
|
||||
// Hit wall or other obstacle
|
||||
blockedPos = p;
|
||||
blockedPos = points[i - 1];
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user