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

Side by Side Diff: sky/sdk/example/game/lib/game_demo_world.dart

Issue 1233673003: Fix bugs found by Dart analyzer (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: typo Created 5 years, 5 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 unified diff | Download patch
OLDNEW
1 part of game; 1 part of game;
2 2
3 const double _steeringThreshold = 0.0; 3 const double _steeringThreshold = 0.0;
4 const double _steeringMax = 150.0; 4 const double _steeringMax = 150.0;
5 5
6 // Random generator 6 // Random generator
7 Math.Random _rand = new Math.Random(); 7 Math.Random _rand = new Math.Random();
8 8
9 const double _gameSizeWidth = 1024.0; 9 const double _gameSizeWidth = 1024.0;
10 const double _gameSizeHeight = 1024.0; 10 const double _gameSizeHeight = 1024.0;
11 11
12 const double _shipRadius = 30.0; 12 const double _shipRadius = 30.0;
13 const double _lrgAsteroidRadius = 40.0; 13 const double _lrgAsteroidRadius = 40.0;
14 const double _medAsteroidRadius = 20.0; 14 const double _medAsteroidRadius = 20.0;
15 const double _smlAsteroidRadius = 10.0; 15 const double _smlAsteroidRadius = 10.0;
16 const double _maxAsteroidSpeed = 1.0; 16 const double _maxAsteroidSpeed = 1.0;
17 17
18 const int _lifeTimeLaser = 50; 18 const int _lifeTimeLaser = 50;
19 19
20 const int _numStarsInStarField = 150; 20 const int _numStarsInStarField = 150;
21 21
22 const int _numFramesShieldActive = 60 * 5; 22 const int _numFramesShieldActive = 60 * 5;
23 const int _numFramesShieldFlickers = 60; 23 const int _numFramesShieldFlickers = 60;
24 24
25 class GameDemoWorld extends NodeWithSize { 25 class GameDemoWorld extends NodeWithSize {
26 App _app;
27
28 // Images 26 // Images
29 Image _imgNebula; 27 Image _imgNebula;
30 28
31 SpriteSheet _spriteSheet; 29 SpriteSheet _spriteSheet;
32 30
33 // Inputs 31 // Inputs
34 double _joystickX = 0.0; 32 double _joystickX = 0.0;
35 double _joystickY = 0.0; 33 double _joystickY = 0.0;
36 bool _fire;
37 34
38 Node _gameLayer; 35 Node _gameLayer;
39 36
40 Ship _ship; 37 Ship _ship;
41 Sprite _shield; 38 Sprite _shield;
42 List<Asteroid> _asteroids = []; 39 List<Asteroid> _asteroids = [];
43 List<Laser> _lasers = []; 40 List<Laser> _lasers = [];
44 StarField _starField; 41 StarField _starField;
45 Nebula _nebula; 42 Nebula _nebula;
46 43
47 // Game state 44 // Game state
48 int _numFrames = 0; 45 int _numFrames = 0;
49 bool _isGameOver = false; 46 bool _isGameOver = false;
50 47
51 GameDemoWorld(this._app, ImageMap images, this._spriteSheet) : super(new Size( _gameSizeWidth, _gameSizeHeight)) { 48 GameDemoWorld(App app, ImageMap images, this._spriteSheet) : super(new Size(_g ameSizeWidth, _gameSizeHeight)) {
52 49
53 // Fetch images 50 // Fetch images
54 _imgNebula = images["assets/nebula.png"]; 51 _imgNebula = images["assets/nebula.png"];
55 52
56 _gameLayer = new Node(); 53 _gameLayer = new Node();
57 this.addChild(_gameLayer); 54 this.addChild(_gameLayer);
58 55
59 // Add some asteroids to the game world 56 // Add some asteroids to the game world
60 for (int i = 0; i < 5; i++) { 57 for (int i = 0; i < 5; i++) {
61 addAsteroid(AsteroidSize.large); 58 addAsteroid(AsteroidSize.large);
(...skipping 561 matching lines...) Expand 10 before | Expand all | Expand 10 after
623 double dy = a.y - b.y; 620 double dy = a.y - b.y;
624 if (dx < 0.0) dx = -dx; 621 if (dx < 0.0) dx = -dx;
625 if (dy < 0.0) dy = -dy; 622 if (dy < 0.0) dy = -dy;
626 if (dx > dy) { 623 if (dx > dy) {
627 return dx + dy/2.0; 624 return dx + dy/2.0;
628 } 625 }
629 else { 626 else {
630 return dy + dx/2.0; 627 return dy + dx/2.0;
631 } 628 }
632 } 629 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698