• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*******************************************************************************
2  * Copyright 2011 See AUTHORS file.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *   http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  ******************************************************************************/
16 /*
17  * Copyright 2010 Mario Zechner (contact@badlogicgames.com), Nathan Sweet (admin@esotericsoftware.com)
18  *
19  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the
20  * License. You may obtain a copy of the License at
21  *
22  * http://www.apache.org/licenses/LICENSE-2.0
23  *
24  * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS"
25  * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language
26  * governing permissions and limitations under the License.
27  */
28 
29 package com.badlogic.gdx.tests.box2d;
30 
31 import com.badlogic.gdx.math.Vector2;
32 import com.badlogic.gdx.physics.box2d.Body;
33 import com.badlogic.gdx.physics.box2d.BodyDef;
34 import com.badlogic.gdx.physics.box2d.BodyDef.BodyType;
35 import com.badlogic.gdx.physics.box2d.EdgeShape;
36 import com.badlogic.gdx.physics.box2d.PolygonShape;
37 import com.badlogic.gdx.physics.box2d.World;
38 
39 public class Pyramid extends Box2DTest {
40 	@Override
createWorld(World world)41 	protected void createWorld (World world) {
42 		{
43 			BodyDef bd = new BodyDef();
44 			Body ground = world.createBody(bd);
45 
46 			EdgeShape shape = new EdgeShape();
47 			shape.set(new Vector2(-40, 0), new Vector2(40, 0));
48 			ground.createFixture(shape, 0.0f);
49 			shape.dispose();
50 		}
51 
52 		{
53 			float a = 0.5f;
54 			PolygonShape shape = new PolygonShape();
55 			shape.setAsBox(a, a);
56 
57 			Vector2 x = new Vector2(-7.0f, 0.75f);
58 			Vector2 y = new Vector2();
59 			Vector2 deltaX = new Vector2(0.5625f, 1.25f);
60 			Vector2 deltaY = new Vector2(1.125f, 0.0f);
61 
62 			for (int i = 0; i < 20; i++) {
63 				y.set(x);
64 
65 				for (int j = i; j < 20; j++) {
66 					BodyDef bd = new BodyDef();
67 					bd.type = BodyType.DynamicBody;
68 					bd.position.set(y);
69 					Body body = world.createBody(bd);
70 					body.createFixture(shape, 5.0f);
71 
72 					y.add(deltaY);
73 				}
74 
75 				x.add(deltaX);
76 			}
77 
78 		}
79 	}
80 }
81