OLD | NEW |
1 part of game; | 1 part of game; |
2 | 2 |
3 // Random generator | 3 // Random generator |
4 Math.Random _rand = new Math.Random(); | 4 Math.Random _rand = new Math.Random(); |
5 | 5 |
6 const double _gameSizeWidth = 1024.0; | 6 const double _gameSizeWidth = 1024.0; |
7 const double _gameSizeHeight = 1024.0; | 7 const double _gameSizeHeight = 1024.0; |
8 | 8 |
9 const double _shipRadius = 30.0; | 9 const double _shipRadius = 30.0; |
10 const double _lrgAsteroidRadius = 40.0; | 10 const double _lrgAsteroidRadius = 40.0; |
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
262 | 262 |
263 class Laser extends Sprite { | 263 class Laser extends Sprite { |
264 int _frameCount = 0; | 264 int _frameCount = 0; |
265 Point _movementVector; | 265 Point _movementVector; |
266 double radius = 10.0; | 266 double radius = 10.0; |
267 | 267 |
268 Laser.withImage(Image img, Ship ship) : super.withImage(img) { | 268 Laser.withImage(Image img, Ship ship) : super.withImage(img) { |
269 size = new Size(20.0, 20.0); | 269 size = new Size(20.0, 20.0); |
270 position = ship.position; | 270 position = ship.position; |
271 rotation = ship.rotation + 90.0; | 271 rotation = ship.rotation + 90.0; |
272 transferMode = TransferMode.plusMode; | 272 transferMode = TransferMode.plus; |
273 double rotRadians = convertDegrees2Radians(rotation); | 273 double rotRadians = convertDegrees2Radians(rotation); |
274 _movementVector = pointMult(new Point(Math.sin(rotRadians), -Math.cos(rotRad
ians)), 10.0); | 274 _movementVector = pointMult(new Point(Math.sin(rotRadians), -Math.cos(rotRad
ians)), 10.0); |
275 _movementVector = new Point(_movementVector.x + ship._movementVector[0], _mo
vementVector.y + ship._movementVector[1]); | 275 _movementVector = new Point(_movementVector.x + ship._movementVector[0], _mo
vementVector.y + ship._movementVector[1]); |
276 } | 276 } |
277 | 277 |
278 bool move() { | 278 bool move() { |
279 position = pointAdd(position, _movementVector); | 279 position = pointAdd(position, _movementVector); |
280 _frameCount++; | 280 _frameCount++; |
281 } | 281 } |
282 } | 282 } |
(...skipping 15 matching lines...) Expand all Loading... |
298 for (int i = 0; i < _numStars; i++) { | 298 for (int i = 0; i < _numStars; i++) { |
299 _starPositions.add(new Point(_rand.nextDouble() * _gameSizeWidth, _rand.ne
xtDouble() * _gameSizeHeight)); | 299 _starPositions.add(new Point(_rand.nextDouble() * _gameSizeWidth, _rand.ne
xtDouble() * _gameSizeHeight)); |
300 _starScales.add(_rand.nextDouble()); | 300 _starScales.add(_rand.nextDouble()); |
301 _opacity.add(_rand.nextDouble() * 0.5 + 0.5); | 301 _opacity.add(_rand.nextDouble() * 0.5 + 0.5); |
302 } | 302 } |
303 } | 303 } |
304 | 304 |
305 void paint(PictureRecorder canvas) { | 305 void paint(PictureRecorder canvas) { |
306 // Setup paint object for opacity and transfer mode | 306 // Setup paint object for opacity and transfer mode |
307 Paint paint = new Paint(); | 307 Paint paint = new Paint(); |
308 paint.setTransferMode(TransferMode.plusMode); | 308 paint.setTransferMode(TransferMode.plus); |
309 | 309 |
310 double baseScaleX = 32.0/_img.width; | 310 double baseScaleX = 32.0/_img.width; |
311 double baseScaleY = 32.0/_img.height; | 311 double baseScaleY = 32.0/_img.height; |
312 | 312 |
313 // Draw each star | 313 // Draw each star |
314 for (int i = 0; i < _numStars; i++) { | 314 for (int i = 0; i < _numStars; i++) { |
315 Point pos = _starPositions[i]; | 315 Point pos = _starPositions[i]; |
316 double scale = _starScales[i]; | 316 double scale = _starScales[i]; |
317 paint.color = new Color.fromARGB((255.0*_opacity[i]).toInt(), 255, 255, 25
5); | 317 paint.color = new Color.fromARGB((255.0*_opacity[i]).toInt(), 255, 255, 25
5); |
318 | 318 |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
384 double dy = a.y - b.y; | 384 double dy = a.y - b.y; |
385 if (dx < 0.0) dx = -dx; | 385 if (dx < 0.0) dx = -dx; |
386 if (dy < 0.0) dy = -dy; | 386 if (dy < 0.0) dy = -dy; |
387 if (dx > dy) { | 387 if (dx > dy) { |
388 return dx + dy/2.0; | 388 return dx + dy/2.0; |
389 } | 389 } |
390 else { | 390 else { |
391 return dy + dx/2.0; | 391 return dy + dx/2.0; |
392 } | 392 } |
393 } | 393 } |
OLD | NEW |