Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(750)

Unified Diff: samples/pop_pop_win/lib/src/audio.dart

Issue 242443008: samples/pop_pop_win: now based on StageXL (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: tiny nit Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « samples/pop_pop_win/lib/pop_pop_win.dart ('k') | samples/pop_pop_win/lib/src/canvas.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: samples/pop_pop_win/lib/src/audio.dart
diff --git a/samples/pop_pop_win/lib/src/audio.dart b/samples/pop_pop_win/lib/src/audio.dart
new file mode 100644
index 0000000000000000000000000000000000000000..431759e72daefb95a1bb2fa418bef237409c2a37
--- /dev/null
+++ b/samples/pop_pop_win/lib/src/audio.dart
@@ -0,0 +1,53 @@
+library pop_pop_win.audio;
+
+import 'dart:math';
+
+import 'package:stagexl/stagexl.dart';
+
+class GameAudio {
+ static final Random _rnd = new Random();
+
+ static ResourceManager _resourceManager;
+
+ static const String _WIN = 'win',
+ _CLICK = 'click',
+ _POP = 'Pop',
+ _FLAG = 'flag',
+ _UNFLAG = 'unflag',
+ _BOMB = 'Bomb',
+ _THROW_DART = 'throw';
+
+ static void initialize(ResourceManager resourceManager) {
+ if (_resourceManager != null) throw new StateError('already initialized');
+ _resourceManager = resourceManager;
+ }
+
+ static void win() => _playAudio(_WIN);
+
+ static void click() => _playAudio(_CLICK);
+
+ static void pop() => _playAudio(_POP);
+
+ static void flag() => _playAudio(_FLAG);
+
+ static void unflag() => _playAudio(_UNFLAG);
+
+ static void bomb() => _playAudio(_BOMB);
+
+ static void throwDart() => _playAudio(_THROW_DART);
+
+ static void _playAudio(String name) {
+ if (_resourceManager == null) throw new StateError('Not initialized');
+ switch (name) {
+ case GameAudio._POP:
+ var i = _rnd.nextInt(8);
+ name = '${GameAudio._POP}$i';
+ break;
+ case GameAudio._BOMB:
+ var i = _rnd.nextInt(4);
+ name = '${GameAudio._BOMB}$i';
+ break;
+ }
+ _resourceManager.getSoundSprite('audio').play(name);
+ }
+}
« no previous file with comments | « samples/pop_pop_win/lib/pop_pop_win.dart ('k') | samples/pop_pop_win/lib/src/canvas.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698