65 lines
1.7 KiB
Dart
65 lines
1.7 KiB
Dart
import 'package:flame/components.dart';
|
|
import 'package:flame/effects.dart';
|
|
import 'package:flutter/material.dart';
|
|
import '../components/gem_component.dart';
|
|
import '../../utils/constants.dart';
|
|
|
|
class PhysicsSystem {
|
|
static animateSwap(GemComponent gem1, GemComponent gem2) async {
|
|
final pos1 = gem1.position.clone();
|
|
final pos2 = gem2.position.clone();
|
|
|
|
gem1.add(MoveEffect.to(
|
|
pos2,
|
|
EffectController(duration: GameConstants.swapDuration),
|
|
));
|
|
|
|
gem2.add(MoveEffect.to(
|
|
pos1,
|
|
EffectController(duration: GameConstants.swapDuration),
|
|
));
|
|
await Future.delayed(
|
|
Duration(milliseconds: (GameConstants.swapDuration * 1000).toInt()));
|
|
}
|
|
|
|
static Future<void> animateFall(
|
|
GemComponent gem, Vector2 targetPosition) async {
|
|
final fallDistance = targetPosition.y - gem.position.y;
|
|
final fallTime =
|
|
(fallDistance / 400).clamp(0.2, GameConstants.fallDuration);
|
|
|
|
gem.add(MoveEffect.to(
|
|
targetPosition,
|
|
EffectController(
|
|
duration: fallTime,
|
|
curve: Curves.easeIn,
|
|
),
|
|
));
|
|
await Future.delayed(Duration(milliseconds: (fallTime * 1000).toInt()));
|
|
}
|
|
|
|
static void animateMatch(GemComponent gem) {
|
|
// Scale down and fade out
|
|
gem.add(ScaleEffect.to(
|
|
Vector2.zero(),
|
|
EffectController(duration: GameConstants.matchDuration),
|
|
));
|
|
|
|
gem.add(OpacityEffect.to(
|
|
0.0,
|
|
EffectController(duration: GameConstants.matchDuration),
|
|
));
|
|
}
|
|
|
|
static void animatePop(GemComponent gem) {
|
|
// Quick scale up then down
|
|
gem.add(ScaleEffect.by(
|
|
Vector2.all(1.3),
|
|
EffectController(
|
|
duration: 0.1,
|
|
reverseDuration: 0.1,
|
|
),
|
|
));
|
|
}
|
|
}
|