OLD | NEW |
(Empty) | |
| 1 library pop_pop_win.audio; |
| 2 |
| 3 import 'dart:math'; |
| 4 |
| 5 import 'package:stagexl/stagexl.dart'; |
| 6 |
| 7 class GameAudio { |
| 8 static final Random _rnd = new Random(); |
| 9 |
| 10 static ResourceManager _resourceManager; |
| 11 |
| 12 static const String _WIN = 'win', |
| 13 _CLICK = 'click', |
| 14 _POP = 'Pop', |
| 15 _FLAG = 'flag', |
| 16 _UNFLAG = 'unflag', |
| 17 _BOMB = 'Bomb', |
| 18 _THROW_DART = 'throw'; |
| 19 |
| 20 static void initialize(ResourceManager resourceManager) { |
| 21 if (_resourceManager != null) throw new StateError('already initialized'); |
| 22 _resourceManager = resourceManager; |
| 23 } |
| 24 |
| 25 static void win() => _playAudio(_WIN); |
| 26 |
| 27 static void click() => _playAudio(_CLICK); |
| 28 |
| 29 static void pop() => _playAudio(_POP); |
| 30 |
| 31 static void flag() => _playAudio(_FLAG); |
| 32 |
| 33 static void unflag() => _playAudio(_UNFLAG); |
| 34 |
| 35 static void bomb() => _playAudio(_BOMB); |
| 36 |
| 37 static void throwDart() => _playAudio(_THROW_DART); |
| 38 |
| 39 static void _playAudio(String name) { |
| 40 if (_resourceManager == null) throw new StateError('Not initialized'); |
| 41 switch (name) { |
| 42 case GameAudio._POP: |
| 43 var i = _rnd.nextInt(8); |
| 44 name = '${GameAudio._POP}$i'; |
| 45 break; |
| 46 case GameAudio._BOMB: |
| 47 var i = _rnd.nextInt(4); |
| 48 name = '${GameAudio._BOMB}$i'; |
| 49 break; |
| 50 } |
| 51 _resourceManager.getSoundSprite('audio').play(name); |
| 52 } |
| 53 } |
OLD | NEW |