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

Side by Side Diff: sky/examples/game/lib/game_world.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 unified diff | Download patch
« no previous file with comments | « sky/examples/game/lib/game_tests.dart ('k') | sky/examples/game/lib/sprite_box.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 class GameWorld extends TransformNode { 3 class GameWorld extends TransformNode {
4 4
5 World world; 5 World world;
6 List<Body> bodies = []; 6 List<Body> bodies = [];
7 Body _bodyShip; 7 Body _bodyShip;
8 8
9 Image _imgBg; 9 Image _imgBg;
10 Image _imgAsteroid; 10 Image _imgAsteroid;
(...skipping 12 matching lines...) Expand all
23 _imgAsteroid = images["https://raw.githubusercontent.com/slembcke/GalacticGu ardian.spritebuilder/GDC/Packages/SpriteBuilder%20Resources.sbpack/Sprites/resou rces-auto/asteroid_big_002.png"]; 23 _imgAsteroid = images["https://raw.githubusercontent.com/slembcke/GalacticGu ardian.spritebuilder/GDC/Packages/SpriteBuilder%20Resources.sbpack/Sprites/resou rces-auto/asteroid_big_002.png"];
24 _imgShip = images["https://raw.githubusercontent.com/slembcke/GalacticGuardi an.spritebuilder/GDC/Packages/SpriteBuilder%20Resources.sbpack/Sprites/resources -auto/GG_blueship_Lv3.png"]; 24 _imgShip = images["https://raw.githubusercontent.com/slembcke/GalacticGuardi an.spritebuilder/GDC/Packages/SpriteBuilder%20Resources.sbpack/Sprites/resources -auto/GG_blueship_Lv3.png"];
25 25
26 // Create the physics world 26 // Create the physics world
27 world = new World.withGravity(new Vector2(0.0, 0.0)); 27 world = new World.withGravity(new Vector2(0.0, 0.0));
28 28
29 // Add a background 29 // Add a background
30 addBackground(); 30 addBackground();
31 31
32 // Add some asteroids to the game world 32 // Add some asteroids to the game world
33 for (int i = 0; i < 5; i++) { 33 for (int i = 0; i < 50; i++) {
34 addAsteroid(10.0); 34 addAsteroid(10.0);
35 } 35 }
36 for (int i = 0; i < 5; i++) { 36 for (int i = 0; i < 50; i++) {
37 addAsteroid(20.0); 37 addAsteroid(20.0);
38 } 38 }
39 39
40 // Add ship 40 // Add ship
41 addShip(); 41 addShip();
42 } 42 }
43 43
44 void addBackground() { 44 void addBackground() {
45 SpriteNode sprtBg = new SpriteNode.withImage(_imgBg); 45 SpriteNode sprtBg = new SpriteNode.withImage(_imgBg);
46 sprtBg.width = width; 46 sprtBg.width = width;
47 sprtBg.height = height; 47 sprtBg.height = height;
48 sprtBg.pivot = new Vector2(0.0, 0.0); 48 sprtBg.pivot = new Vector2(0.0, 0.0);
49 this.children.add(sprtBg); 49 this.addChild(sprtBg);
50 } 50 }
51 51
52 void addAsteroid([double radius=20.0]) { 52 void addAsteroid([double radius=20.0]) {
53 53
54 // Create shape 54 // Create shape
55 final CircleShape shape = new CircleShape(); 55 final CircleShape shape = new CircleShape();
56 shape.radius = radius; 56 shape.radius = radius;
57 57
58 // Define fixture (links body and shape) 58 // Define fixture (links body and shape)
59 final FixtureDef activeFixtureDef = new FixtureDef(); 59 final FixtureDef activeFixtureDef = new FixtureDef();
(...skipping 20 matching lines...) Expand all
80 // Add to list 80 // Add to list
81 bodies.add(body); 81 bodies.add(body);
82 82
83 // Create sprite 83 // Create sprite
84 SpriteNode sprt = new SpriteNode.withImage(_imgAsteroid); 84 SpriteNode sprt = new SpriteNode.withImage(_imgAsteroid);
85 sprt.width = radius*2; 85 sprt.width = radius*2;
86 sprt.height = radius*2; 86 sprt.height = radius*2;
87 // sprt.colorOverlay = new Color(0x33ff0000); 87 // sprt.colorOverlay = new Color(0x33ff0000);
88 // sprt.transferMode = TransferMode.plusMode; 88 // sprt.transferMode = TransferMode.plusMode;
89 body.userData = sprt; 89 body.userData = sprt;
90 this.children.add(sprt); 90 this.addChild(sprt);
91 } 91 }
92 92
93 void addShip() { 93 void addShip() {
94 double radius = 30.0; 94 double radius = 30.0;
95 95
96 // Create shape 96 // Create shape
97 final CircleShape shape = new CircleShape(); 97 final CircleShape shape = new CircleShape();
98 shape.radius = radius; 98 shape.radius = radius;
99 99
100 // Define fixture (links body and shape) 100 // Define fixture (links body and shape)
(...skipping 19 matching lines...) Expand all
120 // Add to list 120 // Add to list
121 bodies.add(body); 121 bodies.add(body);
122 _bodyShip = body; 122 _bodyShip = body;
123 123
124 // Create sprite 124 // Create sprite
125 SpriteNode sprt = new SpriteNode.withImage(_imgShip); 125 SpriteNode sprt = new SpriteNode.withImage(_imgShip);
126 sprt.width = radius*2; 126 sprt.width = radius*2;
127 sprt.height = radius*2; 127 sprt.height = radius*2;
128 sprt.position = new Vector2(width/2.0, height/2.0); 128 sprt.position = new Vector2(width/2.0, height/2.0);
129 body.userData = sprt; 129 body.userData = sprt;
130 this.children.add(sprt); 130 this.addChild(sprt);
131 } 131 }
132 132
133 void update(double dt) { 133 void update(double dt) {
134 // Apply thrust 134 // Apply thrust
135 if (_thrustInput != null) { 135 if (_thrustInput != null) {
136 double force = _thrustInput*10000.0; 136 double force = _thrustInput*10000.0;
137 double rad = degrees2radians(_bodyShip.getAngle()); 137 double rad = degrees2radians(_bodyShip.getAngle());
138 _bodyShip.applyLinearImpulse(new Vector2(Math.cos(rad)*force, Math.sin(rad )*force), new Vector2(0.0, 0.0), true); 138 _bodyShip.applyLinearImpulse(new Vector2(Math.cos(rad)*force, Math.sin(rad )*force), new Vector2(0.0, 0.0), true);
139 } 139 }
140 140
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 } 182 }
183 183
184 void controlThrust(double input) { 184 void controlThrust(double input) {
185 _thrustInput = input; 185 _thrustInput = input;
186 } 186 }
187 187
188 void controlFire() { 188 void controlFire() {
189 189
190 } 190 }
191 } 191 }
OLDNEW
« no previous file with comments | « sky/examples/game/lib/game_tests.dart ('k') | sky/examples/game/lib/sprite_box.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698