Commit b529445f authored by Viktor Lidholt's avatar Viktor Lidholt

Adds sounds to demo game

parent 86a8e06a
...@@ -28,6 +28,10 @@ class GameDemoWorld extends NodeWithSize { ...@@ -28,6 +28,10 @@ class GameDemoWorld extends NodeWithSize {
SpriteSheet _spriteSheet; SpriteSheet _spriteSheet;
SpriteSheet _spriteSheetUI; SpriteSheet _spriteSheetUI;
Map<String,SoundEffect> _sounds;
SoundPool _soundPool = SoundPool.sharedInstance();
Navigator _navigator; Navigator _navigator;
// Inputs // Inputs
...@@ -54,7 +58,7 @@ class GameDemoWorld extends NodeWithSize { ...@@ -54,7 +58,7 @@ class GameDemoWorld extends NodeWithSize {
Function _gameOverCallback; Function _gameOverCallback;
GameDemoWorld(App app, this._navigator, ImageMap images, this._spriteSheet, this._spriteSheetUI, this._gameOverCallback) : super(new Size(_gameSizeWidth, _gameSizeHeight)) { GameDemoWorld(App app, this._navigator, ImageMap images, this._spriteSheet, this._spriteSheetUI, this._sounds, this._gameOverCallback) : super(new Size(_gameSizeWidth, _gameSizeHeight)) {
// Fetch images // Fetch images
_imgNebula = images["assets/nebula.png"]; _imgNebula = images["assets/nebula.png"];
...@@ -140,6 +144,8 @@ class GameDemoWorld extends NodeWithSize { ...@@ -140,6 +144,8 @@ class GameDemoWorld extends NodeWithSize {
laser.constrainProportions = true; laser.constrainProportions = true;
_lasers.add(laser); _lasers.add(laser);
_gameLayer.addChild(laser); _gameLayer.addChild(laser);
_soundPool.play(_sounds["laser"]);
} }
void addNebula() { void addNebula() {
...@@ -225,6 +231,8 @@ class GameDemoWorld extends NodeWithSize { ...@@ -225,6 +231,8 @@ class GameDemoWorld extends NodeWithSize {
} }
_gameLayer.addChild(explosionNode); _gameLayer.addChild(explosionNode);
_soundPool.play(_sounds["explosion"]);
} }
void update(double dt) { void update(double dt) {
......
...@@ -28,6 +28,7 @@ ImageMap _loader; ...@@ -28,6 +28,7 @@ ImageMap _loader;
SpriteSheet _spriteSheet; SpriteSheet _spriteSheet;
SpriteSheet _spriteSheetUI; SpriteSheet _spriteSheetUI;
GameDemoApp _app; GameDemoApp _app;
Map<String,SoundEffect> _sounds = {};
main() async { main() async {
_loader = new ImageMap(_bundle); _loader = new ImageMap(_bundle);
...@@ -47,6 +48,12 @@ main() async { ...@@ -47,6 +48,12 @@ main() async {
_app = new GameDemoApp(); _app = new GameDemoApp();
_sounds["explosion"] = new SoundEffect('https://github.com/slembcke/GalacticGuardian.spritebuilder/raw/GDC/Packages/SpriteBuilder%20Resources.sbpack/TempSounds/Explosion.wav');
_sounds["laser"] = new SoundEffect('https://github.com/slembcke/GalacticGuardian.spritebuilder/raw/GDC/Packages/SpriteBuilder%20Resources.sbpack/TempSounds/Laser.wav');
await _sounds["explosion"].load();
await _sounds["laser"].load();
runApp(_app); runApp(_app);
} }
...@@ -103,6 +110,7 @@ class GameDemoApp extends App { ...@@ -103,6 +110,7 @@ class GameDemoApp extends App {
_loader, _loader,
_spriteSheet, _spriteSheet,
_spriteSheetUI, _spriteSheetUI,
_sounds,
(lastScore) { (lastScore) {
setState(() {_lastScore = lastScore;}); setState(() {_lastScore = lastScore;});
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment