mirror of
https://github.com/flame-engine/flame.git
synced 2025-11-01 19:12:31 +08:00
Update min Dart constraint to 3.8, which will enable us to use the fancier collection literals. This requires bumping the min Flutter version as well: <img width="1892" height="1122" alt="image" src="https://github.com/user-attachments/assets/7c7b07fc-4d96-4987-824d-9a7133ecfb85" />
55 lines
1.6 KiB
Dart
55 lines
1.6 KiB
Dart
import 'package:flame/extensions.dart';
|
|
import 'package:flame_oxygen/flame_oxygen.dart';
|
|
import 'package:flame_oxygen_example/component/timer_component.dart';
|
|
import 'package:flame_oxygen_example/component/velocity_component.dart';
|
|
import 'package:flame_oxygen_example/main.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
|
class MoveSystem extends System with UpdateSystem, GameRef<ExampleGame> {
|
|
Query? _query;
|
|
|
|
@override
|
|
void init() {
|
|
_query = createQuery([
|
|
Has<PositionComponent>(),
|
|
Has<VelocityComponent>(),
|
|
]);
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
_query = null;
|
|
super.dispose();
|
|
}
|
|
|
|
@override
|
|
void update(double delta) {
|
|
for (final entity in _query?.entities ?? <Entity>[]) {
|
|
final velocity = entity.get<VelocityComponent>()!.velocity;
|
|
final size = entity.get<SizeComponent>()!.size;
|
|
final position = entity.get<PositionComponent>()!.position
|
|
..add(velocity * delta);
|
|
|
|
final screenSize = Vector2.zero() & game!.size;
|
|
if (!screenSize.containsPoint(position) ||
|
|
!screenSize.containsPoint(position + size)) {
|
|
velocity.setFrom(-velocity);
|
|
|
|
game!.createEntity(
|
|
name: '${entity.name} says',
|
|
position: position + size / 2,
|
|
size: Vector2.zero(),
|
|
anchor: Anchor.topCenter,
|
|
)
|
|
..add<TextComponent, TextInit>(
|
|
TextInit(
|
|
'Kawabunga',
|
|
style: const TextStyle(color: Colors.blue, fontSize: 12),
|
|
),
|
|
)
|
|
..add<TimerComponent, double>(3);
|
|
}
|
|
}
|
|
}
|
|
}
|