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

Side by Side Diff: samples/pop_pop_win/lib/pop_pop_win.dart

Issue 786443002: Delete pop-pop-win from the repo (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « samples/pop_pop_win/lib/platform_target.dart ('k') | samples/pop_pop_win/lib/src/audio.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4 library pop_pop_win;
5
6 import 'dart:async';
7 import 'dart:html';
8
9 import 'package:pop_pop_win/platform_target.dart';
10 import 'package:stagexl/stagexl.dart';
11
12 import 'src/audio.dart';
13 import 'src/platform.dart';
14 import 'src/stage.dart';
15
16 const String _ASSET_DIR = 'packages/pop_pop_win/assets';
17
18 Future startGame(PlatformTarget platform) {
19 initPlatform(platform);
20
21 var stage = new Stage(querySelector('#gameCanvas'), webGL: true,
22 color: 0xb4ad7f, frameRate: 60);
23
24 var renderLoop = new RenderLoop()
25 ..addStage(stage);
26
27 BitmapData.defaultLoadOptions.webp = true;
28
29 //have to load the loading bar first...
30 var resourceManager = new ResourceManager()
31 ..addTextureAtlas("static", '$_ASSET_DIR/images/static.json',
32 TextureAtlasFormat.JSON);
33
34 return resourceManager.load()
35 .then((resMan) => _initialLoad(resMan, stage));
36 }
37
38 void _initialLoad(ResourceManager resourceManager, Stage stage) {
39 var atlas = resourceManager.getTextureAtlas('static');
40
41 var bar = new Gauge(atlas.getBitmapData('loading_bar'), Gauge.DIRECTION_RIGHT)
42 ..x = 51
43 ..y = 8
44 ..ratio = 0;
45
46 var loadingText = new Bitmap(atlas.getBitmapData('loading_text'))
47 ..x = 141
48 ..y = 10;
49
50 var loadingSprite = new Sprite()
51 ..addChild(new Bitmap(atlas.getBitmapData('loading_background')))
52 ..addChild(bar)
53 ..addChild(loadingText)
54 ..x = stage.sourceWidth ~/ 2 - 1008 ~/ 2
55 ..y = 400
56 ..scaleX = 2
57 ..scaleY = 2
58 ..addTo(stage);
59
60 resourceManager
61 ..addTextureAtlas('opaque', '$_ASSET_DIR/images/opaque.json',
62 TextureAtlasFormat.JSON)
63 ..addTextureAtlas('animated', '$_ASSET_DIR/images/animated.json',
64 TextureAtlasFormat.JSON);
65
66 resourceManager.addSoundSprite('audio', '$_ASSET_DIR/audio/audio.json');
67
68 resourceManager.onProgress.listen((e) {
69 bar.ratio = resourceManager.finishedResources.length /
70 resourceManager.resources.length;
71 });
72
73 resourceManager.load().then((resMan) =>
74 _secondaryLoad(resMan, stage, loadingSprite));
75 }
76
77 void _secondaryLoad(ResourceManager resourceManager, Stage stage,
78 Sprite loadingSprite) {
79 var tween = stage.juggler.tween(loadingSprite, .5)
80 ..animate.alpha.to(0)
81 ..onComplete = () => stage.removeChild(loadingSprite);
82
83 _updateAbout();
84
85 targetPlatform.aboutChanged.listen((_) => _updateAbout());
86
87 var size = targetPlatform.size;
88 var m = (size * size * 0.15625).toInt();
89
90 GameAudio.initialize(resourceManager);
91 var gameRoot = new GameRoot(size, size, m, stage, resourceManager);
92
93 // disable touch events
94 window.onTouchMove.listen((args) => args.preventDefault());
95
96 window.onKeyDown.listen(_onKeyDown);
97
98 querySelector('#popup').onClick.listen(_onPopupClick);
99
100 titleClickedEvent.listen((args) => targetPlatform.toggleAbout(true));
101 }
102
103 void _onPopupClick(args) {
104 if (args.toElement is! AnchorElement) {
105 targetPlatform.toggleAbout(false);
106 }
107 }
108
109 void _onKeyDown(args) {
110 var keyEvent = new KeyEvent.wrap(args);
111 switch (keyEvent.keyCode) {
112 case KeyCode.ESC: // esc
113 targetPlatform.toggleAbout(false);
114 break;
115 case KeyCode.H: // h
116 targetPlatform.toggleAbout();
117 break;
118 }
119 }
120
121 void _updateAbout() {
122 var popDisplay = targetPlatform.showAbout ? 'inline-block' : 'none';
123 querySelector('#popup').style.display = popDisplay;
124 }
OLDNEW
« no previous file with comments | « samples/pop_pop_win/lib/platform_target.dart ('k') | samples/pop_pop_win/lib/src/audio.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698