match-three/lib/game/components/particle_system.dart

65 lines
1.8 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: 15,
lifespan: 1.0,
generator: (i) => AcceleratedParticle(
acceleration: Vector2(0, 200),
speed: Vector2.random(Random()) * 100,
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,
);
}
}