| 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; |
| 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 // Images | 26 // Images |
| 27 Image _imgNebula; | 27 sky.Image _imgNebula; |
| 28 | 28 |
| 29 SpriteSheet _spriteSheet; | 29 SpriteSheet _spriteSheet; |
| 30 | 30 |
| 31 // Inputs | 31 // Inputs |
| 32 double _joystickX = 0.0; | 32 double _joystickX = 0.0; |
| 33 double _joystickY = 0.0; | 33 double _joystickY = 0.0; |
| 34 | 34 |
| 35 Node _gameLayer; | 35 Node _gameLayer; |
| 36 | 36 |
| 37 Ship _ship; | 37 Ship _ship; |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 | 94 |
| 95 void addShip() { | 95 void addShip() { |
| 96 Ship ship = new Ship(_spriteSheet["ship.png"]); | 96 Ship ship = new Ship(_spriteSheet["ship.png"]); |
| 97 ship.zPosition = 10.0; | 97 ship.zPosition = 10.0; |
| 98 _gameLayer.addChild(ship); | 98 _gameLayer.addChild(ship); |
| 99 _ship = ship; | 99 _ship = ship; |
| 100 | 100 |
| 101 _shield = new Sprite(_spriteSheet["shield.png"]); | 101 _shield = new Sprite(_spriteSheet["shield.png"]); |
| 102 _shield.zPosition = 11.0; | 102 _shield.zPosition = 11.0; |
| 103 _shield.scale = 0.5; | 103 _shield.scale = 0.5; |
| 104 _shield.transferMode = TransferMode.plus; | 104 _shield.transferMode = sky.TransferMode.plus; |
| 105 _gameLayer.addChild(_shield); | 105 _gameLayer.addChild(_shield); |
| 106 | 106 |
| 107 Action rotate = new ActionRepeatForever(new ActionTween((a) => _shield.rotat
ion = a, 0.0, 360.0, 1.0)); | 107 Action rotate = new ActionRepeatForever(new ActionTween((a) => _shield.rotat
ion = a, 0.0, 360.0, 1.0)); |
| 108 actions.run(rotate); | 108 actions.run(rotate); |
| 109 } | 109 } |
| 110 | 110 |
| 111 void addLaser() { | 111 void addLaser() { |
| 112 Laser laser = new Laser(_spriteSheet["laser.png"], _ship); | 112 Laser laser = new Laser(_spriteSheet["laser.png"], _ship); |
| 113 laser.zPosition = 8.0; | 113 laser.zPosition = 8.0; |
| 114 laser.constrainProportions = true; | 114 laser.constrainProportions = true; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 posVar: new Point(10.0, 10.0), | 155 posVar: new Point(10.0, 10.0), |
| 156 speed: 10.0, | 156 speed: 10.0, |
| 157 speedVar: 5.0 | 157 speedVar: 5.0 |
| 158 ); | 158 ); |
| 159 particlesFire.zPosition = 1011.0; | 159 particlesFire.zPosition = 1011.0; |
| 160 explosionNode.addChild(particlesFire); | 160 explosionNode.addChild(particlesFire); |
| 161 | 161 |
| 162 | 162 |
| 163 // Add ring | 163 // Add ring |
| 164 Sprite sprtRing = new Sprite(_spriteSheet["explosion_ring.png"]); | 164 Sprite sprtRing = new Sprite(_spriteSheet["explosion_ring.png"]); |
| 165 sprtRing.transferMode = TransferMode.plus; | 165 sprtRing.transferMode = sky.TransferMode.plus; |
| 166 explosionNode.addChild(sprtRing); | 166 explosionNode.addChild(sprtRing); |
| 167 | 167 |
| 168 Action scale = new ActionTween( (a) => sprtRing.scale = a, 0.2, 1.0, 1.5); | 168 Action scale = new ActionTween( (a) => sprtRing.scale = a, 0.2, 1.0, 1.5); |
| 169 Action scaleAndRemove = new ActionSequence([scale, new ActionRemoveNode(sprt
Ring)]); | 169 Action scaleAndRemove = new ActionSequence([scale, new ActionRemoveNode(sprt
Ring)]); |
| 170 Action fade = new ActionTween( (a) => sprtRing.opacity = a, 1.0, 0.0, 1.5); | 170 Action fade = new ActionTween( (a) => sprtRing.opacity = a, 1.0, 0.0, 1.5); |
| 171 actions.run(scaleAndRemove); | 171 actions.run(scaleAndRemove); |
| 172 actions.run(fade); | 172 actions.run(fade); |
| 173 | 173 |
| 174 // Add streaks | 174 // Add streaks |
| 175 for (int i = 0; i < 5; i++) { | 175 for (int i = 0; i < 5; i++) { |
| 176 Sprite sprtFlare = new Sprite(_spriteSheet["explosion_flare.png"]); | 176 Sprite sprtFlare = new Sprite(_spriteSheet["explosion_flare.png"]); |
| 177 sprtFlare.pivot = new Point(0.3, 1.0); | 177 sprtFlare.pivot = new Point(0.3, 1.0); |
| 178 sprtFlare.scaleX = 0.3; | 178 sprtFlare.scaleX = 0.3; |
| 179 sprtFlare.transferMode = TransferMode.plus; | 179 sprtFlare.transferMode = sky.TransferMode.plus; |
| 180 sprtFlare.rotation = _rand.nextDouble() * 360.0; | 180 sprtFlare.rotation = _rand.nextDouble() * 360.0; |
| 181 explosionNode.addChild(sprtFlare); | 181 explosionNode.addChild(sprtFlare); |
| 182 | 182 |
| 183 double multiplier = _rand.nextDouble() * 0.3 + 1.0; | 183 double multiplier = _rand.nextDouble() * 0.3 + 1.0; |
| 184 | 184 |
| 185 Action scale = new ActionTween( (a) => sprtFlare.scaleY = a, 0.3 * multipl
ier, 0.8, 1.5 * multiplier); | 185 Action scale = new ActionTween( (a) => sprtFlare.scaleY = a, 0.3 * multipl
ier, 0.8, 1.5 * multiplier); |
| 186 Action scaleAndRemove = new ActionSequence([scale, new ActionRemoveNode(sp
rtFlare)]); | 186 Action scaleAndRemove = new ActionSequence([scale, new ActionRemoveNode(sp
rtFlare)]); |
| 187 Action fadeIn = new ActionTween( (a) => sprtFlare.opacity = a, 0.0, 1.0, 0
.5 * multiplier); | 187 Action fadeIn = new ActionTween( (a) => sprtFlare.opacity = a, 0.0, 1.0, 0
.5 * multiplier); |
| 188 Action fadeOut = new ActionTween( (a) => sprtFlare.opacity = a, 1.0, 0.0,
1.0 * multiplier); | 188 Action fadeOut = new ActionTween( (a) => sprtFlare.opacity = a, 1.0, 0.0,
1.0 * multiplier); |
| 189 Action fadeInOut = new ActionSequence([fadeIn, fadeOut]); | 189 Action fadeInOut = new ActionSequence([fadeIn, fadeOut]); |
| (...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 496 | 496 |
| 497 class Laser extends Sprite { | 497 class Laser extends Sprite { |
| 498 int _frameCount = 0; | 498 int _frameCount = 0; |
| 499 Point _movementVector; | 499 Point _movementVector; |
| 500 double radius = 20.0; | 500 double radius = 20.0; |
| 501 | 501 |
| 502 Laser(Texture img, Ship ship) : super(img) { | 502 Laser(Texture img, Ship ship) : super(img) { |
| 503 size = new Size(30.0, 30.0); | 503 size = new Size(30.0, 30.0); |
| 504 position = ship.position; | 504 position = ship.position; |
| 505 rotation = ship.rotation + 90.0; | 505 rotation = ship.rotation + 90.0; |
| 506 transferMode = TransferMode.plus; | 506 transferMode = sky.TransferMode.plus; |
| 507 double rotRadians = convertDegrees2Radians(rotation); | 507 double rotRadians = convertDegrees2Radians(rotation); |
| 508 _movementVector = pointMult(new Point(Math.sin(rotRadians), -Math.cos(rotRad
ians)), 10.0); | 508 _movementVector = pointMult(new Point(Math.sin(rotRadians), -Math.cos(rotRad
ians)), 10.0); |
| 509 _movementVector = new Point(_movementVector.x + ship._movementVector[0], _mo
vementVector.y + ship._movementVector[1]); | 509 _movementVector = new Point(_movementVector.x + ship._movementVector[0], _mo
vementVector.y + ship._movementVector[1]); |
| 510 } | 510 } |
| 511 | 511 |
| 512 void move() { | 512 void move() { |
| 513 position = pointAdd(position, _movementVector); | 513 position = pointAdd(position, _movementVector); |
| 514 _frameCount++; | 514 _frameCount++; |
| 515 } | 515 } |
| 516 } | 516 } |
| (...skipping 17 matching lines...) Expand all Loading... |
| 534 _starPositions.add(new Point(_rand.nextDouble() * _gameSizeWidth, _rand.ne
xtDouble() * _gameSizeHeight)); | 534 _starPositions.add(new Point(_rand.nextDouble() * _gameSizeWidth, _rand.ne
xtDouble() * _gameSizeHeight)); |
| 535 _starScales.add(_rand.nextDouble()); | 535 _starScales.add(_rand.nextDouble()); |
| 536 _opacity.add(_rand.nextDouble() * 0.5 + 0.5); | 536 _opacity.add(_rand.nextDouble() * 0.5 + 0.5); |
| 537 _textures.add(spriteSheet["star_${_rand.nextInt(2)}.png"]); | 537 _textures.add(spriteSheet["star_${_rand.nextInt(2)}.png"]); |
| 538 } | 538 } |
| 539 } | 539 } |
| 540 | 540 |
| 541 void paint(PaintingCanvas canvas) { | 541 void paint(PaintingCanvas canvas) { |
| 542 // Setup paint object for opacity and transfer mode | 542 // Setup paint object for opacity and transfer mode |
| 543 Paint paint = new Paint(); | 543 Paint paint = new Paint(); |
| 544 paint.setTransferMode(TransferMode.plus); | 544 paint.setTransferMode(sky.TransferMode.plus); |
| 545 | 545 |
| 546 double baseScaleX = 64.0 / _textures[0].size.width; | 546 double baseScaleX = 64.0 / _textures[0].size.width; |
| 547 double baseScaleY = 64.0 / _textures[0].size.height; | 547 double baseScaleY = 64.0 / _textures[0].size.height; |
| 548 | 548 |
| 549 // Draw each star | 549 // Draw each star |
| 550 for (int i = 0; i < _numStars; i++) { | 550 for (int i = 0; i < _numStars; i++) { |
| 551 Point pos = _starPositions[i]; | 551 Point pos = _starPositions[i]; |
| 552 double scale = _starScales[i]; | 552 double scale = _starScales[i]; |
| 553 paint.color = new Color.fromARGB((255.0*_opacity[i]).toInt(), 255, 255, 25
5); | 553 paint.color = new Color.fromARGB((255.0*_opacity[i]).toInt(), 255, 255, 25
5); |
| 554 | 554 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 577 if (yPos >= _gameSizeHeight) yPos -= _gameSizeHeight; | 577 if (yPos >= _gameSizeHeight) yPos -= _gameSizeHeight; |
| 578 if (yPos < 0) yPos += _gameSizeHeight; | 578 if (yPos < 0) yPos += _gameSizeHeight; |
| 579 | 579 |
| 580 _starPositions[i] = new Point(xPos, yPos); | 580 _starPositions[i] = new Point(xPos, yPos); |
| 581 } | 581 } |
| 582 } | 582 } |
| 583 } | 583 } |
| 584 | 584 |
| 585 class Nebula extends Node { | 585 class Nebula extends Node { |
| 586 | 586 |
| 587 Nebula.withImage(Image img) { | 587 Nebula.withImage(sky.Image img) { |
| 588 for (int i = 0; i < 2; i++) { | 588 for (int i = 0; i < 2; i++) { |
| 589 for (int j = 0; j < 2; j++) { | 589 for (int j = 0; j < 2; j++) { |
| 590 Sprite sprt = new Sprite.fromImage(img); | 590 Sprite sprt = new Sprite.fromImage(img); |
| 591 sprt.pivot = Point.origin; | 591 sprt.pivot = Point.origin; |
| 592 sprt.position = new Point(i * _gameSizeWidth - _gameSizeWidth, j * _game
SizeHeight - _gameSizeHeight); | 592 sprt.position = new Point(i * _gameSizeWidth - _gameSizeWidth, j * _game
SizeHeight - _gameSizeHeight); |
| 593 addChild(sprt); | 593 addChild(sprt); |
| 594 } | 594 } |
| 595 } | 595 } |
| 596 } | 596 } |
| 597 } | 597 } |
| (...skipping 22 matching lines...) Expand all Loading... |
| 620 double dy = a.y - b.y; | 620 double dy = a.y - b.y; |
| 621 if (dx < 0.0) dx = -dx; | 621 if (dx < 0.0) dx = -dx; |
| 622 if (dy < 0.0) dy = -dy; | 622 if (dy < 0.0) dy = -dy; |
| 623 if (dx > dy) { | 623 if (dx > dy) { |
| 624 return dx + dy/2.0; | 624 return dx + dy/2.0; |
| 625 } | 625 } |
| 626 else { | 626 else { |
| 627 return dy + dx/2.0; | 627 return dy + dx/2.0; |
| 628 } | 628 } |
| 629 } | 629 } |
| OLD | NEW |