import { TILE } from '../core/constants.js'; import { state } from '../core/state.js'; import { getBlock } from '../world/world-storage.js'; import { playSound } from '../audio/sound-engine.js'; function isWaterAt(px, py) { const gx = Math.floor(px / TILE); const gy = Math.floor(py / TILE); const b = getBlock(gx, gy); return !!(b && b.t === 'water'); } function updateWaterFlag(e) { const cx = e.x + e.w / 2; const wasInWater = e.inWater; // В воде, если в воде хотя бы центр/ноги (чтобы корректно работать у поверхности) const mid = isWaterAt(cx, e.y + e.h / 2); const feet = isWaterAt(cx, e.y + e.h - 2); e.inWater = mid || feet; // Голова под водой — для кислорода/урона e.headInWater = isWaterAt(cx, e.y + 4); // Звук при падении в воду if (e === state.player && !wasInWater && e.inWater && e.vy > 100) { playSound('splash'); } } export { isWaterAt, updateWaterFlag };