| OLD | NEW |
| 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; |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 Ship _ship; | 40 Ship _ship; |
| 41 Sprite _shield; | 41 Sprite _shield; |
| 42 List<Asteroid> _asteroids = []; | 42 List<Asteroid> _asteroids = []; |
| 43 List<Laser> _lasers = []; | 43 List<Laser> _lasers = []; |
| 44 StarField _starField; | 44 StarField _starField; |
| 45 Nebula _nebula; | 45 Nebula _nebula; |
| 46 | 46 |
| 47 // Game state | 47 // Game state |
| 48 int _numFrames = 0; | 48 int _numFrames = 0; |
| 49 bool _isGameOver = false; | 49 bool _isGameOver = false; |
| 50 | 50 |
| 51 GameDemoWorld(this._app, ImageMap images, this._spriteSheet) : super(new Size(
_gameSizeWidth, _gameSizeHeight)) { | 51 GameDemoWorld(this._app, ImageMap images, this._spriteSheet) : super(new Size(
_gameSizeWidth, _gameSizeHeight)) { |
| 52 | 52 |
| 53 // Fetch images | 53 // Fetch images |
| 54 _imgNebula = images["res/nebula.png"]; | 54 _imgNebula = images["assets/nebula.png"]; |
| 55 | 55 |
| 56 _gameLayer = new Node(); | 56 _gameLayer = new Node(); |
| 57 this.addChild(_gameLayer); | 57 this.addChild(_gameLayer); |
| 58 | 58 |
| 59 // Add some asteroids to the game world | 59 // Add some asteroids to the game world |
| 60 for (int i = 0; i < 5; i++) { | 60 for (int i = 0; i < 5; i++) { |
| 61 addAsteroid(AsteroidSize.large); | 61 addAsteroid(AsteroidSize.large); |
| 62 } | 62 } |
| 63 for (int i = 0; i < 5; i++) { | 63 for (int i = 0; i < 5; i++) { |
| 64 addAsteroid(AsteroidSize.medium); | 64 addAsteroid(AsteroidSize.medium); |
| 65 } | 65 } |
| 66 | 66 |
| 67 // Add ship | 67 // Add ship |
| 68 addShip(); | 68 addShip(); |
| 69 | 69 |
| 70 // Add background | 70 // Add background |
| 71 Sprite sprtBackground = new Sprite.fromImage(images["res/starfield.png"]); | 71 Sprite sprtBackground = new Sprite.fromImage(images["assets/starfield.png"])
; |
| 72 sprtBackground.position = new Point(512.0, 512.0); | 72 sprtBackground.position = new Point(512.0, 512.0); |
| 73 sprtBackground.zPosition = -3.0; | 73 sprtBackground.zPosition = -3.0; |
| 74 addChild(sprtBackground); | 74 addChild(sprtBackground); |
| 75 | 75 |
| 76 // Add starfield | 76 // Add starfield |
| 77 _starField = new StarField(_spriteSheet, _numStarsInStarField); | 77 _starField = new StarField(_spriteSheet, _numStarsInStarField); |
| 78 _starField.zPosition = -2.0; | 78 _starField.zPosition = -2.0; |
| 79 addChild(_starField); | 79 addChild(_starField); |
| 80 | 80 |
| 81 // Add nebula | 81 // Add nebula |
| 82 addNebula(); | 82 addNebula(); |
| 83 | 83 |
| 84 userInteractionEnabled = true; | 84 userInteractionEnabled = true; |
| 85 handleMultiplePointers = true; | 85 handleMultiplePointers = true; |
| 86 } | 86 } |
| 87 | 87 |
| 88 // Methods for adding game objects | 88 // Methods for adding game objects |
| 89 | 89 |
| 90 void addAsteroid(AsteroidSize size, [Point pos]) { | 90 void addAsteroid(AsteroidSize size, [Point pos]) { |
| 91 Asteroid asteroid = new Asteroid(_spriteSheet, size); | 91 Asteroid asteroid = new Asteroid(_spriteSheet, size); |
| 92 asteroid.zPosition = 1.0; | 92 asteroid.zPosition = 1.0; |
| 93 if (pos != null) asteroid.position = pos; | 93 if (pos != null) asteroid.position = pos; |
| 94 _gameLayer.addChild(asteroid); | 94 _gameLayer.addChild(asteroid); |
| 95 _asteroids.add(asteroid); | 95 _asteroids.add(asteroid); |
| 96 } | 96 } |
| 97 | 97 |
| 98 void addShip() { | 98 void addShip() { |
| 99 Ship ship = new Ship(_spriteSheet["ship.png"]); | 99 Ship ship = new Ship(_spriteSheet["ship.png"]); |
| (...skipping 523 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 623 double dy = a.y - b.y; | 623 double dy = a.y - b.y; |
| 624 if (dx < 0.0) dx = -dx; | 624 if (dx < 0.0) dx = -dx; |
| 625 if (dy < 0.0) dy = -dy; | 625 if (dy < 0.0) dy = -dy; |
| 626 if (dx > dy) { | 626 if (dx > dy) { |
| 627 return dx + dy/2.0; | 627 return dx + dy/2.0; |
| 628 } | 628 } |
| 629 else { | 629 else { |
| 630 return dy + dx/2.0; | 630 return dy + dx/2.0; |
| 631 } | 631 } |
| 632 } | 632 } |
| OLD | NEW |