This repository has been archived by the owner on Mar 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
71 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
packages/trashy_road/lib/src/game/entities/trash/behaviors/behaviors.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export 'trash_shaking_behavior.dart'; |
44 changes: 44 additions & 0 deletions
44
packages/trashy_road/lib/src/game/entities/trash/behaviors/trash_shaking_behavior.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import 'dart:async'; | ||
import 'dart:math'; | ||
|
||
import 'package:flame/components.dart'; | ||
import 'package:flame/effects.dart'; | ||
import 'package:flame_behaviors/flame_behaviors.dart'; | ||
import 'package:flame_noise/flame_noise.dart'; | ||
import 'package:trashy_road/src/game/game.dart'; | ||
|
||
final _random = Random(0); | ||
|
||
/// Shakes the [Trash] around every now and then. | ||
/// | ||
/// This is to catch the player's attention so they know that the [Trash] is | ||
/// interactable and needs to be collected. | ||
class TrashShakingBehavior extends Behavior<Trash> { | ||
final _shakeDistance = Vector2(10, 4); | ||
|
||
@override | ||
FutureOr<void> onLoad() async { | ||
await super.onLoad(); | ||
|
||
add( | ||
TimerComponent( | ||
repeat: true, | ||
period: 2 + _random.nextDouble() * 2, | ||
onTick: () { | ||
parent.add( | ||
MoveEffect.by( | ||
_shakeDistance, | ||
NoiseEffectController( | ||
noise: WhiteNoise( | ||
seed: _random.nextInt(100), | ||
frequency: 5, | ||
), | ||
duration: 0.5, | ||
), | ||
), | ||
); | ||
}, | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters