feat(spawnRandomPerk): Добавлена функция создания случайного бонуса по заданым координатам

This commit is contained in:
Ilia Mashkov
2026-07-19 15:08:22 +03:00
parent b2f0810ec2
commit a4c4e2a192
3 changed files with 58 additions and 0 deletions
@@ -0,0 +1,28 @@
import { PERK_FALL_SPEED, PERK_HEIGHT, PERK_WIDTH } from '../../config';
import { Perk } from '../../entities/perk/perk';
/**
* Типы бонусов
*/
const DROPPABLE_PERKS = ['slow'];
/**
* Создает случайный бонус в заданной точке
* @param {number} x координата бонуса по оси X
* @param {number} y координата бонуса по оси Y
* @returns {Perk | null}
*/
export function spawnRandomPerk(x, y) {
try {
if (typeof x !== 'number' || typeof y !== 'number') {
throw new Error('Координаты бонуса должны являться числами');
}
const type = DROPPABLE_PERKS[Math.floor(Math.random() * DROPPABLE_PERKS.length)];
return new Perk(x, y, PERK_WIDTH, PERK_HEIGHT, type, PERK_FALL_SPEED);
} catch (err) {
console.error(err);
return null;
}
}