Skip to content

Commit

Permalink
chore: update flame (#38)
Browse files Browse the repository at this point in the history
* chore: update flame

* chore: update flame
  • Loading branch information
renancaraujo authored Oct 10, 2023
1 parent 97175d7 commit 717bbe2
Show file tree
Hide file tree
Showing 8 changed files with 162 additions and 165 deletions.
2 changes: 1 addition & 1 deletion android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {

compileSdkVersion 32
compileSdkVersion 33

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
Expand Down
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ subprojects {
project.evaluationDependsOn(':app')
}

task clean(type: Delete) {
tasks.register("clean", Delete) {
delete rootProject.buildDir
}
7 changes: 2 additions & 5 deletions lib/bootstrap.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class AppBlocObserver extends BlocObserver {
@override
void onChange(BlocBase<dynamic> bloc, Change<dynamic> change) {
super.onChange(bloc, change);
// log('onChange(${bloc.runtimeType}, $change)');
log('onChange(${bloc.runtimeType}, $change)');
}

@override
Expand All @@ -33,8 +33,5 @@ Future<void> bootstrap(FutureOr<Widget> Function() builder) async {

Bloc.observer = AppBlocObserver();

await runZonedGuarded(
() async => runApp(await builder()),
(error, stackTrace) => log(error.toString(), stackTrace: stackTrace),
);
runApp(await builder());
}
27 changes: 14 additions & 13 deletions lib/game/game/hud.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'dart:ui';

import 'package:flame/camera.dart';
import 'package:flame/components.dart';
import 'package:flame/palette.dart';
import 'package:watchsteroids/app/app.dart';
Expand All @@ -10,7 +11,7 @@ class NoiseOverlay extends SpriteComponent with HasGameRef<WatchsteroidsGame> {

@override
Future<void> onLoad() async {
size = Vector2.all(600);
size = Vector2.all(500);
sprite = await gameRef.loadSprite('noise7.png');
}

Expand All @@ -22,7 +23,7 @@ class NoiseOverlay extends SpriteComponent with HasGameRef<WatchsteroidsGame> {
@override
void update(double dt) {
super.update(dt);
position = gameRef.camera.position * -0.35;
position = gameRef.cameraSubject.position * -0.5;
}
}

Expand All @@ -41,26 +42,26 @@ class NoiseAdd extends SpriteComponent with HasGameRef<WatchsteroidsGame> {
@override
void update(double dt) {
super.update(dt);
position = gameRef.camera.position * -0.15;
position = gameRef.cameraSubject.position * 0.15;
}
}

class Vignette extends RectangleComponent with HasGameRef<WatchsteroidsGame> {
@override
Future<void> onLoad() async {
size = Vector2(400, 400);
final parent = this.parent! as Viewport;
size = parent.size;
priority = 100;

paint = BasicPalette.white.paint()
..shader = Gradient.radial(
(size / 2).toOffset(),
(size / 2).x,
[WatchsteroidsColors.transparent, const Color(0xff000000)],
[0.45, 1.0],
);
}

@override
PositionType positionType = PositionType.viewport;

@override
Paint paint = BasicPalette.white.paint()
..shader = Gradient.radial(
const Offset(200, 200),
200,
[WatchsteroidsColors.transparent, const Color(0xFF000000)],
[0.45, 1.0],
);
}
26 changes: 13 additions & 13 deletions lib/game/game/watchsteroids_game.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@ class WatchsteroidsGame extends FlameGame with HasCollisionDetection {
required this.rotationCubit,
required this.gameCubit,
required this.scoreCubit,
});
}) : super(
camera: CameraComponent.withFixedResolution(
width: 400,
height: 400,
hudComponents: [Vignette()],
),
);

final RotationCubit rotationCubit;
final GameCubit gameCubit;
Expand All @@ -28,9 +34,7 @@ class WatchsteroidsGame extends FlameGame with HasCollisionDetection {

@override
Future<void> onLoad() async {
await add(Radar());

await add(
await world.add(
flameMultiBlocProvider = FlameMultiBlocProvider(
providers: [
FlameBlocProvider<RotationCubit, RotationState>.value(
Expand All @@ -51,15 +55,11 @@ class WatchsteroidsGame extends FlameGame with HasCollisionDetection {
),
);

await add(NoiseAdd());
await add(NoiseOverlay());

await add(Vignette());
await add(cameraSubject = CameraSubject());

camera
..followComponent(cameraSubject)
..viewport = FixedResolutionViewport(Vector2(400, 400));
await world.add(NoiseAdd());
await world.add(Radar());
await world.add(NoiseOverlay());
await world.add(cameraSubject = CameraSubject());
camera.follow(cameraSubject);
}
}

Expand Down
4 changes: 2 additions & 2 deletions lib/game/widgets/overlays.dart
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ class CreditsOverlay extends StatelessWidget {
),
child: Opacity(
opacity: progress,
child: Column(
children: const [
child: const Column(
children: [
Spacer(),
Text(
'Made with ❤️ by',
Expand Down
Loading

0 comments on commit 717bbe2

Please sign in to comment.