Java Code Examples for com.badlogic.gdx.physics.box2d.Box2DDebugRenderer

The following are top voted examples for showing how to use com.badlogic.gdx.physics.box2d.Box2DDebugRenderer. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: feup-lpoo-armadillo   File: GameScreen.java   View source code 6 votes vote down vote up
/**
 * Creates a new Orthographic Camera for the Game.
 *
 * @return the created camera.
 */
private OrthographicCamera createCamera() {
    OrthographicCamera camera = new OrthographicCamera(VIEWPORT_WIDTH / PIXEL_TO_METER,
            VIEWPORT_HEIGHT / PIXEL_TO_METER);

    camera.position.set(model.getBallModel().getX() / PIXEL_TO_METER,
            model.getBallModel().getY() / PIXEL_TO_METER, 0);
    camera.update();

    if (DEBUG_PHYSICS) {
        debugRenderer = new Box2DDebugRenderer();
        debugCamera = camera.combined.cpy();
        debugCamera.scl(1 / PIXEL_TO_METER);
    }

    return camera;
}
 
Example 2
Project: fabulae   File: GameMap.java   View source code 6 votes vote down vote up
/**
 * Recreates all disposables.
 */
public void undispose() {
	if (!isDisposed) {
		return;
	}
	box2DDebugRenderer = new Box2DDebugRenderer(true, true, true, true, true, true);
	fogOfWarWorld = new World(new Vector2(0, 0), true);
	lightsWorld = new World(new Vector2(0, 0), true);
	createFogOfWarRayHandler();
	createLightsRayHandler();
	createViewConesRayHandler();
	
	isDisposed = false;
	
	for (int i = 0; i < gameObjects.size; ++i) {
		gameObjects.get(i).undispose();
	}
	
	for (Entry<TrapLocation, FilledPolygonRenderer> entry : traps.entries()) {
		traps.put(entry.key, entry.key.createRenderer());
	}
}
 
Example 3
Project: libgdxGP   File: LevelScreen.java   View source code 6 votes vote down vote up
@Override
public void show() {
    this.box2DDebugRenderer = new Box2DDebugRenderer(true, true, false, true, false, true);
    this.camera = new OrthographicCamera(level.getWidth(), level.getWidth() * camera.viewportHeight / camera.viewportWidth);
    this.particlesStage.getViewport().setCamera(camera);
    this.bordersStage.getViewport().setCamera(camera);
    this.othersStage.getViewport().setCamera(camera);
    this.startColor = this.particlesStage.getBatch().getColor();
    this.xMin = level.getXMin();
    this.xMax = level.getXMax();
    this.yMin = level.getYMin();
    this.yMax = level.getYMax();
    Graphics.setCurrentCamera(camera);
    this.box2DDebugRenderer.SHAPE_AWAKE.set(0, 0, 0, 0.5f);

    GDXGameGP.currentGame.inputMultiplexer.addProcessor(this);
    GDXGameGP.currentGame.inputMultiplexer.addProcessor(new GestureDetector(this));
}
 
Example 4
Project: Entitas-Java   File: DebugRendererSystem.java   View source code 6 votes vote down vote up
public DebugRendererSystem(Entitas entitas, World world, Batch batch) {
    this.physics = world;
    this.entitas = entitas;
    this.batch = batch;

    this.shapeRenderer = new ShapeRenderer();
    this.debugRenderer = new Box2DDebugRenderer(DRAW_BOX2D_BODIES, DRAW_BOX2D_JOINTS, DRAW_BOX2D_ABBs,
            DRAW_BOX2D_INACTIVE_BODIES, DRAW_BOX2D_VELOCITIES, DRAW_BOX2D_CONTACTS);
    debugRenderer.setDrawAABBs(DRAW_BOX2D_ABBs);
    debugRenderer.setDrawBodies(DRAW_BOX2D_BODIES);
    debugRenderer.setDrawContacts(DRAW_BOX2D_CONTACTS);
    debugRenderer.setDrawInactiveBodies(DRAW_BOX2D_INACTIVE_BODIES);
    debugRenderer.setDrawJoints(DRAW_BOX2D_JOINTS);
    debugRenderer.setDrawVelocities(DRAW_BOX2D_VELOCITIES);

}
 
Example 5
Project: Entitas-Java   File: RendererSystem.java   View source code 6 votes vote down vote up
public RendererSystem(Entitas entitas, Camera cam, Batch batch, World world) {
    this.physics = world;
    this.cam = cam;
    this.batch = batch;
    this.entitas = entitas;
    _groupTextureView = entitas.game.getGroup(GameMatcher.TextureView());
    this.debugShapeRenderer = new ShapeRenderer();
    this.debugRenderer = new Box2DDebugRenderer(DRAW_BOX2D_BODIES, DRAW_BOX2D_JOINTS, DRAW_BOX2D_ABBs,
            DRAW_BOX2D_INACTIVE_BODIES, DRAW_BOX2D_VELOCITIES, DRAW_BOX2D_CONTACTS);
    debugRenderer.setDrawAABBs(DRAW_BOX2D_ABBs);
    debugRenderer.setDrawBodies(DRAW_BOX2D_BODIES);
    debugRenderer.setDrawContacts(DRAW_BOX2D_CONTACTS);
    debugRenderer.setDrawInactiveBodies(DRAW_BOX2D_INACTIVE_BODIES);
    debugRenderer.setDrawJoints(DRAW_BOX2D_JOINTS);
    debugRenderer.setDrawVelocities(DRAW_BOX2D_VELOCITIES);
    this.inputs = entitas.input.getGroup(InputMatcher.Input());
}
 
Example 6
Project: SupaBax   File: GameScreen.java   View source code 6 votes vote down vote up
/**
 * 
 */
public GameScreen(SupaBox game) {
	this.game = game;
	
	//float aspectRatio = (float) Gdx.graphics.getHeight() / (float) Gdx.graphics.getWidth();
	
	camera = new OrthographicCamera();
	viewport = new FitViewport(24, 16, camera);
	viewport.apply();
	
	camera.position.set(viewport.getWorldWidth() / 2, viewport.getWorldHeight() / 2, 0);
	
	debugRenderer = new Box2DDebugRenderer();
	world = new World(new Vector2(0, -9.8f), true);
	
	mapLoader = new TmxMapLoader();
	map = mapLoader.load("crate.tmx");
	mapRenderer = new OrthogonalTiledMapRenderer(map, 1f / SupaBox.PPM);
	
	bodyBuilder = new BodyBuilder();
	bodyBuilder.createBodies(entities, world, map);
}
 
Example 7
Project: libgdxcn   File: KinematicBodyTest.java   View source code 6 votes vote down vote up
public void create () {
	cam = new OrthographicCamera(48, 32);
	cam.position.set(0, 15, 0);
	renderer = new Box2DDebugRenderer();

	world = new World(new Vector2(0, -10), true);
	Body body = world.createBody(new BodyDef());
	CircleShape shape = new CircleShape();
	shape.setRadius(1f);
	MassData mass = new MassData();
	mass.mass = 1f;
	body.setMassData(mass);
	body.setFixedRotation(true);
	body.setType(BodyType.KinematicBody);
	body.createFixture(shape, 1);
	body.setBullet(true);
	body.setTransform(new Vector2(0, 0), body.getAngle());
	body.setLinearVelocity(new Vector2(50f, 0));
}
 
Example 8
Project: catchr   File: CatchrScreen.java   View source code 6 votes vote down vote up
public CatchrScreen(Catchr game, boolean debug)
{
	super(game);
	this.debug = debug;

	this.batch = new SpriteBatch();

	this.cam = new OrthographicCamera();
	this.cam.viewportHeight = Catchr.WINDOW_HEIGHT;
	this.cam.viewportWidth = Catchr.WINDOW_WIDTH;
	this.cam.position.set(this.cam.viewportWidth / 2, this.cam.viewportHeight / 2, 0f);

	this.board = new Board(game, this.cam, this.debug);

	this.debugRenderer = new Box2DDebugRenderer();

}
 
Example 9
Project: jastroblast   File: JastroScreen.java   View source code 6 votes vote down vote up
public JastroScreen()
{
	this.debug = JastroBlast.DEBUG;
	this.batch = new SpriteBatch();

	this.camera = new OrthographicCamera();
	this.camera.viewportHeight = JastroBlast.WINDOW_HEIGHT;
	this.camera.viewportWidth = JastroBlast.WINDOW_WIDTH;
	this.camera.position.set(this.camera.viewportWidth / 2, this.camera.viewportHeight / 2 , 0);


	this.space = new Space(this.camera, this.debug);
	this.boxDebugRenderer = new Box2DDebugRenderer();
	this.shipController = new ShipController(this.space.getShip());
	this.hud = new Hud(this.space);
}
 
Example 10
Project: GDX-Engine   File: PhysicsManager.java   View source code 5 votes vote down vote up
/**
    * Create a physics scene
    * 
    * @param gameService
    */
   public PhysicsManager(IGameService gameService) {
super(gameService);
debugRender = new Box2DDebugRenderer();
debugMatrix = new Matrix4(services.getCamera().combined);
debugMatrix.scale(BOX_TO_WORLD, BOX_TO_WORLD, 1f);
   }
 
Example 11
Project: water2d-libgdx   File: GameMain.java   View source code 5 votes vote down vote up
@Override
public void create() {
	camera = new OrthographicCamera();
	stage = new Stage(new StretchViewport(Gdx.graphics.getWidth() / 100, Gdx.graphics.getHeight() / 100, camera));

	// Create box2d world
	world = new World(new Vector2(0, -10), true);
	world.setContactListener(new MyContactListener());
	debugRenderer = new Box2DDebugRenderer();
	
	water = new Water();
	water.createBody(world, 3f, 0, 8, 2); //world, x, y, width, height
	//water.setDebugMode(true);
}
 
Example 12
Project: summer17-android   File: PlayScreen.java   View source code 5 votes vote down vote up
public PlayScreen(NoObjectionGame game) {
    atlas = new TextureAtlas("dudestuff3.pack");

    this.game = game;
    bg = new Texture("main_background.png");
    gameCam = new OrthographicCamera();
    gamePort = new FitViewport(NoObjectionGame.V_WIDTH / NoObjectionGame.PPM, NoObjectionGame.V_HEIGHT / NoObjectionGame.PPM, gameCam);
    hud = new Hud(game.batch);

    maploader = new TmxMapLoader();
    map = maploader.load("map1.tmx");
    renderer = new OrthoCachedTiledMapRenderer(map, 1 / NoObjectionGame.PPM);
    gameCam.position.set(gamePort.getWorldWidth() / 2, gamePort.getWorldHeight() / 2, 0);

    world = new World(new Vector2(0, -10), true);
    b2dr = new Box2DDebugRenderer();

    new B2WorldCreator(world, map);
    hero = new Hero(world, this);
    controller = new Controller();
    worldContactListener = new WorldContactListener();
    world.setContactListener(worldContactListener);

    //timer
    sb = new SpriteBatch();
    viewport = new FitViewport(NoObjectionGame.V_WIDTH, NoObjectionGame.V_HEIGHT, new OrthographicCamera());
    stage = new Stage(viewport, sb);
    table = new Table();
    table.top();
    table.setFillParent(true);
    countDownLabel = new Label(Float.toString(playTime), new Label.LabelStyle(new BitmapFont(), Color.WHITE));
    table.add(countDownLabel).expandX();
    stage.addActor(table);


}
 
Example 13
Project: libGdx-xiyou   File: Play.java   View source code 5 votes vote down vote up
private void init() {

		//初始化世界 初始化重力
		mWorld = new World(new Vector2(0, -9.8f), true);

		//初始化刚体世界相机
		mBox2DCamera = new OrthographicCamera();
		mBox2DCamera.setToOrtho(false, MyGdxGame.VIEW_WIDTH / Constant.RATE, MyGdxGame.VIEW_HEIGHT / Constant.RATE);

		//初始化Box2D渲染器
		mBox2DRender = new Box2DDebugRenderer();

		//初始化蟠桃与蓝瓶
		mTaos = new Array<Tao>();
		mBlues = new Array<Blue>();

		//创建地图
		createMap();

		//创建天兵
		createEnemy();

		//创建Boss
		createBoss(level);

		//创建主角
		createActor();

		//初始化所有控件
		initWidget();

		//初始化孙悟空所有按钮的监听事件
		initListener();

		//注册碰撞监听事件
		mContactListener = new Box2DContactListener();
		mWorld.setContactListener(mContactListener);
	}
 
Example 14
Project: fluffybalance   File: Balanceball.java   View source code 5 votes vote down vote up
private void initDebugRenderer() {
    if (!DEBUG_RENDERER) {
        return;
    }

    mDebugRenderer = new Box2DDebugRenderer();
    mDebugFont = new BitmapFont();

    mDebugTextLayout = new GlyphLayout(mDebugFont, "test");
}
 
Example 15
Project: Undertailor   File: CollisionHandler.java   View source code 5 votes vote down vote up
public CollisionHandler(OverworldCamera ovwCam, boolean renderCollision) {
    this.overworldCam = ovwCam;
    this.rendererCam = new OrthographicCamera(640, 480);
    this.rendererCam.zoom = 1 / OverworldController.METERS_TO_PIXELS;
    this.destroyed = false;
    this.reset();

    this.renderer = new Box2DDebugRenderer(true, true, false, true, false, true);
}
 
Example 16
Project: joe   File: Driver.java   View source code 5 votes vote down vote up
public Driver(Game game) {
    debugMatrix = new Matrix4();
    debugRenderer = new Box2DDebugRenderer();

    spriteBatch = new SpriteBatch();

    Gdx.app.setLogLevel(Globals.LOG_LEVEL);
}
 
Example 17
Project: advio   File: GameScreen.java   View source code 5 votes vote down vote up
public GameScreen(Level LEVEL_BEGINNER, boolean preview) {
	this.preview = preview;
	Gdx.input.setInputProcessor(Advio.instance.console);
	this.camera = new OrthographicCamera(1280, 720);
	batch = new SpriteBatch();
	cameraBatch = new SpriteBatch();
	shapes = new ShapeRenderer();
	shapes.setColor(0, 0, 0, 1);
	this.level = LEVEL_BEGINNER;
	debug = new Box2DDebugRenderer(true, true, true, true, true, true);
}
 
Example 18
Project: fabulae   File: GameMap.java   View source code 5 votes vote down vote up
private void init() {
	tempVector = new Vector3();
	tempSet = new ObjectSet<GameObject>();
	s_sunlightMultiplier = 1f;
	drawables = new Array<Drawable>();
	blockers = new Array<TileBlocker>();
	textDrawers = new Array<TextDrawer>();
	myAssets = new AssetMap();
	gameObjects = new Array<GameObject>(true, 16, GameObject.class);
	gameObjectsByType = new ObjectMap<String, Array<GameObject>>();
	gameObjectsByClass = new ObjectMap<Class<?>, Array<GameObject>>();
	locations =  new Array<GameLocation>();
	tempLocations =  new ObjectSet<GameLocation>();
	traps = new ObjectMap<TrapLocation, FilledPolygonRenderer>();
	groundLayers = new Array<TiledMapTileLayer>();
	overheadLayers = new Array<TiledMapTileLayer>();
	alwaysAboveLayers = new Array<TiledMapTileLayer>();
	transitionTiles = new ObjectMap<Vector2, Transition>();
	shapeDrawers = new Array<ShapeDrawer>();
	weatherProfileModifiers = new Array<WeatherProfile>();
	transitionLocks = new Array<TransitionLock>();
	transitionTraps = new Array<TransitionTrap>();
	mapTileObjects = new Array<TiledMapObject>(); 
	renderGrid = false;
	isDisposed = false;
	tweenManager = new TweenManager();
	unpausableTweenManager = new TweenManager();
	
	RayHandler.useDiffuseLight(true);
	
	fogOfWarWorld = new World(new Vector2(0, 0), true);
	lightsWorld =  new World(new Vector2(0, 0), true);
	box2DDebugRenderer = new Box2DDebugRenderer(true, true, true, true, true, true);
	createFogOfWarRayHandler();
	createLightsRayHandler();
	createViewConesRayHandler();
	mapLoaded = false;
	super.setMap(null);
}
 
Example 19
Project: libgdxGP   File: LevelScreen.java   View source code 5 votes vote down vote up
public LevelScreen(Level level, float w, float h) {
    this.level = level;
    this.box2DDebugRenderer = new Box2DDebugRenderer(true, true, false, true, true, true);
    this.camera = new OrthographicCamera(1f, 1f * h / w);
    this.particlesStage = new Stage();
    this.particlesStage.getViewport().setCamera(camera);
    this.bordersStage = new Stage();
    this.bordersStage.getViewport().setCamera(camera);
    this.othersStage = new Stage();
    this.othersStage.getViewport().setCamera(camera);
    this.startColor = this.particlesStage.getBatch().getColor();
}
 
Example 20
Project: puffin   File: GameStage.java   View source code 5 votes vote down vote up
public GameStage(Game game) {
    this.game = game;
    setUpWorld();
    setupCamera();
    setupTouchControlAreas();
    renderer = new Box2DDebugRenderer();
    sb = new SpriteBatch();
    background = new Sprite(new Texture("background1.png"));
    wasted = new Sprite(new Texture("wasted.gif"));
    wastedGray = new Sprite(new Texture("stage.png"));
}
 
Example 21
Project: BlockBunny   File: Menu.java   View source code 5 votes vote down vote up
public Menu(GameStateManager gsm) {

        super(gsm);

        Texture tex = Game.res.getTexture("menu");
        bg = new Background(new TextureRegion(tex), cam, 1f);
        bg.setVector(-20, 0);

        tex = Game.res.getTexture("bunny");
        TextureRegion[] reg = new TextureRegion[4];
        for (int i = 0; i < reg.length; i++) {
            reg[i] = new TextureRegion(tex, i * 32, 0, 32, 32);
        }
        animation = new Animation(reg, 1 / 12f);

        tex = Game.res.getTexture("hud");
        playButton = new GameButton(new TextureRegion(tex, 0, 34, 58, 27), 160, 100, cam);

        cam.setToOrtho(false, Game.V_WIDTH, Game.V_HEIGHT);

        world = new World(new Vector2(0, -9.8f * 5), true);
        //world = new World(new Vector2(0, 0), true);
        b2dRenderer = new Box2DDebugRenderer();

        createTitleBodies();

    }
 
Example 22
Project: tabox2d   File: Tabox2D.java   View source code 5 votes vote down vote up
private Tabox2D(Vector2 gravity) {
    width = Gdx.graphics.getWidth();
    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();
}
 
Example 23
Project: jumpdontdie   File: Box2DScreen.java   View source code 5 votes vote down vote up
@Override
public void show() {
    // Create the world. We give it some gravity that is similar to the one used in the earth.
    // Box2D, like any other physics system in this world, treats Y coordinates upwards. Thus,
    // by using y = -10, we make gravity go down. If you look at your physics book, it is
    // the same.
    world = new World(new Vector2(0, -10), true);

    // Create a renderer and a camera to make it possible for us to see what is in the world.
    renderer = new Box2DDebugRenderer();
    camera = new OrthographicCamera(16, 9);
    camera.translate(0, 1);

    // Create the bodies for entities in this world.
    minijoeBody = world.createBody(BodyDefFactory.createPlayer());
    floorBody = world.createBody(BodyDefFactory.createFloor());
    spikeBody = world.createBody(BodyDefFactory.createSpikes(6f));

    // Create the fixture for the entities in this world.
    minijoeFixture = FixtureFactory.createPlayerFixture(minijoeBody);
    floorFixture = FixtureFactory.createFloorFixture(floorBody);
    spikeFixture = FixtureFactory.createSpikeFixture(spikeBody);

    // Set the user data to some categories that will let us handle collisions in a more
    // generic way. Player can collide with floor and with spike.
    minijoeFixture.setUserData("player");
    floorFixture.setUserData("floor");
    spikeFixture.setUserData("spike");

    // Set the contact listener for this world. The contact listener will handle contacts.
    world.setContactListener(new Box2DScreenContactListener());
}
 
Example 24
Project: KillTheNerd   File: PlayRenderer.java   View source code 5 votes vote down vote up
/**
 * @param level
 * @param worldController
 */
public PlayRenderer(final AbstractLevel level, final WorldController worldController) {
	this.b2World = worldController.getB2World();
	this.worldController = worldController;
	this.level = level;
	this.level.init();

	// Gdx.graphics.getWidth() gets the width defined in DesktopLauncher.java
	// final float width = Gdx.graphics.getWidth();
	// final float height = Gdx.graphics.getHeight();
	// this.camera = new OrthographicCamera(width, height * (height / width));
	// this.camera = new OrthographicCamera(width, height * (height / width));
	this.debugRenderer = new Box2DDebugRenderer();
	this.victory = Assets.getInstance().findRegion("victory_basic");
	this.victory.flip(false, true);

	this.score = new Scoreboard();
	this.hudElements.add(new WeaponDisplay(this.level.getPlayer1()));
	// camera
	this.camera = new OrthographicCamera(Constants.VIEWPORT_WIDTH_IN_METER, Constants.VIEWPORT_HEIGHT_IN_METER);
	this.camera.position.set(0, 0, 0);
	this.camera.update();

	// GUI camera
	this.cameraGUI = new OrthographicCamera();
	this.cameraGUI.setToOrtho(true, Constants.SCREEN_WIDTH_IN_PIXEL, Constants.SCREEN_HEIGHT_IN_PIXEL); // flip y
	this.cameraGUI.update();

	// b2d camera - collision debugger - Box2D - view is for example 10x17.78 meters
	this.cameraB2D = new OrthographicCamera(Constants.VIEWPORT_WIDTH_IN_METER, Constants.VIEWPORT_HEIGHT_IN_METER);
	// this.b2dCamera.position.set(0, 0, 0);
	// this.b2dCamera.update();

	this.batch = new SpriteBatch();

	this.backgroundSprite = new Sprite(AssetStore.background);
	this.backgroundSprite.setSize(1, 1);
}
 
Example 25
Project: Pong-Tutorial   File: gameScreen.java   View source code 5 votes vote down vote up
public gameScreen(final Pong g, boolean multiplayer){
	float screenWidth = 800;
	float screenHeight = 400;
	float gameWidth = 203;
	float gameHeight = screenHeight / (screenWidth / gameWidth);
	
	camera = new OrthographicCamera(gameWidth/10, gameHeight/10);
	camera2 = new OrthographicCamera(gameWidth*1.5f, gameHeight*1.5f);
	world = new World(new Vector2(0, 0), true);
	debugRenderer = new Box2DDebugRenderer();
	batch = new SpriteBatch();
	shapeRenderer = new ShapeRenderer();
	layout = new GlyphLayout();
	preferences = Gdx.app.getPreferences("pong");
	this.multiplayer = multiplayer;
	angle = 0;
	force = 800;
	scoreP1 = 0;
	scoreP2 = 0;
	scored = 0;
	end = false;
	paused = false;
	
	initObjects();
	initAssets();
	
	Gdx.input.setInputProcessor(new InputHandler(g, this, gameWidth/10, gameHeight/10));
	createCollisionListener();
}
 
Example 26
Project: Pong-Tutorial   File: onlineScreen.java   View source code 5 votes vote down vote up
public onlineScreen(Pong game, int init_side){

        this.game = game;

		float screenWidth = 800;
		float screenHeight = 400;
		float gameWidth = 203;
		float gameHeight = screenHeight / (screenWidth / gameWidth);

		camera = new OrthographicCamera(gameWidth/10, gameHeight/10);
		camera2 = new OrthographicCamera(gameWidth*1.5f, gameHeight*1.5f);
		world = new World(new Vector2(0, 0), true);
		debugRenderer = new Box2DDebugRenderer();
		batch = new SpriteBatch();
		shapeRenderer = new ShapeRenderer();
		layout = new GlyphLayout();

		angle = 0;
		force = 800;
		scoreP1 = 0;
		scoreP2 = 0;
		scored = 0;
		end = false;
        side = init_side;

		initObjects();
		initAssets();

		if(side == 0 && !started){
			ball.getBody().applyForce(800f,100f,0,0,true);
			started = true;
		}else if(side == 1 && !started){
			ball.getBody().applyForce(-800f,100f,0,0,true);
			started = true;
		}

		Gdx.input.setInputProcessor(new InputOnlineHandler(game, this, side, gameWidth / 10, gameHeight / 10));
		createCollisionListener();
    }
 
Example 27
Project: Pong-Tutorial   File: gameWallScreen.java   View source code 5 votes vote down vote up
public gameWallScreen(final Pong g, boolean multiplayer){
float screenWidth = 800;
float screenHeight = 400;
float gameWidth = 203;
float gameHeight = screenHeight / (screenWidth / gameWidth);

camera = new OrthographicCamera(gameWidth/10, gameHeight/10);
camera2 = new OrthographicCamera(gameWidth*1.5f, gameHeight*1.5f);
      camera3 = new OrthographicCamera(gameWidth*3f, gameHeight*3f);

      world = new World(new Vector2(0, 0), true);
debugRenderer = new Box2DDebugRenderer();
batch = new SpriteBatch();
      batch2 = new SpriteBatch();
shapeRenderer = new ShapeRenderer();
layout = new GlyphLayout();

angle = 0;
force = 800;
score = 0;
scored = 0;
end = false;
paused = false;

preferences = Gdx.app.getPreferences("pong");
highscore = preferences.getInteger("highscore", 0);

initObjects();
initAssets();

Gdx.input.setInputProcessor(new InputHandlerWall(g, this, gameWidth/10, gameHeight/10));
createCollisionListener();
  }
 
Example 28
Project: GDXJam   File: PhysicsSystem.java   View source code 5 votes vote down vote up
@Override
public void addedToEngine(Engine engine) {
	super.addedToEngine(engine);
	this.camera = engine.getSystem(CameraSystem.class).getCamera();
	renderer = new Box2DDebugRenderer();

}
 
Example 29
Project: libgdx_mario   File: PlayScreen.java   View source code 5 votes vote down vote up
public PlayScreen(MarioBros game) {
    this.game = game;
    gameCam = new OrthographicCamera();
    gamePort = new FitViewport(MarioBros.V_WIDTH / MarioBros.PPM, MarioBros.V_HEIGHT / MarioBros.PPM, gameCam);
    hud = new Hud(game.batch);
    mapLoader = new TmxMapLoader();
    map = mapLoader.load("level1.tmx");
    atlas = new TextureAtlas("Mario_and_Enemies.pack");
    renderer = new OrthogonalTiledMapRenderer(map, 1 / MarioBros.PPM);

    //set gamecam to the center at the start of the game
    gameCam.position.set(gamePort.getWorldWidth() / 2, gamePort.getWorldHeight() / 2, 0);

    world = new World(new Vector2(0, -10), true);
    b2dr = new Box2DDebugRenderer();

    creator = new B2WorldCreator(this);
    player = new Mario(this);

    world.setContactListener(new WorldContactListener());

    music = MarioBros.manager.get("audio/music/mario_music.ogg", Music.class);
    music.setLooping(true);
    music.play();

    items = new Array<Item>();
    itemsToSpawn = new LinkedBlockingQueue<ItemDef>();
}
 
Example 30
Project: sioncore   File: RenderingSystem.java   View source code 5 votes vote down vote up
public RenderingSystem() {
	super();
	
	this.sortedEntities = new Array<Entity>(100);
	this.batch = new SpriteBatch();
	this.camera = Env.game.getCamera();
	this.viewport = Env.game.getViewport();
	this.uiCamera = Env.game.getUICamera();
	this.uiViewport = Env.game.getUIViewport();
	this.sorter = new DepthSorter();
	this.shapeRenderer = new ShapeRenderer();
	this.box2DRenderer = new Box2DDebugRenderer(Env.drawBodies,
												Env.drawJoints,
												Env.drawABBs,
												Env.drawInactiveBodies,
												Env.drawVelocities,
												Env.drawContacts);
	
	this.particleFrameBuffer = new FrameBuffer(Pixmap.Format.RGBA8888, Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), false);
	this.particleRegion = new TextureRegion(particleFrameBuffer.getColorBufferTexture());
	this.particleRegion.flip(false, true);
	
	this.skeletonRenderer = new SkeletonRenderer();
	
	if (Env.debug) {
		debugFont = Env.game.getAssets().get("data/ui/default.fnt", BitmapFont.class);
	}
}
 
Example 31
Project: Little-Nibolas   File: PantallaActual.java   View source code 5 votes vote down vote up
public PantallaActual(LittleNibolas game){
	
	this.game = game;
	
	float screenWidth = 980;
	float screenHeight = 720;
	float gameWidth = 203;
	float gameHeight = screenHeight / (screenWidth / gameWidth);
	
	inc = 0;
	score = 0;
	hide = false;
	pantalla = this;
	world = new World(new Vector2(0, -9.81f), true);
	debugRenderer = new Box2DDebugRenderer();
	batch = new SpriteBatch();
	batch2 = new SpriteBatch();
	lastBin = -1;
	stop = false;
	
	camera = new OrthographicCamera(gameWidth/15, gameHeight/15);
	camera2 = new OrthographicCamera(gameWidth, gameHeight);
	
	groundPos = -2;
	
	initObjects();
	initAssets();
	
	Gdx.input.setInputProcessor(new InputHandler(this,gameWidth/10,gameHeight/10));
	createCollisionListener();
}
 
Example 32
Project: Little-Nibolas   File: PantallaActual.java   View source code 5 votes vote down vote up
public PantallaActual(){
	
	float screenWidth = 980;
	float screenHeight = 720;
	float gameWidth = 203;
	float gameHeight = screenHeight / (screenWidth / gameWidth);
	
	runTime = 0;
	hide = false;
	insideBin = false;
	pantalla = this;
	world = new World(new Vector2(0, -9.81f), true);
	debugRenderer = new Box2DDebugRenderer();
	shapeRenderer = new ShapeRenderer();
	batch = new SpriteBatch();
	lastBin = -1;
	stop = false;
	
	camera = new OrthographicCamera(gameWidth/10, gameHeight/10);
	
	groundPos = -3;
	
	initObjects();
	initAssets();
	
	Gdx.input.setInputProcessor(new InputHandler(this,gameWidth/10,gameHeight/10));
	createCollisionListener();
}
 
Example 33
Project: libgdxcn   File: Box2DTest.java   View source code 5 votes vote down vote up
@Override
public void create () {
	// setup the camera. In Box2D we operate on a
	// meter scale, pixels won't do it. So we use
	// an orthographic camera with a viewport of
	// 48 meters in width and 32 meters in height.
	// We also position the camera so that it
	// looks at (0,16) (that's where the middle of the
	// screen will be located).
	camera = new OrthographicCamera(48, 32);
	camera.position.set(0, 15, 0);

	// create the debug renderer
	renderer = new Box2DDebugRenderer();

	// create the world
	world = new World(new Vector2(0, -10), true);

	// we also need an invisible zero size ground body
	// to which we can connect the mouse joint
	BodyDef bodyDef = new BodyDef();
	groundBody = world.createBody(bodyDef);

	// call abstract method to populate the world
	createWorld(world);

	batch = new SpriteBatch();
	font = new BitmapFont(Gdx.files.internal("data/arial-15.fnt"), false);
}
 
Example 34
Project: libgdxcn   File: Box2DCharacterControllerTest.java   View source code 5 votes vote down vote up
@Override
public void create () {
	world = new World(new Vector2(0, -40), true);
	renderer = new Box2DDebugRenderer();
	cam = new OrthographicCamera(28, 20);
	createWorld();
	Gdx.input.setInputProcessor(this);
	batch = new SpriteBatch();
	font = new BitmapFont(Gdx.files.internal("data/arial-15.fnt"), false);
}
 
Example 35
Project: libgdxcn   File: Box2DTest.java   View source code 5 votes vote down vote up
@Override
public void create () {
	// setup the camera. In Box2D we operate on a
	// meter scale, pixels won't do it. So we use
	// an orthographic camera with a viewport of
	// 48 meters in width and 32 meters in height.
	// We also position the camera so that it
	// looks at (0,16) (that's where the middle of the
	// screen will be located).
	camera = new OrthographicCamera(48, 32);
	camera.position.set(0, 16, 0);

	// next we setup the immediate mode renderer
	renderer = new ShapeRenderer();

	// next we create the box2d debug renderer
	debugRenderer = new Box2DDebugRenderer();

	// next we create a SpriteBatch and a font
	batch = new SpriteBatch();
	font = new BitmapFont(Gdx.files.internal("data/arial-15.fnt"), false);
	font.setColor(Color.RED);
	textureRegion = new TextureRegion(new Texture(Gdx.files.internal("data/badlogicsmall.jpg")));

	// next we create out physics world.
	createPhysicsWorld();

	// register ourselfs as an InputProcessor
	Gdx.input.setInputProcessor(this);
}
 
Example 36
Project: libgdx   File: MyWorld.java   View source code 5 votes vote down vote up
@Override
public void create() {
	// C�mara del juego
	camera = new OrthographicCamera();
	// Zona visible de la c�mara
	camera.viewportWidth = 480;
	camera.viewportHeight = 320;
	// Colca la c�mara en el centro de la pantalla
	camera.position.set(camera.viewportWidth / 2, camera.viewportHeight / 2, 0f);
	camera.update();
	
	spriteBatch = new SpriteBatch();
	font = new BitmapFont();
	
	world = new World(new Vector2(0, -WorldGenerator.GRAVITY), true);
	renderer = new Box2DDebugRenderer();
	
	// Define un cuerpo (la tierra)
	BodyDef groundDef = new BodyDef();
	groundDef.type = BodyType.StaticBody;
	groundDef.position.set(new Vector2(0, 10));
	Body groundBody= world.createBody(groundDef);
	PolygonShape groundShape = new PolygonShape();
	groundShape.setAsBox(camera.viewportWidth * 2, 10.0f);
	groundBody.createFixture(groundShape, 0.0f);
	
	// A�ade dos cuerpos circulares al mundo
	Body circle1 = WorldGenerator.createCircleBody(world, 100, 100);
	Body circle2 = WorldGenerator.createCircleBody(world, 105, 120);
	// A�ade un cuerpo con forma de caja al mundo
	Body box = WorldGenerator.createBoxBody(world, 101, 140);
}
 
Example 37
Project: fluid-simulator-v2   File: FluidSimulatorGeneric.java   View source code 5 votes vote down vote up
public FluidSimulatorGeneric(FluidSimulatorStarter fluidSimulatorStarter) {
		this.game = fluidSimulatorStarter;
		// LibGDX single batches cannot have a size more than 5460
		batch = new SpriteBatch(IS_DESKTOP ? 5460 : ANDROID_SIZE);
		font = new BitmapFont();
		camera = new OrthographicCamera(WORLD_WIDTH, WORLD_HEIGHT);
		camera.position.set(0, (WORLD_HEIGHT / 2) - 1, 0);
		immediateRenderer = new ImmediateModeRenderer20(SIZE*6, false, true, 0);
		irt = new Renderer20(SIZE*6, false, true, 1);
		irt2 = new ImmediateModeRenderer20(SIZE*11, false, true, 1);
		shapeRenderer = new ShapeRenderer(SIZE);
		renderer = new Box2DDebugRenderer(true, true, false, true, false, false);
		
		//3D
		camera3D = new PerspectiveCamera(67, WORLD_WIDTH, WORLD_HEIGHT);
		camera3D.position.set(0, 130f, 250f);
		camera3D.lookAt(0,150f,0);
		camera3D.near = 0.1f;
		camera3D.far = 500f;
		camera3D.update();
		ModelBuilder modelBuilder = new ModelBuilder();
//        model = modelBuilder.createSphere(5f, 5f, 5f, 4, 4, GL10.GL_TRIANGLES,
//                new Material(ColorAttribute.createDiffuse(Color.GREEN)),
//                Usage.Position | Usage.Normal);
        model = modelBuilder.createBox(5f, 5f, 5f,
            new Material(ColorAttribute.createDiffuse(Color.GREEN)),
            Usage.Position | Usage.Normal);
        instance = new ModelInstance(model);
        modelBatch = new ModelBatch();
        environment = new Environment();
        environment.set(new ColorAttribute(ColorAttribute.AmbientLight, 0.4f, 0.4f, 0.4f, 1f));
        environment.add(new DirectionalLight().set(0.8f, 0.8f, 0.8f, 0, -0.8f, -0.2f));
        camController = new Camera3DController(camera3D);
        camController.setFluidSimulator(this);
		
		world = new World(new Vector2(0, -9.8f), false);
		world.setContactListener(this);
	}
 
Example 38
Project: GDX-Logic-Bricks   File: RenderingSystem.java   View source code 5 votes vote down vote up
public RenderingSystem() {
    super(Family.all(ViewsComponent.class).get(), 5);
    vm = ComponentMapper.getFor(ViewsComponent.class);
    setProcessing(false);
    renderQueue = new Array<View>();
    comparator = new Comparator<View>() {
        @Override
        public int compare(View viewA, View viewB) {
            return (int) Math.signum(viewA.layer - viewB.layer);
        }
    };


    if (Settings.DRAW_GRID) {
        this.debugShapeRenderer = new ShapeRenderer();
    }
    if (Settings.DEBUG && !Settings.TESTING) {
        this.debugRenderer = new Box2DDebugRenderer(Settings.DRAW_BOX2D_BODIES, Settings.DRAW_BOX2D_JOINTS, Settings.DRAW_BOX2D_ABBs,
                Settings.DRAW_BOX2D_INACTIVE_BODIES, Settings.DRAW_BOX2D_VELOCITIES, Settings.DRAW_BOX2D_CONTACTS);
        debugRenderer.setDrawAABBs(Settings.DRAW_BOX2D_ABBs);
        debugRenderer.setDrawBodies(Settings.DRAW_BOX2D_BODIES);
        debugRenderer.setDrawContacts(Settings.DRAW_BOX2D_CONTACTS);
        debugRenderer.setDrawInactiveBodies(Settings.DRAW_BOX2D_INACTIVE_BODIES);
        debugRenderer.setDrawJoints(Settings.DRAW_BOX2D_JOINTS);
        debugRenderer.setDrawVelocities(Settings.DRAW_BOX2D_VELOCITIES);

        debugFont = new BitmapFont();
        debugFont.setUseIntegerPositions(false);
        debugFont.getData().setScale(0.1f);
        uiCamera = new OrthographicCamera();

    }

}
 
Example 39
Project: gdx-combat   File: GameScene.java   View source code 5 votes vote down vote up
public GameScene(AbstractArena arena, AbstractFighter player, AbstractFighter enemy) {
	this.arena = arena;
	this.player = player;
	this.enemy = enemy;

	world = new World(new Vector2(0, -20), true);

	camera = Touch.getCamera();

	Matrix4 hudMatrix = new Matrix4();
	hudMatrix.setToOrtho2D(0, 0, 480, 320);
	hudBatch = new SpriteBatch();
	hudBatch.setProjectionMatrix(hudMatrix);

	fightTextAnim = new Animation(0.03f, AnimationUtils.loadAnim(Assets.getTextureAtlas(), "fight", 21));
	startTime = System.currentTimeMillis();

	player.setPosition(30, 150 - player.getHeight());
	enemy.setPosition(350, 150 - enemy.getHeight());

	player.setGroundLevel(arena.getGroundLevel());
	enemy.setGroundLevel(arena.getGroundLevel());

	player.setOponent(enemy);
	enemy.setOponent(player);

	enemy.initAi(new RandomBot());

	arena.initPhys(world);
	player.initPhys(world);
	enemy.initPhys(world);

	createHUD();

	debugRenderer = new Box2DDebugRenderer();
	box2dRenderMatrix = new Matrix4();

	Assets.fight.play();
}
 
Example 40
Project: QwikGDX   File: Box2dScreen.java   View source code 5 votes vote down vote up
@Override
public void show() {
	debugRenderer = new Box2DDebugRenderer();
	camera = new OrthographicCamera();
	camera.setToOrtho(false, Gdx.graphics.getWidth(),
			Gdx.graphics.getHeight());
}