Skip to content
This repository has been archived by the owner on Mar 13, 2024. It is now read-only.

Commit

Permalink
feat: add game_over and stage_pass effects
Browse files Browse the repository at this point in the history
  • Loading branch information
alestiago committed Mar 11, 2024
1 parent 83fc2d3 commit bb303fb
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 4 deletions.
Binary file added packages/trashy_road/assets/audio/game_over.mp3
Binary file not shown.
Binary file not shown.
Binary file modified packages/trashy_road/assets/audio/step1.mp3
Binary file not shown.
Binary file removed packages/trashy_road/assets/audio/steps.mp3
Binary file not shown.
8 changes: 8 additions & 0 deletions packages/trashy_road/lib/gen/assets.gen.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions packages/trashy_road/lib/src/audio/bloc/audio_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ class AudioCubit extends Cubit<AudioState> {
GameSoundEffects.ratingStars2: AudioPlayer()..audioCache = _audioCache,
GameSoundEffects.ratingStars3: AudioPlayer()..audioCache = _audioCache,
GameSoundEffects.runningTime: AudioPlayer()..audioCache = _audioCache,
GameSoundEffects.gameOver: AudioPlayer()..audioCache = _audioCache,
GameSoundEffects.stagePass: AudioPlayer()..audioCache = _audioCache,
};

late final Map<GameAudioData, Future<AudioPool>> _pools = {
Expand Down
18 changes: 14 additions & 4 deletions packages/trashy_road/lib/src/audio/bloc/audio_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -84,17 +84,17 @@ abstract class GameSoundEffects {

static final ratingStars1 = GameAudioData.fromPath(
Assets.audio.ratingStars1,
volume: 0.35,
volume: 0.45,
);

static final ratingStars2 = GameAudioData.fromPath(
Assets.audio.ratingStars2,
volume: 0.35,
volume: 0.45,
);

static final ratingStars3 = GameAudioData.fromPath(
Assets.audio.ratingStars3,
volume: 0.35,
volume: 0.45,
);

static final wrongBin = GameAudioData.fromPath(
Expand All @@ -104,11 +104,21 @@ abstract class GameSoundEffects {

static final step1 = GameAudioData.fromPath(
Assets.audio.step1,
volume: 0.35,
volume: 0.2,
);

static final runningTime = GameAudioData.fromPath(
Assets.audio.runningTime,
volume: 0.3,
);

static final gameOver = GameAudioData.fromPath(
Assets.audio.gameOver,
volume: 0.3,
);

static final stagePass = GameAudioData.fromPath(
Assets.audio.stagePass,
volume: 0.2,
);
}
4 changes: 4 additions & 0 deletions packages/trashy_road/lib/src/game/view/game_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:tiled/tiled.dart';
import 'package:trashy_road/gen/gen.dart';
import 'package:trashy_road/src/audio/audio.dart';
import 'package:trashy_road/src/game/game.dart';
import 'package:trashy_road/src/loading/loading.dart';
import 'package:trashy_road/src/maps/maps.dart';
Expand Down Expand Up @@ -109,6 +110,8 @@ class _GameCompletionListener extends BlocListener<GameBloc, GameState> {
state.score != null,
'The game is completed, but the score is null.',
);
context.read<AudioCubit>().playEffect(GameSoundEffects.stagePass);

final gameMapsBloc = context.read<GameMapsBloc>();
final gameMap = gameMapsBloc.state.maps[state.identifier];
final scoreRating = ScoreRating.fromSteps(
Expand Down Expand Up @@ -140,6 +143,7 @@ class _GameLostRunnedOverListener extends BlocListener<GameBloc, GameState> {
current.status == GameStatus.lost &&
current.lostReason == GameLostReason.vehicleRunningOver,
listener: (context, state) {
context.read<AudioCubit>().playEffect(GameSoundEffects.gameOver);
context.read<GameBloc>().add(const GameResetEvent());
},
);
Expand Down

0 comments on commit bb303fb

Please sign in to comment.