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

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

Issue 1216573009: Adds particle systems to 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
« no previous file with comments | « sky/sdk/example/game/lib/game_demo.dart ('k') | sky/sdk/example/game/lib/particle_system.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 void addShip() { 83 void addShip() {
84 Ship ship = new Ship(_spriteSheet["ship.png"]); 84 Ship ship = new Ship(_spriteSheet["ship.png"]);
85 ship.zPosition = 10.0; 85 ship.zPosition = 10.0;
86 _gameLayer.addChild(ship); 86 _gameLayer.addChild(ship);
87 _ship = ship; 87 _ship = ship;
88 } 88 }
89 89
90 void addLaser() { 90 void addLaser() {
91 Laser laser = new Laser(_spriteSheet["laser.png"], _ship); 91 Laser laser = new Laser(_spriteSheet["laser.png"], _ship);
92 laser.zPosition = 8.0; 92 laser.zPosition = 8.0;
93 laser.constrainProportions = true;
93 _lasers.add(laser); 94 _lasers.add(laser);
94 _gameLayer.addChild(laser); 95 _gameLayer.addChild(laser);
95 } 96 }
96 97
97 void addNebula() { 98 void addNebula() {
98 _nebula = new Nebula.withImage(_imgNebula); 99 _nebula = new Nebula.withImage(_imgNebula);
99 _gameLayer.addChild(_nebula); 100 _gameLayer.addChild(_nebula);
100 } 101 }
101 102
103 void addExplosion(AsteroidSize asteroidSize, Point position) {
104 // Add particles
105 ParticleSystem particles = new ParticleSystem(_spriteSheet["laser.png"], rot ateToMovement: true,
eseidel 2015/06/30 01:04:50 I'm not sure what the dart style is, but I would h
106 startRotation:90.0, startRotationVar: 0.0, endRotation: 90.0, startSize: 0.2 , startSizeVar: 0.1, endSize: 0.2, endSizeVar: 0.1,
107 numParticlesToEmit: 25, emissionRate:1000.0, blueVar: 127);
108 particles.zPosition = 1010.0;
109 particles.position = position;
110 _gameLayer.addChild(particles);
111 }
112
102 void update(double dt) { 113 void update(double dt) {
103 // Move asteroids 114 // Move asteroids
104 for (Asteroid asteroid in _asteroids) { 115 for (Asteroid asteroid in _asteroids) {
105 asteroid.position = pointAdd(asteroid.position, asteroid._movementVector); 116 asteroid.position = pointAdd(asteroid.position, asteroid._movementVector);
106 } 117 }
107 118
108 // Move lasers and remove expired lasers 119 // Move lasers and remove expired lasers
109 for (int i = _lasers.length - 1; i >= 0; i--) { 120 for (int i = _lasers.length - 1; i >= 0; i--) {
110 Laser laser = _lasers[i]; 121 Laser laser = _lasers[i];
111 laser.move(); 122 laser.move();
(...skipping 19 matching lines...) Expand all
131 for (int j = _asteroids.length - 1; j >= 0; j--) { 142 for (int j = _asteroids.length - 1; j >= 0; j--) {
132 // Iterate over all the asteroids 143 // Iterate over all the asteroids
133 Asteroid asteroid = _asteroids[j]; 144 Asteroid asteroid = _asteroids[j];
134 145
135 // Check for collision 146 // Check for collision
136 if (pointQuickDist(laser.position, asteroid.position) < laser.radius + a steroid.radius) { 147 if (pointQuickDist(laser.position, asteroid.position) < laser.radius + a steroid.radius) {
137 // Remove laser 148 // Remove laser
138 laser.removeFromParent(); 149 laser.removeFromParent();
139 _lasers.removeAt(i); 150 _lasers.removeAt(i);
140 151
141 // Add asteroids 152 // Add asteroids and explosions
142 if (asteroid._asteroidSize == AsteroidSize.large) { 153 if (asteroid._asteroidSize == AsteroidSize.large) {
143 for (int a = 0; a < 3; a++) addAsteroid(AsteroidSize.medium, asteroi d.position); 154 for (int a = 0; a < 3; a++) addAsteroid(AsteroidSize.medium, asteroi d.position);
144 } 155 }
145 else if (asteroid._asteroidSize == AsteroidSize.medium) { 156 else if (asteroid._asteroidSize == AsteroidSize.medium) {
146 for (int a = 0; a < 5; a++) addAsteroid(AsteroidSize.small, asteroid .position); 157 for (int a = 0; a < 5; a++) addAsteroid(AsteroidSize.small, asteroid .position);
147 } 158 }
148 159
160 addExplosion(asteroid._asteroidSize, asteroid.position);
161
149 // Remove asteroid 162 // Remove asteroid
150 asteroid.removeFromParent(); 163 asteroid.removeFromParent();
151 _asteroids.removeAt(j); 164 _asteroids.removeAt(j);
152 break; 165 break;
153 } 166 }
154 } 167 }
155 } 168 }
156 169
157 // Move objects to center camera and warp objects around the edges 170 // Move objects to center camera and warp objects around the edges
158 centerCamera(); 171 centerCamera();
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
326 position = new Point(position.x + _movementVector[0], position.y + _movement Vector[1]); 339 position = new Point(position.x + _movementVector[0], position.y + _movement Vector[1]);
327 _movementVector.scale(0.9); 340 _movementVector.scale(0.9);
328 341
329 rotation = dampenRotation(rotation, _rotationTarget, 0.1); 342 rotation = dampenRotation(rotation, _rotationTarget, 0.1);
330 } 343 }
331 } 344 }
332 345
333 class Laser extends Sprite { 346 class Laser extends Sprite {
334 int _frameCount = 0; 347 int _frameCount = 0;
335 Point _movementVector; 348 Point _movementVector;
336 double radius = 10.0; 349 double radius = 20.0;
337 350
338 Laser(Texture img, Ship ship) : super(img) { 351 Laser(Texture img, Ship ship) : super(img) {
339 size = new Size(20.0, 20.0); 352 size = new Size(30.0, 30.0);
340 position = ship.position; 353 position = ship.position;
341 rotation = ship.rotation + 90.0; 354 rotation = ship.rotation + 90.0;
342 transferMode = TransferMode.plus; 355 transferMode = TransferMode.plus;
343 double rotRadians = convertDegrees2Radians(rotation); 356 double rotRadians = convertDegrees2Radians(rotation);
344 _movementVector = pointMult(new Point(Math.sin(rotRadians), -Math.cos(rotRad ians)), 10.0); 357 _movementVector = pointMult(new Point(Math.sin(rotRadians), -Math.cos(rotRad ians)), 10.0);
345 _movementVector = new Point(_movementVector.x + ship._movementVector[0], _mo vementVector.y + ship._movementVector[1]); 358 _movementVector = new Point(_movementVector.x + ship._movementVector[0], _mo vementVector.y + ship._movementVector[1]);
346 } 359 }
347 360
348 void move() { 361 void move() {
349 position = pointAdd(position, _movementVector); 362 position = pointAdd(position, _movementVector);
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
454 double dy = a.y - b.y; 467 double dy = a.y - b.y;
455 if (dx < 0.0) dx = -dx; 468 if (dx < 0.0) dx = -dx;
456 if (dy < 0.0) dy = -dy; 469 if (dy < 0.0) dy = -dy;
457 if (dx > dy) { 470 if (dx > dy) {
458 return dx + dy/2.0; 471 return dx + dy/2.0;
459 } 472 }
460 else { 473 else {
461 return dy + dx/2.0; 474 return dy + dx/2.0;
462 } 475 }
463 } 476 }
OLDNEW
« no previous file with comments | « sky/sdk/example/game/lib/game_demo.dart ('k') | sky/sdk/example/game/lib/particle_system.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698