Added more sounds, and fixed an audio bug.

This commit is contained in:
Marco Salazar 2021-10-06 12:22:57 -06:00
parent ebc575df88
commit 504fff2a7e
17 changed files with 70 additions and 22 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
assets/audio/sfx/land.mp3 Normal file

Binary file not shown.

BIN
assets/audio/sfx/laser.mp3 Normal file

Binary file not shown.

BIN
assets/audio/sfx/shield.mp3 Normal file

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.0 KiB

1
flutter_01.sksl.json Normal file

File diff suppressed because one or more lines are too long

View File

@ -4,6 +4,8 @@ import 'package:firo_runner/main.dart';
import 'package:flame/components.dart'; import 'package:flame/components.dart';
import 'package:flame/extensions.dart'; import 'package:flame/extensions.dart';
import 'package:flame/flame.dart'; import 'package:flame/flame.dart';
import 'package:flame_audio/flame_audio.dart';
import 'package:audioplayers/src/api/player_mode.dart';
enum FireworkState { normal } enum FireworkState { normal }
@ -108,6 +110,8 @@ class Firework extends Component {
message = messages.elementAt(random.nextInt(messages.length)); message = messages.elementAt(random.nextInt(messages.length));
sprite1.animation!.reset(); sprite1.animation!.reset();
sprite2.animation!.reset(); sprite2.animation!.reset();
FlameAudio.audioCache
.play("sfx/fireworks.mp3", volume: 0.75, mode: PlayerMode.LOW_LATENCY);
} }
void resize(Vector2 newSize, double xRatio, double yRatio) { void resize(Vector2 newSize, double xRatio, double yRatio) {

View File

@ -3,6 +3,8 @@ import 'package:flutter/material.dart';
import 'main.dart'; import 'main.dart';
import 'package:audioplayers/src/api/player_mode.dart';
class LoseMenuOverlay extends StatelessWidget { class LoseMenuOverlay extends StatelessWidget {
const LoseMenuOverlay({ const LoseMenuOverlay({
Key? key, Key? key,
@ -63,8 +65,10 @@ class LoseMenuOverlay extends StatelessWidget {
), ),
), ),
// ), // ),
onPressed: () { onPressed: () async {
// Go to the Main Menu // Go to the Main Menu
await FlameAudio.audioCache.play('sfx/button_click.mp3',
mode: PlayerMode.LOW_LATENCY);
game.mainMenu(); game.mainMenu();
}, },
), ),
@ -94,6 +98,8 @@ class LoseMenuOverlay extends StatelessWidget {
), ),
// ), // ),
onPressed: () async { onPressed: () async {
await FlameAudio.audioCache.play('sfx/button_click.mp3',
mode: PlayerMode.LOW_LATENCY);
game.runner.friend = await FlameAudio.audioCache game.runner.friend = await FlameAudio.audioCache
.loop('sfx/robot_friend_beep.mp3'); .loop('sfx/robot_friend_beep.mp3');
game.reset(); game.reset();

View File

@ -150,14 +150,19 @@ class MyGame extends BaseGame with PanDetector, TapDetector, KeyboardEvents {
FlameAudio.bgm.initialize(); FlameAudio.bgm.initialize();
await FlameAudio.audioCache.loadAll([ await FlameAudio.audioCache.loadAll([
'sfx/bug_chomp.mp3',
'sfx/coin_catch.mp3', 'sfx/coin_catch.mp3',
'sfx/fall_death.mp3',
'sfx/glitch_death.mp3', 'sfx/glitch_death.mp3',
'sfx/jet_boost.mp3', 'sfx/jet_boost.mp3',
'sfx/menu_button.mp3', 'sfx/menu_button.mp3',
'sfx/obstacle_death.mp3', 'sfx/obstacle_death.mp3',
'sfx/robot_friend_beep.mp3', 'sfx/robot_friend_beep.mp3',
'sfx/button_click.mp3',
'sfx/land.mp3',
'sfx/laser.mp3',
'sfx/shield.mp3',
'sfx/bug_death1.mp3',
'sfx/fireworks.mp3',
'sfx/fall_death_speed.mp3',
'Infinite_Menu.mp3', 'Infinite_Menu.mp3',
'Infinite_Spankage_M.mp3', 'Infinite_Spankage_M.mp3',
]); ]);

View File

@ -1,6 +1,7 @@
import 'package:flame_audio/flame_audio.dart'; import 'package:flame_audio/flame_audio.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:audioplayers/src/api/player_mode.dart';
import 'main.dart'; import 'main.dart';
class MainMenuOverlay extends StatelessWidget { class MainMenuOverlay extends StatelessWidget {
@ -66,12 +67,15 @@ class MainMenuOverlay extends StatelessWidget {
// ), // ),
onPressed: () async { onPressed: () async {
// Go to the Main Menu // Go to the Main Menu
FlameAudio.audioCache.play('sfx/menu_button.mp3'); FlameAudio.audioCache.play('sfx/menu_button.mp3',
mode: PlayerMode.LOW_LATENCY);
game.reset(); game.reset();
FlameAudio.bgm.stop(); FlameAudio.bgm.stop();
FlameAudio.bgm.play('Infinite_Spankage_M.mp3'); FlameAudio.bgm.play('Infinite_Spankage_M.mp3');
game.runner.friend = await FlameAudio.audioCache game.runner.friend = await FlameAudio.audioCache.loop(
.loop('sfx/robot_friend_beep.mp3'); 'sfx/robot_friend_beep.mp3',
volume: 0.25,
mode: PlayerMode.LOW_LATENCY);
}, },
), ),
// MaterialButton( // MaterialButton(
@ -98,6 +102,7 @@ class MainMenuOverlay extends StatelessWidget {
// // ), // // ),
// onPressed: () { // onPressed: () {
// // Show QR code // // Show QR code
// await FlameAudio.audioCache.play('sfx/button_click.mp3', mode: PlayerMode.LOW_LATENCY);
// }, // },
// ), // ),
// MaterialButton( // MaterialButton(
@ -124,6 +129,7 @@ class MainMenuOverlay extends StatelessWidget {
// // ), // // ),
// onPressed: () { // onPressed: () {
// // Show QR code // // Show QR code
// await FlameAudio.audioCache.play('sfx/button_click.mp3', mode: PlayerMode.LOW_LATENCY);
// }, // },
// ), // ),
], ],

View File

@ -10,6 +10,7 @@ import 'package:flame/components.dart';
import 'package:flame/image_composition.dart'; import 'package:flame/image_composition.dart';
import 'package:flame_audio/flame_audio.dart'; import 'package:flame_audio/flame_audio.dart';
import 'package:flutter/animation.dart'; import 'package:flutter/animation.dart';
import 'package:audioplayers/src/api/player_mode.dart';
enum RunnerState { enum RunnerState {
run, run,
@ -37,7 +38,7 @@ class Runner extends Component with HasGameRef<MyGame> {
var runnerPosition = Vector2(0, 0); var runnerPosition = Vector2(0, 0);
late Vector2 runnerSize; late Vector2 runnerSize;
bool dead = false; bool dead = false;
late var boost = null; late Future boost;
late var friend = null; late var friend = null;
void setUp() { void setUp() {
@ -81,7 +82,7 @@ class Runner extends Component with HasGameRef<MyGame> {
level = (sprite.position.y / gameRef.blockSize).round(); level = (sprite.position.y / gameRef.blockSize).round();
} }
Future<void> event(String event) async { void event(String event) {
if (gameRef.gameState.isPaused) { if (gameRef.gameState.isPaused) {
return; return;
} }
@ -109,7 +110,7 @@ class Runner extends Component with HasGameRef<MyGame> {
break; break;
} }
previousState = runnerState; previousState = runnerState;
clearEffects(); clearEffects(keepSounds: true);
if (level - 1 < 0) { if (level - 1 < 0) {
break; break;
} }
@ -152,6 +153,8 @@ class Runner extends Component with HasGameRef<MyGame> {
case "kick": case "kick":
previousState = runnerState; previousState = runnerState;
runnerState = event; runnerState = event;
boost = FlameAudio.audioCache
.play('sfx/laser.mp3', volume: 1.0, mode: PlayerMode.LOW_LATENCY);
switch (gameRef.gameState.getRobotLevel()) { switch (gameRef.gameState.getRobotLevel()) {
case 3: case 3:
sprite.current = RunnerState.kick3; sprite.current = RunnerState.kick3;
@ -172,6 +175,8 @@ class Runner extends Component with HasGameRef<MyGame> {
case "float": case "float":
previousState = runnerState; previousState = runnerState;
runnerState = event; runnerState = event;
boost = FlameAudio.audioCache.play('sfx/jet_boost.mp3',
volume: 0.25, mode: PlayerMode.LOW_LATENCY);
switch (gameRef.gameState.getRobotLevel()) { switch (gameRef.gameState.getRobotLevel()) {
case 3: case 3:
sprite.current = RunnerState.float3; sprite.current = RunnerState.float3;
@ -183,14 +188,13 @@ class Runner extends Component with HasGameRef<MyGame> {
sprite.current = RunnerState.float; sprite.current = RunnerState.float;
break; break;
} }
boost = await FlameAudio.audioCache.play('sfx/jet_boost.mp3');
sprite.addEffect(MoveEffect( sprite.addEffect(MoveEffect(
path: [sprite.position], path: [sprite.position],
duration: 1.5, duration: 1.5,
curve: Curves.ease, curve: Curves.ease,
onComplete: () { onComplete: () {
updateLevel(); updateLevel();
boost.stop(); // boost.stop();
if (onTopOfPlatform()) { if (onTopOfPlatform()) {
this.event("run"); this.event("run");
} else { } else {
@ -202,6 +206,8 @@ class Runner extends Component with HasGameRef<MyGame> {
case "duck": case "duck":
previousState = runnerState; previousState = runnerState;
runnerState = event; runnerState = event;
boost = FlameAudio.audioCache
.play('sfx/shield.mp3', volume: 0.25, mode: PlayerMode.LOW_LATENCY);
switch (gameRef.gameState.getRobotLevel()) { switch (gameRef.gameState.getRobotLevel()) {
case 3: case 3:
sprite.current = RunnerState.duck3; sprite.current = RunnerState.duck3;
@ -218,6 +224,10 @@ class Runner extends Component with HasGameRef<MyGame> {
duration: 1.5, duration: 1.5,
curve: Curves.linear, curve: Curves.linear,
onComplete: () { onComplete: () {
if (boost != null) {
boost.then((value) => value.stop());
}
// boost.stop();
this.event("run"); this.event("run");
}, },
)); ));
@ -226,7 +236,8 @@ class Runner extends Component with HasGameRef<MyGame> {
if (dead) { if (dead) {
return; return;
} }
await FlameAudio.audioCache.play('sfx/fall_death.mp3'); FlameAudio.audioCache.play('sfx/fall_death_speed.mp3',
volume: 0.5, mode: PlayerMode.LOW_LATENCY);
previousState = runnerState; previousState = runnerState;
clearEffects(); clearEffects();
runnerState = event; runnerState = event;
@ -240,7 +251,8 @@ class Runner extends Component with HasGameRef<MyGame> {
if (dead) { if (dead) {
return; return;
} }
await FlameAudio.audioCache.play('sfx/fall_death.mp3'); FlameAudio.audioCache.play('sfx/fall_death_speed.mp3',
volume: 0.5, mode: PlayerMode.LOW_LATENCY);
previousState = runnerState; previousState = runnerState;
clearEffects(); clearEffects();
runnerState = event; runnerState = event;
@ -254,7 +266,8 @@ class Runner extends Component with HasGameRef<MyGame> {
if (dead) { if (dead) {
return; return;
} }
await FlameAudio.play('sfx/glitch_death.mp3'); FlameAudio.audioCache.play('sfx/glitch_death.mp3',
volume: 0.5, mode: PlayerMode.LOW_LATENCY);
previousState = runnerState; previousState = runnerState;
clearEffects(); clearEffects();
runnerState = event; runnerState = event;
@ -292,6 +305,8 @@ class Runner extends Component with HasGameRef<MyGame> {
onComplete: () { onComplete: () {
updateLevel(); updateLevel();
if (onTopOfPlatform()) { if (onTopOfPlatform()) {
FlameAudio.audioCache
.play('sfx/land.mp3', mode: PlayerMode.LOW_LATENCY);
event("run"); event("run");
} else { } else {
event("fall"); event("fall");
@ -309,6 +324,8 @@ class Runner extends Component with HasGameRef<MyGame> {
curve: Curves.ease, curve: Curves.ease,
onComplete: () { onComplete: () {
updateLevel(); updateLevel();
FlameAudio.audioCache
.play('sfx/land.mp3', mode: PlayerMode.LOW_LATENCY);
if (onTopOfPlatform()) { if (onTopOfPlatform()) {
event("run"); event("run");
} else { } else {
@ -380,6 +397,8 @@ class Runner extends Component with HasGameRef<MyGame> {
if (onTopOfPlatform()) { if (onTopOfPlatform()) {
updateLevel(); updateLevel();
clearEffects(); clearEffects();
FlameAudio.audioCache
.play('sfx/land.mp3', mode: PlayerMode.LOW_LATENCY);
event("run"); event("run");
} }
} }
@ -428,7 +447,7 @@ class Runner extends Component with HasGameRef<MyGame> {
return belowPlatform; return belowPlatform;
} }
Future<void> intersecting() async { void intersecting() {
if (gameRef.gameState.isPaused) { if (gameRef.gameState.isPaused) {
return; return;
} }
@ -439,7 +458,8 @@ class Runner extends Component with HasGameRef<MyGame> {
for (int i = 0; i < coinLevel.length;) { for (int i = 0; i < coinLevel.length;) {
if (coinLevel[i].intersect(runnerRect) != "none") { if (coinLevel[i].intersect(runnerRect) != "none") {
gameRef.gameState.numCoins++; gameRef.gameState.numCoins++;
await FlameAudio.audioCache.play('sfx/coin_catch.mp3'); FlameAudio.audioCache.play('sfx/coin_catch.mp3',
volume: 0.25, mode: PlayerMode.LOW_LATENCY);
gameRef.coinHolder.remove(coinLevel, i); gameRef.coinHolder.remove(coinLevel, i);
continue; continue;
} }
@ -477,7 +497,8 @@ class Runner extends Component with HasGameRef<MyGame> {
return; return;
} }
} else if (intersectState == "left" && runnerState == "kick") { } else if (intersectState == "left" && runnerState == "kick") {
await FlameAudio.audioCache.play('sfx/bug_chomp.mp3'); FlameAudio.audioCache
.play('sfx/bug_death1.mp3', mode: PlayerMode.LOW_LATENCY);
bugLevel[i].sprite.current = BugState.breaking; bugLevel[i].sprite.current = BugState.breaking;
gameRef.coinHolder.generateCoin(gameRef, level, gameRef.coinHolder.generateCoin(gameRef, level,
force: true, xPosition: bugLevel[i].sprite.x + gameRef.blockSize); force: true, xPosition: bugLevel[i].sprite.x + gameRef.blockSize);
@ -501,7 +522,8 @@ class Runner extends Component with HasGameRef<MyGame> {
} else if (runnerState == "duck" && intersectState != "above") { } else if (runnerState == "duck" && intersectState != "above") {
continue; continue;
} else { } else {
await FlameAudio.audioCache.play('sfx/obstacle_death.mp3'); FlameAudio.audioCache
.play('sfx/obstacle_death.mp3', mode: PlayerMode.LOW_LATENCY);
event("die"); event("die");
} }
} }
@ -518,7 +540,8 @@ class Runner extends Component with HasGameRef<MyGame> {
if (intersectState == "none") { if (intersectState == "none") {
continue; continue;
} else { } else {
await FlameAudio.audioCache.play('sfx/obstacle_death.mp3'); FlameAudio.audioCache
.play('sfx/obstacle_death.mp3', mode: PlayerMode.LOW_LATENCY);
event("die"); event("die");
} }
} }
@ -534,6 +557,8 @@ class Runner extends Component with HasGameRef<MyGame> {
} }
Future load() async { Future load() async {
boost = FlameAudio.audioCache
.play('sfx/laser.mp3', volume: 0.0, mode: PlayerMode.LOW_LATENCY);
List<Image> satellites = []; List<Image> satellites = [];
for (int i = 1; i <= 38; i++) { for (int i = 1; i <= 38; i++) {
satellites.add(await Flame.images.load( satellites.add(await Flame.images.load(
@ -580,7 +605,7 @@ class Runner extends Component with HasGameRef<MyGame> {
await loadSpriteAnimation("death2", 57, loop: false); await loadSpriteAnimation("death2", 57, loop: false);
SpriteAnimation dyingGlitch = SpriteAnimation dyingGlitch =
await loadSpriteAnimation("death1", 81, loop: false); await loadSpriteAnimation("death1", 82, loop: false);
sprite = SpriteAnimationGroupComponent( sprite = SpriteAnimationGroupComponent(
animations: { animations: {
@ -638,8 +663,9 @@ class Runner extends Component with HasGameRef<MyGame> {
void clearEffects({bool keepSounds = false}) { void clearEffects({bool keepSounds = false}) {
sprite.clearEffects(); sprite.clearEffects();
if (!keepSounds) { if (!keepSounds && boost != null) {
boost.stop(); // boost.stop();
boost.then((value) => value.stop());
} }
} }
} }