| 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 _transparentTextureName = 'images/transparent_animated.png'; | 16 const String _transparentTextureName = 'images/transparent_animated.png'; |
| 17 const String _opaqueTextureName = 'images/dart_opaque_01.jpg'; | 17 const String _opaqueTextureName = 'images/dart_opaque_01.jpg'; |
| 18 const String _transparentStaticTexture = 'images/transparent_static.png'; | 18 const String _transparentStaticTexture = 'images/transparent_static.png'; |
| 19 | 19 |
| 20 const int _loadingBarPxWidth = 398; | 20 const int _loadingBarPxWidth = 398; |
| 21 | 21 |
| 22 DivElement _loadingBar; | 22 DivElement _loadingBar; |
| 23 ImageLoader _imageLoader; | 23 ImageLoader _imageLoader; |
| 24 | 24 |
| 25 _Audio _audio; | 25 _Audio _audio; |
| 26 | 26 |
| 27 void startGame(PlatformTarget platform) { | 27 void startGame(PlatformTarget platform) { |
| 28 initPlatform(platform); | 28 initPlatform(platform); |
| 29 | 29 |
| 30 _loadingBar = query('.sprite.loading_bar'); | 30 _loadingBar = querySelector('.sprite.loading_bar'); |
| 31 _loadingBar.style.display = 'block'; | 31 _loadingBar.style.display = 'block'; |
| 32 _loadingBar.style.width = '0'; | 32 _loadingBar.style.width = '0'; |
| 33 | 33 |
| 34 _imageLoader = new ImageLoader([_transparentTextureName, | 34 _imageLoader = new ImageLoader([_transparentTextureName, |
| 35 _opaqueTextureName]); | 35 _opaqueTextureName]); |
| 36 _imageLoader.loaded.listen(_onLoaded); | 36 _imageLoader.loaded.listen(_onLoaded); |
| 37 _imageLoader.progress.listen(_onProgress); | 37 _imageLoader.progress.listen(_onProgress); |
| 38 _imageLoader.load(); | 38 _imageLoader.load(); |
| 39 | 39 |
| 40 _audio = new _Audio(); | 40 _audio = new _Audio(); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 64 final transparentImage = _imageLoader.getResource(_transparentTextureName); | 64 final transparentImage = _imageLoader.getResource(_transparentTextureName); |
| 65 | 65 |
| 66 // already loaded. Used in CSS. | 66 // already loaded. Used in CSS. |
| 67 final staticTransparentImage = new ImageElement(src: _transparentStaticTextu
re); | 67 final staticTransparentImage = new ImageElement(src: _transparentStaticTextu
re); |
| 68 | 68 |
| 69 final textures = getTextures(transparentImage, opaqueImage, staticTransparen
tImage); | 69 final textures = getTextures(transparentImage, opaqueImage, staticTransparen
tImage); |
| 70 | 70 |
| 71 final textureData = new TextureData(textures); | 71 final textureData = new TextureData(textures); |
| 72 | 72 |
| 73 // run the app | 73 // run the app |
| 74 query('#loading').style.display = 'none'; | 74 querySelector('#loading').style.display = 'none'; |
| 75 _runPPW(textureData); | 75 _runPPW(textureData); |
| 76 } | 76 } |
| 77 } | 77 } |
| 78 | 78 |
| 79 void _runPPW(TextureData textureData) { | 79 void _runPPW(TextureData textureData) { |
| 80 final size = _processUrlHash(false) ? 16 : 7; | 80 final size = _processUrlHash(false) ? 16 : 7; |
| 81 final int m = (size * size * 0.15625).toInt(); | 81 final int m = (size * size * 0.15625).toInt(); |
| 82 | 82 |
| 83 final CanvasElement gameCanvas = query('#gameCanvas'); | 83 final CanvasElement gameCanvas = querySelector('#gameCanvas'); |
| 84 gameCanvas.style.userSelect = 'none'; | 84 gameCanvas.style.userSelect = 'none'; |
| 85 | 85 |
| 86 final gameRoot = new GameRoot(size, size, m, gameCanvas, textureData); | 86 final gameRoot = new GameRoot(size, size, m, gameCanvas, textureData); |
| 87 | 87 |
| 88 // disable touch events | 88 // disable touch events |
| 89 window.onTouchMove.listen((args) => args.preventDefault()); | 89 window.onTouchMove.listen((args) => args.preventDefault()); |
| 90 window.onPopState.listen((args) => _processUrlHash(true)); | 90 window.onPopState.listen((args) => _processUrlHash(true)); |
| 91 | 91 |
| 92 window.onKeyDown.listen(_onKeyDown); | 92 window.onKeyDown.listen(_onKeyDown); |
| 93 | 93 |
| 94 query('#popup').onClick.listen(_onPopupClick); | 94 querySelector('#popup').onClick.listen(_onPopupClick); |
| 95 | 95 |
| 96 titleClickedEvent.listen((args) => _toggleAbout(true)); | 96 titleClickedEvent.listen((args) => _toggleAbout(true)); |
| 97 } | 97 } |
| 98 | 98 |
| 99 void _onPopupClick(MouseEvent args) { | 99 void _onPopupClick(MouseEvent args) { |
| 100 if(!(args.toElement is AnchorElement)) { | 100 if(!(args.toElement is AnchorElement)) { |
| 101 _toggleAbout(false); | 101 _toggleAbout(false); |
| 102 } | 102 } |
| 103 } | 103 } |
| 104 | 104 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 case '#big': | 149 case '#big': |
| 150 if(forceReload) { | 150 if(forceReload) { |
| 151 loc.reload(); | 151 loc.reload(); |
| 152 } | 152 } |
| 153 return true; | 153 return true; |
| 154 case '#about': | 154 case '#about': |
| 155 showAbout = true; | 155 showAbout = true; |
| 156 break; | 156 break; |
| 157 } | 157 } |
| 158 | 158 |
| 159 query('#popup').style.display = showAbout ? 'inline-block' : 'none'; | 159 querySelector('#popup').style.display = showAbout ? 'inline-block' : 'none'; |
| 160 | 160 |
| 161 return false; | 161 return false; |
| 162 } | 162 } |
| OLD | NEW |