13
13
import com .brentaureli .mariobros .MarioBros ;
14
14
import com .brentaureli .mariobros .Screens .PlayScreen ;
15
15
import com .brentaureli .mariobros .Sprites .Enemies .Enemy ;
16
+ import com .brentaureli .mariobros .Sprites .Enemies .Goomba ;
16
17
import com .brentaureli .mariobros .Sprites .Enemies .Turtle ;
18
+ import com .brentaureli .mariobros .Sprites .Mario ;
17
19
import com .brentaureli .mariobros .Sprites .TileObjects .Brick ;
18
20
import com .brentaureli .mariobros .Sprites .TileObjects .Coin ;
19
- import com .brentaureli .mariobros .Sprites .Enemies .Goomba ;
20
21
21
22
/**
22
23
* Created by brentaureli on 8/28/15.
@@ -29,9 +30,10 @@ public class B2WorldCreator {
29
30
public static final String COINS_LAYER = "Coins" ;
30
31
public static final String GOOMBAS_LAYER = "Goombas" ;
31
32
public static final String TURTLES_LAYER = "Turtles" ;
33
+ private static final String PLAYER_LAYER = "Player" ;
32
34
33
- private Array < Goomba > goombas ;
34
- private Array <Turtle > turtles ;
35
+ private Mario mario ;
36
+ Array <Enemy > enemies = new Array < Enemy >() ;
35
37
36
38
public B2WorldCreator (PlayScreen screen ){
37
39
World world = screen .getWorld ();
@@ -41,8 +43,29 @@ public B2WorldCreator(PlayScreen screen){
41
43
PolygonShape shape = new PolygonShape ();
42
44
FixtureDef fdef = new FixtureDef ();
43
45
Body body ;
46
+ enemies = new Array <Enemy >();
44
47
45
48
//create ground bodies/fixtures
49
+ createGround (world , map , bdef , shape , fdef );
50
+
51
+ //create pipe bodies/fixtures
52
+ createPipes (world , map , bdef , shape , fdef );
53
+
54
+ //create brick bodies/fixtures
55
+ createBricks (screen , map );
56
+
57
+ //create coin bodies/fixtures
58
+ createCoins (screen , map );
59
+
60
+ //create all goombas
61
+ createGoombas (screen , map );
62
+ createTurtles (screen , map );
63
+
64
+ mario = createPlayer (screen , map );
65
+ }
66
+
67
+ private void createGround (World world , TiledMap map , BodyDef bdef , PolygonShape shape , FixtureDef fdef ) {
68
+ Body body ;
46
69
for (MapObject object : map .getLayers ().get (GROUND_LAYER ).getObjects ().getByType (RectangleMapObject .class )){
47
70
Rectangle rect = ((RectangleMapObject ) object ).getRectangle ();
48
71
@@ -55,8 +78,10 @@ public B2WorldCreator(PlayScreen screen){
55
78
fdef .shape = shape ;
56
79
body .createFixture (fdef );
57
80
}
81
+ }
58
82
59
- //create pipe bodies/fixtures
83
+ private void createPipes (World world , TiledMap map , BodyDef bdef , PolygonShape shape , FixtureDef fdef ) {
84
+ Body body ;
60
85
for (MapObject object : map .getLayers ().get (PIPES_LAYER ).getObjects ().getByType (RectangleMapObject .class )){
61
86
Rectangle rect = ((RectangleMapObject ) object ).getRectangle ();
62
87
@@ -75,34 +100,49 @@ public B2WorldCreator(PlayScreen screen){
75
100
| MarioBros .FIREBALL_BIT ;
76
101
body .createFixture (fdef );
77
102
}
103
+ }
78
104
79
- //create brick bodies/fixtures
105
+ private void createBricks ( PlayScreen screen , TiledMap map ) {
80
106
for (MapObject object : map .getLayers ().get (BRICKS_LAYER ).getObjects ().getByType (RectangleMapObject .class )){
81
107
new Brick (screen , object );
82
108
}
109
+ }
83
110
84
- //create coin bodies/fixtures
111
+ private void createCoins ( PlayScreen screen , TiledMap map ) {
85
112
for (MapObject object : map .getLayers ().get (COINS_LAYER ).getObjects ().getByType (RectangleMapObject .class )){
86
113
new Coin (screen , object );
87
114
}
115
+ }
88
116
89
- //create all goombas
90
- goombas = new Array <Goomba >();
117
+ private void createGoombas ( PlayScreen screen , TiledMap map ) {
118
+ Array < Goomba > goombas = new Array <Goomba >();
91
119
for (MapObject object : map .getLayers ().get (GOOMBAS_LAYER ).getObjects ().getByType (RectangleMapObject .class )){
92
120
Rectangle rect = ((RectangleMapObject ) object ).getRectangle ();
93
121
goombas .add (new Goomba (screen , rect .getX () / MarioBros .PPM , rect .getY () / MarioBros .PPM ));
94
122
}
95
- turtles = new Array <Turtle >();
123
+ enemies .addAll (goombas );
124
+ }
125
+
126
+ private void createTurtles (PlayScreen screen , TiledMap map ) {
127
+ Array <Turtle > turtles = new Array <Turtle >();
96
128
for (MapObject object : map .getLayers ().get (TURTLES_LAYER ).getObjects ().getByType (RectangleMapObject .class )){
97
129
Rectangle rect = ((RectangleMapObject ) object ).getRectangle ();
98
130
turtles .add (new Turtle (screen , rect .getX () / MarioBros .PPM , rect .getY () / MarioBros .PPM ));
99
131
}
132
+ enemies .addAll (turtles );
133
+ }
134
+
135
+ private Mario createPlayer (PlayScreen screen , TiledMap map ) {
136
+ Rectangle playerPosition = map .getLayers ().get (PLAYER_LAYER ).getObjects ().getByType (RectangleMapObject .class ).first ().getRectangle ();
137
+ Mario player = new Mario (screen , playerPosition .getX (), playerPosition .getY ());
138
+ return player ;
139
+ }
140
+
141
+ public Mario getMario () {
142
+ return mario ;
100
143
}
101
144
102
145
public Array <Enemy > getEnemies (){
103
- Array <Enemy > enemies = new Array <Enemy >();
104
- enemies .addAll (goombas );
105
- enemies .addAll (turtles );
106
146
return enemies ;
107
147
}
108
148
}
0 commit comments