List of usage examples for com.badlogic.gdx.physics.box2d World World
public World(Vector2 gravity, boolean doSleep)
From source file:Tabox2D.java
License:Open Source License
private Tabox2D(Vector2 gravity) { width = Gdx.graphics.getWidth();/* www .j a v a 2s . c o m*/ height = Gdx.graphics.getHeight(); meterSize = 100;// 1 metter = 100px, default. polyInfo = new HashMap<String, Float>(); rawForces = false; // Sides by polygon: polyInfo.put("triangle", 3f); polyInfo.put("square", 4f); polyInfo.put("pentagon", 5f); polyInfo.put("hexagon", 6f); polyInfo.put("heptagon", 7f); polyInfo.put("octagon", 8f); // Angle of the sides: polyInfo.put("triangle_angle", 120f); polyInfo.put("square_angle", 90f); polyInfo.put("pentagon_angle", 72f); polyInfo.put("hexagon_angle", 60f); polyInfo.put("heptagon_angle", 51.428f); polyInfo.put("octagon_angle", 45f); filterMin = "linear"; filterMag = "linear"; renderer = new Box2DDebugRenderer(); sr = new ShapeRenderer(); spriteBath = new SpriteBatch(); adjustCamera(); tabodies = new ArrayList<Tabody>(); world = new World(new Vector2(gravity.x, gravity.y), true); sr = new ShapeRenderer(); }
From source file:be.ac.ucl.lfsab1509.bouboule.game.gameManager.GraphicManager.java
License:Open Source License
/** * Create the world, the body container and define the game as notPaused * /*from www . j a v a 2 s. com*/ * GraphicManager() */ public GraphicManager() { world = new World(new Vector2(0, 0), true); world.setContactListener(new EndGameListener()); //world.setVelocityThreshold(10.0f); bodies = new ArrayList<GameBody>(); loadScoreboard(); }
From source file:com.agateau.pixelwheels.GameWorld.java
License:Open Source License
public GameWorld(PwGame game, GameInfo gameInfo, PerformanceCounters performanceCounters) { mGame = game;//from w w w . j ava2s .co m mBox2DWorld = new World(new Vector2(0, 0), true); mBox2DWorld.setContactListener(this); mTrack = gameInfo.getTrack(); mTrack.init(); mCountDown = new CountDown(this, game.getAudioManager(), game.getAssets().soundAtlas); mBox2DPerformanceCounter = performanceCounters.add("- box2d"); mGameObjectPerformanceCounter = performanceCounters.add("- g.o"); setupRacers(gameInfo.getEntrants()); setupRoadBorders(); setupBonusSpots(); setupBonusPools(); }
From source file:com.arkanoid.game.model.GameField.java
License:Apache License
public GameField(WorldListener listener) { this.world = new World(GameField.gravity, true); this.world.setContactListener(this); this.level = 0; this.builder = new WorldBuilder(level); this.vaus = new Vaus(world, WORLD_WIDTH / 2, VAUS_Y_POS, VAUS_WIDTH, VAUS_HEIGHT); this.ball = new Ball(world, WORLD_WIDTH / 2, 300, BALL_RADIUS); this.border = new Border(world); //Border.createBorder(world, new Vector2[]{new Vector2(1, 1), new Vector2(WORLD_WIDTH - 1, 1)}, 10f, 0f); this.bumpedBrick = null; this.contactMask = 0; this.bricks = new ArrayList<Brick>(); buildScene(level);/*from w w w . j ava 2 s.c o m*/ this.listener = listener; rand = new Random(); this.lives = DEFAULT_LIVES; this.state = WORLD_STATE_RUNNING; }
From source file:com.barconr.games.marblegame.Physics2D.java
License:Apache License
public void createFixtures(TiledMap tiledmap) { int layerHeight = 0, layerWidth = 0; float tileWidth = 0, tileHeight = 0; ballsListener = new BallContactListener(); // Load the Tiled map layer and store some relevant variables TiledMapTileLayer tilelayer = (TiledMapTileLayer) (tiledmap.getLayers().get(0)); layerHeight = tilelayer.getHeight(); layerWidth = tilelayer.getWidth();/* w w w. ja v a2 s . c o m*/ maze = new Maze(layerWidth, layerHeight); tileHeight = tilelayer.getTileHeight(); tileWidth = tilelayer.getTileWidth(); System.out.println("Layer height (tiles) = " + layerHeight + " Layer width (tiles) = " + layerWidth + " Tile height = " + tileHeight + "tile width = " + tileWidth); System.out.println("Tile count = " + tilelayer.getObjects().getCount()); System.out.println("layer height pixels = " + (layerHeight * tileHeight) + "LAYER WIDTH PIXELS : " + (layerWidth * tileWidth)); //Create the box2d world world = new World(new Vector2(0, -9), true); world.setContactListener(ballsListener); // Loop through the grid reference for (int y_pos = 0; y_pos < layerHeight; y_pos++) { for (int x_pos = 0; x_pos < layerWidth; x_pos++) { boolean impassibleBlock = tilelayer.getCell(x_pos, layerHeight - y_pos - 1).getTile() .getProperties().containsKey("block"); // If the tile square contains the reference "start" // Store this as the start position if (tilelayer.getCell(x_pos, layerHeight - y_pos - 1).getTile().getProperties() .containsKey("start")) { if (startPosition == null) { System.out.println("x:" + x_pos * tileWidth + " y:" + y_pos * tileHeight); startPosition = new Vector2(x_pos * tileWidth * Assets.METERS_PER_PIXEL, (50 - y_pos) * tileHeight * Assets.METERS_PER_PIXEL); } } //Create a fixture for the end position if (tilelayer.getCell(x_pos, layerHeight - y_pos - 1).getTile().getProperties() .containsKey("end")) { //Draw box for fixture that is impassible PolygonShape squareShape = new PolygonShape(); BodyDef squareBodyDef = new BodyDef(); squareBodyDef.type = BodyType.StaticBody; //Static body which won't move //Box position squareBodyDef.position.set(new Vector2((x_pos * Assets.METERS_PER_PIXEL * tileWidth), (layerHeight - y_pos - 1) * Assets.METERS_PER_PIXEL * tileHeight)); //Correction for fact Box2Ds squares are half width/height from center point squareBodyDef.position.add(tileWidth / 2 * Assets.METERS_PER_PIXEL, tileHeight / 2 * Assets.METERS_PER_PIXEL); Body squareBody = world.createBody(squareBodyDef); squareShape.setAsBox(tileWidth / 2 * Assets.METERS_PER_PIXEL, tileHeight / 2 * Assets.METERS_PER_PIXEL); FixtureDef fixDefSquare = new FixtureDef(); fixDefSquare.shape = squareShape; fixDefSquare.isSensor = true; fixDefSquare.density = 0.1f; fixDefSquare.restitution = 0.3f; Fixture endFix = squareBody.createFixture(fixDefSquare); endFix.setSensor(true); endFix.setUserData("exit"); } if (impassibleBlock) { //Draw box for fixture that blocks maze.setMazeUnit(new MazeUnit("block"), x_pos, y_pos); //System.out.print("@"); // Draw ascii map in stdout } else { maze.setMazeUnit(new MazeUnit("passage"), x_pos, y_pos); } } //System.out.println(); } // The players ball playerBallBodyDef = new BodyDef(); playerBallBodyDef.type = BodyType.DynamicBody; if (startPosition == null) { playerBallBodyDef.position.set(3f, 3f); } else { playerBallBodyDef.position.set(startPosition.x, startPosition.y); } playerBallBodyDef.allowSleep = false; ballCircleBody = world.createBody(playerBallBodyDef); dynamicCircle = new CircleShape(); dynamicCircle.setRadius(8 / Assets.PIXELS_PER_METER); FixtureDef ballFixtureDef = new FixtureDef(); ballFixtureDef.shape = dynamicCircle; ballFixtureDef.density = 0.1f; ballFixtureDef.friction = 1f; //ballFixtureDef. ballFixtureDef.restitution = 0.5f; //ballCircleBody.setUserData("ball"); Fixture fx = ballCircleBody.createFixture(ballFixtureDef); fx.setUserData("ball"); maze.removeExtraBoxes(); /* PolygonShape squareShape = new PolygonShape(); */ for (int i = 0; i < maze.width; i++) { for (int j = 0; j < maze.height; j++) { if (maze.mazeUnits[j][i].getType().equals("block")) { BodyDef squareBodyDef = new BodyDef(); PolygonShape squareShape = new PolygonShape(); squareBodyDef.type = BodyType.StaticBody; //Static body which won't move //Box position squareBodyDef.position.set(new Vector2((j * Assets.METERS_PER_PIXEL * tileWidth), (layerHeight - i - 1) * Assets.METERS_PER_PIXEL * tileHeight)); //Correction for fact Box2Ds squares are half width/height from center point squareBodyDef.position.add(tileWidth / 2 * Assets.METERS_PER_PIXEL, tileHeight / 2 * Assets.METERS_PER_PIXEL); Body squareBody = world.createBody(squareBodyDef); //Size of box squareShape.setAsBox(tileWidth / 2 * Assets.METERS_PER_PIXEL, tileHeight / 2 * Assets.METERS_PER_PIXEL); FixtureDef fixDefSquare = new FixtureDef(); fixDefSquare.shape = squareShape; fixDefSquare.density = 0.1f; fixDefSquare.restitution = 0.3f; squareBody.createFixture(fixDefSquare); } } } }
From source file:com.dgzt.core.Table.java
License:Open Source License
/** * The constructor.//from ww w . j av a 2 s. c o m * * @param shader - The shader. * @param gameControl - The game control. */ public Table(final ShaderProgram shader, final GameControl gameControl) { super(shader, Color.GRAY); box2DWorld = new World(new Vector2(0, 0), true); final EventListener eventListener = new EventListener(this, gameControl); box2DWorld.setContactListener(eventListener); addBox2DWalls(); map = new Map(shader, box2DWorld, (Table.WIDTH - Map.WIDTH) / 2, (Table.HEIGHT - Map.HEIGHT) / 2); leftGate = new LeftGate(shader, box2DWorld, (Table.WIDTH - Map.WIDTH) / 2 - LeftGate.WIDTH + LineShape.LINE_WIDTH, (Table.HEIGHT - LeftGate.HEIGHT) / 2); rightGate = new RightGate(shader, box2DWorld, Table.WIDTH - (Table.WIDTH - Map.WIDTH) / 2 - LineShape.LINE_WIDTH, (Table.HEIGHT - RightGate.HEIGHT) / 2); playerButtons = new ArrayList<Button>(); opponentButtons = new ArrayList<Button>(); addButtons(shader, eventListener); ball = new Ball(this, shader, eventListener, box2DWorld, Table.WIDTH / 2, Table.HEIGHT / 2); arrow = new Arrow(this, shader); }
From source file:com.disc.jammers.states.StatePlay.java
public StatePlay(GameStateManager gsm) { super(gsm);//from w ww .j a va 2s. c o m eventQueue = new EventQueue(); camera.setToOrtho(false, WIDTH, HEIGHT); Gdx.input.setInputProcessor(new MyInputProcessor(eventQueue)); //Box2d Initialization world = new World(new Vector2(0, 0), true); world.setContactListener(new MyContactListener(eventQueue)); b2dr = new Box2DDebugRenderer(); manager = new GameManager(world, eventQueue); //--Sprites createBoxBoundaries(); tempBackground = new Texture("court.png"); }
From source file:com.dongbat.game.util.PhysicsUtil.java
/** * Initialize a box2d world and put it into libGdx ObjectMap * * @param world artemis world/* w w w .j a v a 2s.com*/ */ public static void init(com.artemis.World world) { if (physicsWorldMap.get(world) != null) { return; } World physicsWorld = new World(new Vector2(0, Constants.PHYSICS.DEFAULT_GRAVITY), false); physicsWorldMap.put(world, physicsWorld); artemisWorldMap.put(physicsWorld, world); }
From source file:com.dongbat.invasion.util.PhysicsUtil.java
public static World getWorld() { if (physicsWorld == null) { physicsWorld = new World(new Vector2(0, Constants.PHYSICS.DEFAULT_GRAVITY), false); }/*from ww w .j a va 2s. c o m*/ return physicsWorld; }
From source file:com.esotericsoftware.spine.Box2DExample.java
License:Open Source License
private void createWorld() { world = new World(new Vector2(0, -10), true); float[] vertices = { -0.07421887f, -0.16276085f, -0.12109375f, -0.22786504f, -0.157552f, -0.7122401f, 0.04296875f, -0.7122401f, 0.110677004f, -0.6419276f, 0.13151026f, -0.49869835f, 0.08984375f, -0.3190109f };// ww w. ja v a 2 s .com PolygonShape shape = new PolygonShape(); shape.set(vertices); // next we create a static ground platform. This platform // is not moveable and will not react to any influences from // outside. It will however influence other bodies. First we // create a PolygonShape that holds the form of the platform. // it will be 100 meters wide and 2 meters high, centered // around the origin PolygonShape groundPoly = new PolygonShape(); groundPoly.setAsBox(50, 1); // next we create the body for the ground platform. It's // simply a static body. BodyDef groundBodyDef = new BodyDef(); groundBodyDef.type = BodyType.StaticBody; groundBody = world.createBody(groundBodyDef); // finally we add a fixture to the body using the polygon // defined above. Note that we have to dispose PolygonShapes // and CircleShapes once they are no longer used. This is the // only time you have to care explicitely for memomry managment. FixtureDef fixtureDef = new FixtureDef(); fixtureDef.shape = groundPoly; fixtureDef.filter.groupIndex = 0; groundBody.createFixture(fixtureDef); groundPoly.dispose(); PolygonShape boxPoly = new PolygonShape(); boxPoly.setAsBox(1, 1); // Next we create the 50 box bodies using the PolygonShape we just // defined. This process is similar to the one we used for the ground // body. Note that we reuse the polygon for each body fixture. for (int i = 0; i < 45; i++) { // Create the BodyDef, set a random position above the // ground and create a new body BodyDef boxBodyDef = new BodyDef(); boxBodyDef.type = BodyType.DynamicBody; boxBodyDef.position.x = -24 + (float) (Math.random() * 48); boxBodyDef.position.y = 10 + (float) (Math.random() * 100); Body boxBody = world.createBody(boxBodyDef); boxBody.createFixture(boxPoly, 1); } // we are done, all that's left is disposing the boxPoly boxPoly.dispose(); }