- Add proper validation for null gems during swap operations - Implement swap-back animation for invalid moves (no matches) - Restructure swap flow to emit animation states before match detection - Add move limit validation before processing matches - Improve error handling and logging for edge cases
66 lines
1.9 KiB
Dart
66 lines
1.9 KiB
Dart
import 'dart:math';
|
|
import 'package:flame/components.dart';
|
|
import 'package:flame/particles.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
|
class ParticleSystem {
|
|
static ParticleSystemComponent createMatchExplosion(
|
|
Vector2 position, Color color) {
|
|
return ParticleSystemComponent(
|
|
priority: 1,
|
|
particle: Particle.generate(
|
|
count: 50,
|
|
lifespan: 1.0,
|
|
generator: (i) => AcceleratedParticle(
|
|
acceleration:
|
|
(Vector2.random(Random()) - Vector2.random(Random())) * 300,
|
|
speed: (Vector2.random(Random()) - Vector2.random(Random())) * 500,
|
|
position: Vector2.zero(),
|
|
child: CircleParticle(
|
|
radius: Random().nextDouble() * 3 + 2,
|
|
paint: Paint()..color = color.withOpacity(0.8),
|
|
),
|
|
),
|
|
),
|
|
position: position,
|
|
);
|
|
}
|
|
|
|
static ParticleSystemComponent createComboEffect(Vector2 position) {
|
|
return ParticleSystemComponent(
|
|
particle: Particle.generate(
|
|
count: 25,
|
|
lifespan: 1.5,
|
|
generator: (i) => AcceleratedParticle(
|
|
acceleration: Vector2(0, -50),
|
|
speed: Vector2.random(Random()) * 150,
|
|
position: Vector2.zero(),
|
|
child: CircleParticle(
|
|
radius: Random().nextDouble() * 4 + 3,
|
|
paint: Paint()..color = Colors.yellow.withOpacity(0.9),
|
|
),
|
|
),
|
|
),
|
|
position: position,
|
|
);
|
|
}
|
|
|
|
static ParticleSystemComponent createSwapTrail(Vector2 start, Vector2 end) {
|
|
return ParticleSystemComponent(
|
|
particle: Particle.generate(
|
|
count: 8,
|
|
lifespan: 0.5,
|
|
generator: (i) => MovingParticle(
|
|
from: Vector2.zero(),
|
|
to: end - start,
|
|
child: CircleParticle(
|
|
radius: 2,
|
|
paint: Paint()..color = Colors.white.withOpacity(0.6),
|
|
),
|
|
),
|
|
),
|
|
position: start,
|
|
);
|
|
}
|
|
}
|