| 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(double width, double height) { | 9 GameWorld(ImageMap images) { |
| 10 this.width = width; | 10 this.width = 1024.0; |
| 11 this.height = height; | 11 this.height = 1024.0; |
| 12 | 12 |
| 13 world = new World.withGravity(new Vector2(0.0, 0.0)); | 13 world = new World.withGravity(new Vector2(0.0, 0.0)); |
| 14 | 14 |
| 15 // Load and add background | 15 // Load and add background |
| 16 Image imgBg = new Image()..src="https://raw.githubusercontent.com/slembcke/G
alacticGuardian.spritebuilder/GDC/Packages/SpriteBuilder%20Resources.sbpack/reso
urces-auto/BurnTexture.png"; | 16 Image imgBg = images["https://raw.githubusercontent.com/slembcke/GalacticGua
rdian.spritebuilder/GDC/Packages/SpriteBuilder%20Resources.sbpack/resources-auto
/BurnTexture.png"]; |
| 17 SpriteNode sprtBg = new SpriteNode.withImage(imgBg); | 17 SpriteNode sprtBg = new SpriteNode.withImage(imgBg); |
| 18 sprtBg.width = width; | 18 sprtBg.width = width; |
| 19 sprtBg.height = height; | 19 sprtBg.height = height; |
| 20 sprtBg.pivot = new Vector2(0.0, 0.0); | 20 sprtBg.pivot = new Vector2(0.0, 0.0); |
| 21 this.children.add(sprtBg); | 21 this.children.add(sprtBg); |
| 22 | 22 |
| 23 SpriteNode sprtCenter = new SpriteNode.withImage(imgBg); | |
| 24 sprtCenter.width = 32.0; | |
| 25 sprtCenter.height = 32.0; | |
| 26 sprtCenter.position = new Vector2(512.0, 512.0); | |
| 27 this.children.add(sprtCenter); | |
| 28 | |
| 29 // Load asteroid image | 23 // Load asteroid image |
| 30 _image = new Image()..src="https://raw.githubusercontent.com/slembcke/Galact
icGuardian.spritebuilder/GDC/Packages/SpriteBuilder%20Resources.sbpack/Sprites/r
esources-auto/asteroid_big_002.png"; | 24 _image = images["https://raw.githubusercontent.com/slembcke/GalacticGuardian
.spritebuilder/GDC/Packages/SpriteBuilder%20Resources.sbpack/Sprites/resources-a
uto/asteroid_big_002.png"]; |
| 31 | 25 |
| 32 // Add some asteroids to the game world | 26 // Add some asteroids to the game world |
| 33 for (int i = 0; i < 50; i++) { | 27 for (int i = 0; i < 50; i++) { |
| 34 addAsteroid(10.0); | 28 addAsteroid(10.0); |
| 35 } | 29 } |
| 36 for (int i = 0; i < 50; i++) { | 30 for (int i = 0; i < 50; i++) { |
| 37 addAsteroid(20.0); | 31 addAsteroid(20.0); |
| 38 } | 32 } |
| 39 } | 33 } |
| 40 | 34 |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 } | 92 } |
| 99 if (body.position[1] > this.height + sprt.height/2) { | 93 if (body.position[1] > this.height + sprt.height/2) { |
| 100 body.setTransform(new Vector2(body.position[0], body.position[1] - (this.h
eight + sprt.height)), rot); | 94 body.setTransform(new Vector2(body.position[0], body.position[1] - (this.h
eight + sprt.height)), rot); |
| 101 } | 95 } |
| 102 | 96 |
| 103 // Update sprite | 97 // Update sprite |
| 104 sprt.position = body.position; | 98 sprt.position = body.position; |
| 105 sprt.rotation = body.getAngle(); | 99 sprt.rotation = body.getAngle(); |
| 106 } | 100 } |
| 107 } | 101 } |
| OLD | NEW |