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

Unified Diff: sky/examples/game/lib/game_tests.dart

Issue 1177563004: Adds support for zOrder and references to parent nodes in sprites (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sky/examples/game/lib/game.dart ('k') | sky/examples/game/lib/game_world.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sky/examples/game/lib/game_tests.dart
diff --git a/sky/examples/game/lib/game_tests.dart b/sky/examples/game/lib/game_tests.dart
new file mode 100644
index 0000000000000000000000000000000000000000..c9800df8d001b20d524d59049744e95d303ea1ca
--- /dev/null
+++ b/sky/examples/game/lib/game_tests.dart
@@ -0,0 +1,67 @@
+part of game;
+
+Math.Random _rand;
+
+class GameTests extends TransformNode{
+
+ Image _imgAsteroid;
+ Image _imgBg;
+ Image _imgShip;
+
+ GameTests(ImageMap images) {
+ // Setup random number generator
+ _rand = new Math.Random();
+
+ // Fetch images
+ _imgBg = images["https://raw.githubusercontent.com/slembcke/GalacticGuardian.spritebuilder/GDC/Packages/SpriteBuilder%20Resources.sbpack/resources-auto/BurnTexture.png"];
+ _imgAsteroid = images["https://raw.githubusercontent.com/slembcke/GalacticGuardian.spritebuilder/GDC/Packages/SpriteBuilder%20Resources.sbpack/Sprites/resources-auto/asteroid_big_002.png"];
+ _imgShip = images["https://raw.githubusercontent.com/slembcke/GalacticGuardian.spritebuilder/GDC/Packages/SpriteBuilder%20Resources.sbpack/Sprites/resources-auto/GG_blueship_Lv3.png"];
+
+ for (int i = 0; i < 100; i++) {
+ addSprite(i/100.0);
+ }
+ }
+
+ void addSprite([double scale = null]) {
+ TestAsteroidSprite sprt = new TestAsteroidSprite.withImage(_imgAsteroid);
+ sprt.width = 64.0;
+ sprt.height = 64.0;
+
+ if (scale == null) {
+ scale = _rand.nextDouble();
+ }
+
+ sprt.zPosition = scale;
+ sprt.scale = scale;
+ sprt.position = new Vector2(_rand.nextDouble()*1024.0, _rand.nextDouble()*1024.0);
+
+ this.addChild(sprt);
+ }
+
+ void update(double dt) {
+ for (TransformNode child in children) {
+ child.update(dt);
+ }
+ }
+}
+
+class TestAsteroidSprite extends SpriteNode {
+
+ Vector2 _movementVector;
+ double _rotationalSpeed;
+
+ TestAsteroidSprite.withImage(Image img) : super.withImage(img) {
+ _movementVector = new Vector2(_rand.nextDouble() * 4.0 - 2.0, _rand.nextDouble() * 4.0 - 2.0);
+ _rotationalSpeed = _rand.nextDouble() * 2.0 - 1.0;
+ }
+
+ void update(double dt) {
+ position = position + _movementVector * scale;
+
+ // Bounce at edges
+ if (position[0] < 0 || position[0] > 1024.0) _movementVector[0] = -_movementVector[0];
+ if (position[1] < 0 || position[1] > 1024.0) _movementVector[1] = -_movementVector[1];
+
+ rotation += _rotationalSpeed;
+ }
+}
« no previous file with comments | « sky/examples/game/lib/game.dart ('k') | sky/examples/game/lib/game_world.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698