| OLD | NEW |
| 1 library game; | 1 library game; |
| 2 | 2 |
| 3 import 'dart:html'; | 3 import 'dart:html'; |
| 4 import 'dart:web_audio'; | 4 import 'dart:web_audio'; |
| 5 import 'package:bot/bot.dart'; | 5 import 'package:bot/bot.dart'; |
| 6 import 'package:bot_web/bot_html.dart'; | 6 import 'package:bot_web/bot_html.dart'; |
| 7 import 'package:bot_web/bot_texture.dart'; | 7 import 'package:bot_web/bot_texture.dart'; |
| 8 import 'package:poppopwin/canvas.dart'; | 8 import 'package:poppopwin/canvas.dart'; |
| 9 import 'package:poppopwin/platform_target.dart'; | 9 import 'package:poppopwin/platform_target.dart'; |
| 10 import 'package:poppopwin/html.dart'; | 10 import 'package:poppopwin/html.dart'; |
| 11 | 11 |
| 12 import 'texture_data.dart'; | 12 import 'texture_data.dart'; |
| 13 | 13 |
| 14 part '_audio.dart'; | 14 part '_audio.dart'; |
| 15 | 15 |
| 16 const String _TRANSPARENT_TEXTURE = 'images/transparent_animated.png'; | 16 const String _ASSET_DIR = 'assets/poppopwin/'; |
| 17 const String _OPAQUE_TEXTURE = 'images/dart_opaque_01.jpg'; | 17 |
| 18 const String _TRANSPARENT_STATIC_TEXTURE = 'images/transparent_static.png'; | 18 const String _TRANSPARENT_TEXTURE = '${_ASSET_DIR}images/transparent_animated.pn
g'; |
| 19 const String _OPAQUE_TEXTURE = '${_ASSET_DIR}images/dart_opaque_01.jpg'; |
| 20 const String _TRANSPARENT_STATIC_TEXTURE = '${_ASSET_DIR}images/transparent_stat
ic.png'; |
| 19 | 21 |
| 20 const int _LOADING_BAR_PX_WIDTH = 398; | 22 const int _LOADING_BAR_PX_WIDTH = 398; |
| 21 | 23 |
| 22 DivElement _loadingBar; | 24 DivElement _loadingBar; |
| 23 ImageLoader _imageLoader; | 25 ImageLoader _imageLoader; |
| 24 | 26 |
| 25 _Audio _audio; | 27 final _Audio _audio = new _Audio(); |
| 26 | 28 |
| 27 void startGame(PlatformTarget platform) { | 29 void startGame(PlatformTarget platform) { |
| 28 initPlatform(platform); | 30 initPlatform(platform); |
| 29 | 31 |
| 30 _loadingBar = querySelector('.sprite.loading_bar'); | 32 _loadingBar = querySelector('.sprite.loading_bar'); |
| 31 _loadingBar.style.display = 'block'; | 33 _loadingBar.style.display = 'block'; |
| 32 _loadingBar.style.width = '0'; | 34 _loadingBar.style.width = '0'; |
| 33 | 35 |
| 34 _imageLoader = new ImageLoader([_TRANSPARENT_TEXTURE, | 36 _imageLoader = new ImageLoader([_TRANSPARENT_TEXTURE, |
| 35 _OPAQUE_TEXTURE]); | 37 _OPAQUE_TEXTURE]); |
| 36 _imageLoader.loaded.listen(_onLoaded); | 38 _imageLoader.loaded.listen(_onLoaded); |
| 37 _imageLoader.progress.listen(_onProgress); | 39 _imageLoader.progress.listen(_onProgress); |
| 38 _imageLoader.load(); | 40 _imageLoader.load(); |
| 39 | |
| 40 _audio = new _Audio(); | |
| 41 } | 41 } |
| 42 | 42 |
| 43 void _onProgress(args) { | 43 void _onProgress(_) { |
| 44 int completedBytes = _imageLoader.completedBytes; | 44 int completedBytes = _imageLoader.completedBytes; |
| 45 int totalBytes = _imageLoader.totalBytes; | 45 int totalBytes = _imageLoader.totalBytes; |
| 46 | 46 |
| 47 completedBytes += _audio.completedBytes; | 47 completedBytes += _audio.completedBytes; |
| 48 totalBytes += _audio.totalBytes; | 48 totalBytes += _audio.totalBytes; |
| 49 | 49 |
| 50 final percent = completedBytes / totalBytes; | 50 var percent = completedBytes / totalBytes; |
| 51 final percentClean = (percent * 1000).floor() / 10; | 51 if (percent == double.INFINITY) percent = 0; |
| 52 var percentClean = (percent * 1000).floor() / 10; |
| 52 | 53 |
| 53 final barWidth = percent * _LOADING_BAR_PX_WIDTH; | 54 var barWidth = percent * _LOADING_BAR_PX_WIDTH; |
| 54 _loadingBar.style.width = '${barWidth.toInt()}px'; | 55 _loadingBar.style.width = '${barWidth.toInt()}px'; |
| 55 } | 56 } |
| 56 | 57 |
| 57 void _onLoaded(args) { | 58 void _onLoaded(_) { |
| 58 if(_imageLoader.state == ResourceLoader.StateLoaded && _audio.done) { | 59 if(_imageLoader.state == ResourceLoader.StateLoaded && _audio.done) { |
| 59 | 60 |
| 60 // | 61 // |
| 61 // load textures | 62 // load textures |
| 62 // | 63 // |
| 63 final opaqueImage = _imageLoader.getResource(_OPAQUE_TEXTURE); | 64 final opaqueImage = _imageLoader.getResource(_OPAQUE_TEXTURE); |
| 64 final transparentImage = _imageLoader.getResource(_TRANSPARENT_TEXTURE); | 65 final transparentImage = _imageLoader.getResource(_TRANSPARENT_TEXTURE); |
| 65 | 66 |
| 66 // already loaded. Used in CSS. | 67 // already loaded. Used in CSS. |
| 67 final staticTransparentImage = new ImageElement(src: _TRANSPARENT_STATIC_TEX
TURE); | 68 final staticTransparentImage = new ImageElement(src: _TRANSPARENT_STATIC_TEX
TURE); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 case 72: // h | 114 case 72: // h |
| 114 targetPlatform.toggleAbout(); | 115 targetPlatform.toggleAbout(); |
| 115 break; | 116 break; |
| 116 } | 117 } |
| 117 } | 118 } |
| 118 | 119 |
| 119 void _updateAbout() { | 120 void _updateAbout() { |
| 120 var popDisplay = targetPlatform.showAbout ? 'inline-block' : 'none'; | 121 var popDisplay = targetPlatform.showAbout ? 'inline-block' : 'none'; |
| 121 querySelector('#popup').style.display = popDisplay; | 122 querySelector('#popup').style.display = popDisplay; |
| 122 } | 123 } |
| OLD | NEW |