feat: add heart beat for timing

This commit is contained in:
2026-06-19 02:28:07 +03:30
parent a4cf2b5f39
commit c4c1453f7e
6 changed files with 476 additions and 246 deletions
@@ -42,13 +42,28 @@ class CardComponent extends PositionComponent
}
}
// بزرگ‌نماییِ کارتِ انتخاب‌شده هنگام کشیدن (واضح‌تر برای دیدن).
static const _dragScale = 1.4;
void _scaleTo(double s) {
children.whereType<ScaleEffect>().toList().forEach((e) => e.removeFromParent());
add(ScaleEffect.to(
Vector2.all(s), EffectController(duration: 0.12, curve: Curves.easeOut)));
}
/// بازنشانیِ فوریِ مقیاس به اندازه‌ی عادی (هنگام بازی روی میز).
void resetScale() {
children.whereType<ScaleEffect>().toList().forEach((e) => e.removeFromParent());
scale = Vector2.all(1);
}
@override
void onDragStart(DragStartEvent event) {
super.onDragStart(event);
if (!_playable) return;
_dragging = true;
priority = 1000; // روی همه‌ی کارت‌ها
scale = Vector2.all(1.12); // بزرگ‌نمایی هنگام کشیدن (فیدبک)
_scaleTo(_dragScale); // بزرگ‌نماییِ نرم هنگام انتخاب
}
@override
@@ -63,11 +78,13 @@ class CardComponent extends PositionComponent
super.onDragEnd(event);
if (!_dragging) return;
_dragging = false;
scale = Vector2.all(1);
// فقط اگر داخل ناحیه‌ی وسط میز رها شد ⇒ بازی؛ وگرنه برگشت به جای مرتبِ خود.
// فقط اگر داخل ناحیه‌ی وسط میز رها شد ⇒ بازی (اندازه به حالت عادی)؛
// وگرنه برگشت به جای مرتبِ خود.
if (_inDropZone()) {
resetScale();
onPlay?.call();
} else {
_scaleTo(1);
_returnHome();
}
_overZone = false;
@@ -79,7 +96,7 @@ class CardComponent extends PositionComponent
if (!_dragging) return;
_dragging = false;
_overZone = false;
scale = Vector2.all(1);
_scaleTo(1);
_returnHome();
}
@@ -147,15 +164,15 @@ class CardComponent extends PositionComponent
..color = const Color(0xFF1A1A1A),
);
// هایلایت طلایی وقتی کارت روی ناحیه‌ی انداختن است (رهاکنی، بازی می‌شود).
if (_dragging && _overZone) {
// هایلایت طلایی: هنگام کشیدن همیشه (انتخاب)، و پررنگ‌تر روی ناحیه‌ی انداختن.
if (_dragging) {
canvas.drawRRect(
rrect,
Paint()
..style = PaintingStyle.stroke
..strokeWidth = size.x * 0.06
..strokeWidth = size.x * (_overZone ? 0.06 : 0.035)
..color = const Color(0xFFE9B949)
..maskFilter = const MaskFilter.blur(BlurStyle.normal, 6),
..maskFilter = MaskFilter.blur(BlurStyle.normal, _overZone ? 6 : 3),
);
}
}