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

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

Issue 1215413002: First pass on action animations for sprites (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: 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;
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 296
297 Asteroid(Texture img, AsteroidSize this._asteroidSize) : super(img) { 297 Asteroid(Texture img, AsteroidSize this._asteroidSize) : super(img) {
298 size = new Size(radius * 2.0, radius * 2.0); 298 size = new Size(radius * 2.0, radius * 2.0);
299 position = new Point(_gameSizeWidth * _rand.nextDouble(), _gameSizeHeight * _rand.nextDouble()); 299 position = new Point(_gameSizeWidth * _rand.nextDouble(), _gameSizeHeight * _rand.nextDouble());
300 rotation = 360.0 * _rand.nextDouble(); 300 rotation = 360.0 * _rand.nextDouble();
301 301
302 _movementVector = new Point(_rand.nextDouble() * _maxAsteroidSpeed * 2 - _ma xAsteroidSpeed, 302 _movementVector = new Point(_rand.nextDouble() * _maxAsteroidSpeed * 2 - _ma xAsteroidSpeed,
303 _rand.nextDouble() * _maxAsteroidSpeed * 2 - _ma xAsteroidSpeed); 303 _rand.nextDouble() * _maxAsteroidSpeed * 2 - _ma xAsteroidSpeed);
304 304
305 userInteractionEnabled = true; 305 userInteractionEnabled = true;
306
307 // Rotate forever
308 double direction = (_rand.nextBool()) ? 360.0 : -360.0;
309 ActionTween rot = new ActionTween( (a) => rotation = a, 0.0, direction, 2.0 * _rand.nextDouble() + 2.0);
310 ActionRepeatForever repeat = new ActionRepeatForever(rot);
311 actions.run(repeat);
306 } 312 }
307 313
308 bool handleEvent(SpriteBoxEvent event) { 314 bool handleEvent(SpriteBoxEvent event) {
309 if (event.type == "pointerdown") { 315 if (event.type == "pointerdown") {
310 colorOverlay = new Color(0x99ff0000); 316 colorOverlay = new Color(0x99ff0000);
311 } 317 }
312 else if (event.type == "pointerup") { 318 else if (event.type == "pointerup") {
313 colorOverlay = null; 319 colorOverlay = null;
314 } 320 }
315 return false; 321 return false;
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
467 double dy = a.y - b.y; 473 double dy = a.y - b.y;
468 if (dx < 0.0) dx = -dx; 474 if (dx < 0.0) dx = -dx;
469 if (dy < 0.0) dy = -dy; 475 if (dy < 0.0) dy = -dy;
470 if (dx > dy) { 476 if (dx > dy) {
471 return dx + dy/2.0; 477 return dx + dy/2.0;
472 } 478 }
473 else { 479 else {
474 return dy + dx/2.0; 480 return dy + dx/2.0;
475 } 481 }
476 } 482 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698