feat: В класс Paddle добавлен метод для ограничения положения ракетки
This commit is contained in:
@@ -14,4 +14,16 @@ export class Paddle {
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ограничивает минимальные и максимальные координаты положения ракетки на оси X
|
||||
* @param {number} containerWidth ширина игрового поля
|
||||
*/
|
||||
clampTo(containerWidth) {
|
||||
if (this.x <= 0) {
|
||||
this.x = 0;
|
||||
} else if (this.x >= containerWidth - this.width) {
|
||||
this.x = containerWidth - this.width;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user