diff --git a/assets/audio/HoldLabs-Music.mp3 b/assets/audio/HoldLabs-Music.mp3 new file mode 100644 index 0000000..fb22170 Binary files /dev/null and b/assets/audio/HoldLabs-Music.mp3 differ diff --git a/assets/images/Tiles.png b/assets/images/Tiles.png index 1cc9ba3..5c914ca 100644 Binary files a/assets/images/Tiles.png and b/assets/images/Tiles.png differ diff --git a/assets/tiles/Level2.tmx b/assets/tiles/Level2.tmx index a9fbf6c..c57f15f 100644 --- a/assets/tiles/Level2.tmx +++ b/assets/tiles/Level2.tmx @@ -94,7 +94,7 @@ - + diff --git a/lib/game/game.dart b/lib/game/game.dart index 6a23815..9f09475 100644 --- a/lib/game/game.dart +++ b/lib/game/game.dart @@ -1,8 +1,10 @@ import 'dart:async'; +import 'dart:math'; import 'package:flame/components.dart'; import 'package:flame/game.dart'; import 'package:flame/input.dart'; +import 'package:flame_audio/flame_audio.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:hold_labs/game/level.dart'; @@ -35,12 +37,15 @@ class HoldLabsGame extends FlameGame 'Buttons.png', ], ); - changeLevel(2); + + FlameAudio.bgm.initialize(); + await FlameAudio.bgm.play('HoldLabs-Music.mp3', volume: 0.8); + changeLevel(1); } void changeLevel(int levelId) { currentLevel?.removeFromParent(); - currentLevel = Level(levelId); + currentLevel = Level(min(levelId, 2)); world.add(currentLevel!); } } diff --git a/lib/game/level.dart b/lib/game/level.dart index d456d57..dea5aeb 100644 --- a/lib/game/level.dart +++ b/lib/game/level.dart @@ -170,6 +170,7 @@ class Level extends PositionComponent with HasGameReference { ?.split('audio/') .last; if (audioPath != null) { + FlameAudio.bgm.pause(); _player.moveLock = true; await FlameAudio.audioCache.load(audioPath); @@ -179,6 +180,7 @@ class Level extends PositionComponent with HasGameReference { audioplayer.onPlayerComplete.listen( (event) { _player.moveLock = false; + FlameAudio.bgm.resume(); }, ); } @@ -237,15 +239,15 @@ class Level extends PositionComponent with HasGameReference { audioTrigger.removeFromParent(); if (holdInput) { + FlameAudio.bgm.pause(); _player.moveLock = true; } final audioplayer = await FlameAudio.playLongAudio(filename); - if (holdInput) { - audioplayer.onPlayerComplete.listen((event) { - _player.moveLock = false; - }); - } + audioplayer.onPlayerComplete.listen((event) { + _player.moveLock = false; + FlameAudio.bgm.resume(); + }); } } diff --git a/lib/game/player.dart b/lib/game/player.dart index ca001ea..722d890 100644 --- a/lib/game/player.dart +++ b/lib/game/player.dart @@ -20,7 +20,13 @@ class Player extends PositionComponent bool jump = false; bool _isOnGround = false; - bool moveLock = false; + bool _moveLock = false; + set moveLock(bool value) { + _moveLock = value; + if (_moveLock) { + hAxisValue = 0; + } + } final _gravity = 10 * 60.0; final _moveSpeed = 100.0; @@ -170,7 +176,7 @@ class Player extends PositionComponent hAxisValue = 0; vAxisValue = 0; - if (!moveLock) { + if (!_moveLock) { hAxisValue += keysPressed.contains(LogicalKeyboardKey.keyA) ? -1 : 0; hAxisValue += keysPressed.contains(LogicalKeyboardKey.keyD) ? 1 : 0; diff --git a/tiled-project/Level2.tmx b/tiled-project/Level2.tmx index 2dd2099..c836bf0 100644 --- a/tiled-project/Level2.tmx +++ b/tiled-project/Level2.tmx @@ -95,7 +95,7 @@ - + diff --git a/tiled-project/hold-labs.tiled-session b/tiled-project/hold-labs.tiled-session index e15906d..20ea0e3 100644 --- a/tiled-project/hold-labs.tiled-session +++ b/tiled-project/hold-labs.tiled-session @@ -3,7 +3,7 @@ "height": 4300, "width": 2 }, - "activeFile": "Level1.tmx", + "activeFile": "Level2.tmx", "expandedProjectPaths": [ "." ], @@ -15,14 +15,14 @@ }, "Level1.tmx": { "expandedObjectLayers": [ - 4, - 2 + 2, + 4 ], "scale": 1, "selectedLayer": 1, "viewCenter": { - "x": 265.5, - "y": 100 + "x": 264.5, + "y": 99 } }, "Level2.tmx": { @@ -31,16 +31,16 @@ 4, 2 ], - "scale": 4, - "selectedLayer": 2, + "scale": 0.75, + "selectedLayer": 3, "viewCenter": { - "x": 273.125, - "y": 230.5 + "x": 372.6666666666667, + "y": 277.33333333333337 } }, "Tiles.tsx": { "dynamicWrapping": true, - "scaleInDock": 2, + "scaleInDock": 4, "scaleInEditor": 4 } }, @@ -54,14 +54,14 @@ "map.width": 50, "openFiles": [ "Level1.tmx", - "Bricks.tsx" + "Level2.tmx" ], "project": "hold-labs.tiled-project", "property.type": "bool", "recentFiles": [ + "Level1.tmx", "Level2.tmx", "Tiles.tsx", - "Level1.tmx", "Bricks.tsx" ], "tileset.lastUsedFormat": "tsx",