OLD | NEW |
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 Image _image; | 7 Image _image; |
8 | 8 |
9 GameWorld(ImageMap images) { | 9 GameWorld(ImageMap images) { |
10 this.width = 1024.0; | 10 this.width = 1024.0; |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 Math.Random rand = new Math.Random(); | 59 Math.Random rand = new Math.Random(); |
60 body.setTransform(new Vector2(rand.nextDouble() * this.width, rand.nextDoubl
e() * this.height), 0.0); | 60 body.setTransform(new Vector2(rand.nextDouble() * this.width, rand.nextDoubl
e() * this.height), 0.0); |
61 body.applyLinearImpulse(new Vector2(rand.nextDouble()*10000.0-5000.0, rand.n
extDouble()*10000.0-5000.0), new Vector2(0.0, 0.0), true); | 61 body.applyLinearImpulse(new Vector2(rand.nextDouble()*10000.0-5000.0, rand.n
extDouble()*10000.0-5000.0), new Vector2(0.0, 0.0), true); |
62 | 62 |
63 // Add to list | 63 // Add to list |
64 bodies.add(body); | 64 bodies.add(body); |
65 | 65 |
66 SpriteNode sprt = new SpriteNode.withImage(_image); | 66 SpriteNode sprt = new SpriteNode.withImage(_image); |
67 sprt.width = radius*2; | 67 sprt.width = radius*2; |
68 sprt.height = radius*2; | 68 sprt.height = radius*2; |
| 69 sprt.colorOverlay = new Color(0x33ff0000); |
| 70 sprt.transferMode = TransferMode.plusMode; |
69 body.userData = sprt; | 71 body.userData = sprt; |
70 this.children.add(sprt); | 72 this.children.add(sprt); |
71 } | 73 } |
72 | 74 |
73 void update(double dt) { | 75 void update(double dt) { |
74 world.stepDt(1.0/60.0, 10, 10); // Pass in dt | 76 world.stepDt(1.0/60.0, 10, 10); // Pass in dt |
75 | 77 |
76 bodies.forEach(updateBody); | 78 bodies.forEach(updateBody); |
77 } | 79 } |
78 | 80 |
(...skipping 13 matching lines...) Expand all Loading... |
92 } | 94 } |
93 if (body.position[1] > this.height + sprt.height/2) { | 95 if (body.position[1] > this.height + sprt.height/2) { |
94 body.setTransform(new Vector2(body.position[0], body.position[1] - (this.h
eight + sprt.height)), rot); | 96 body.setTransform(new Vector2(body.position[0], body.position[1] - (this.h
eight + sprt.height)), rot); |
95 } | 97 } |
96 | 98 |
97 // Update sprite | 99 // Update sprite |
98 sprt.position = body.position; | 100 sprt.position = body.position; |
99 sprt.rotation = body.getAngle(); | 101 sprt.rotation = body.getAngle(); |
100 } | 102 } |
101 } | 103 } |
OLD | NEW |