mirror of
https://github.com/flame-engine/flame.git
synced 2025-11-01 10:38:17 +08:00
27 lines
616 B
Dart
27 lines
616 B
Dart
import 'dart:math';
|
|
|
|
import 'package:flame/components.dart';
|
|
import 'package:rogue_shooter/components/enemy_component.dart';
|
|
|
|
class EnemyCreator extends TimerComponent with HasGameReference {
|
|
final Random random = Random();
|
|
final _halfWidth = EnemyComponent.initialSize.x / 2;
|
|
|
|
EnemyCreator() : super(period: 0.05, repeat: true);
|
|
|
|
@override
|
|
void onTick() {
|
|
game.addAll(
|
|
List.generate(
|
|
5,
|
|
(index) => EnemyComponent(
|
|
position: Vector2(
|
|
_halfWidth + (game.size.x - _halfWidth) * random.nextDouble(),
|
|
0,
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|