当前位置: 首页>>代码示例>>Java>>正文


Java World.setContactListener方法代码示例

本文整理汇总了Java中com.badlogic.gdx.physics.box2d.World.setContactListener方法的典型用法代码示例。如果您正苦于以下问题:Java World.setContactListener方法的具体用法?Java World.setContactListener怎么用?Java World.setContactListener使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.badlogic.gdx.physics.box2d.World的用法示例。


在下文中一共展示了World.setContactListener方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: GameScreen

import com.badlogic.gdx.physics.box2d.World; //导入方法依赖的package包/类
/**
 * Create the screen. Since this constructor cannot be invoked before libGDX is fully started,
 * it is safe to do critical code here such as loading assets and setting up the stage.
 * @param game
 */
public GameScreen(es.danirod.jddprototype.game.MainGame game) {
    super(game);

    // Create a new Scene2D stage for displaying things.
    stage = new Stage(new FitViewport(640, 360));
    position = new Vector3(stage.getCamera().position);

    // Create a new Box2D world for managing things.
    world = new World(new Vector2(0, -10), true);
    world.setContactListener(new GameContactListener());

    // Get the sound effect references that will play during the game.
    jumpSound = game.getManager().get("audio/jump.ogg");
    dieSound = game.getManager().get("audio/die.ogg");
    backgroundMusic = game.getManager().get("audio/song.ogg");
}
 
开发者ID:danirod,项目名称:jumpdontdie,代码行数:22,代码来源:GameScreen.java

示例2: create

import com.badlogic.gdx.physics.box2d.World; //导入方法依赖的package包/类
@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);
}
 
开发者ID:jocasolo,项目名称:water2d-libgdx,代码行数:15,代码来源:GameMain.java

示例3: PlayScreen

import com.badlogic.gdx.physics.box2d.World; //导入方法依赖的package包/类
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);


}
 
开发者ID:MissionBit,项目名称:summer17-android,代码行数:37,代码来源:PlayScreen.java

示例4: init

import com.badlogic.gdx.physics.box2d.World; //导入方法依赖的package包/类
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);
	}
 
开发者ID:heyzqt,项目名称:libGdx-xiyou,代码行数:39,代码来源:Play.java

示例5: PlayScreen

import com.badlogic.gdx.physics.box2d.World; //导入方法依赖的package包/类
public PlayScreen(QuackHack game) {
	this.game = game;
	gamecam = new OrthographicCamera();
	gamePort = new ExtendViewport(QuackHack.V_WIDTH * 4 / QuackHack.PPM, QuackHack.V_HEIGHT * 4 / QuackHack.PPM, gamecam);
	hud = new Hud(game);
	maploader = new TmxMapLoader();

	map = maploader.load("Tunnelv0.tmx");
	renderer = new OrthogonalTiledMapRenderer(map, 1 / QuackHack.PPM);
       gameMusic = Gdx.audio.newMusic(Gdx.files.internal("Airborn.wav"));
       gameMusic.setLooping(true);
       gameMusic.play();

	gamecam.position.set(gamePort.getMinWorldWidth() / 2, gamePort.getMinWorldHeight() / 2, 0);
	world = new World(new Vector2(0, -100), true);
	//b2dr = new Box2DDebugRenderer();
	new B2WorldCreator(world, map, this);
	world.setContactListener(new WorldContactListener());
	game.getServer().registerNetListener(this);

       rayHandler = rayHandlerGenerator();

	for(Connection c: game.getServer().getPlayers()) {
		System.out.println("New Player! id: "+game.getServer().getPlayerType(c.getID()).toString());
		players.put(c.getID(), new Player(c.getID(), world, this, game.getServer().getPlayerType(c.getID())));
	}
	game.getServer().sendCommand(NetCommand.PLAYER_JOIN);

       //http://www.badlogicgames.com/forum/viewtopic.php?f=17&t=1795
       rbg = new ParallaxBackground(new ParallaxLayer[]{
               new ParallaxLayer(new TextureRegion(new Texture(Gdx.files.internal("blue_grass.png"))),new Vector2(0.5f, 0.5f),new Vector2(0, 300)),
               //new ParallaxLayer(atlas.findRegion("bg2"),new Vector2(1.0f,1.0f),new Vector2(0, 500)),
       }, 800, 480,new Vector2(150,0));

}
 
开发者ID:edwardszczepanski,项目名称:QuackHack,代码行数:36,代码来源:PlayScreen.java

示例6: CGCWorld

import com.badlogic.gdx.physics.box2d.World; //导入方法依赖的package包/类
public CGCWorld(ChaseApp app, int numPlayers, boolean tutorial)
{
	super(app);
	TimerManager.start();
	TimerManager.setPause(false);
	
	terminated = false;
	gameLost = false;
	gameWon = false;
	bossFight = false;
	this.tutorial = tutorial;
	
	shapes = app.getShapes();
	toDestroyList = new Array<GameEntity>();
	
	world = new World(new Vector2(0, 0), true);
	bf = new BodyFactory(world);
	lh = new LayerHandler();
	
	cm = new ContactManager();
	players = new Array<Player>();
	CGCWorld.numPlayers = numPlayers;
	numCops = 0;
	numPrisoners = 0;
	recentlyDeceased = new Array<Player>();
	patcher = new Patcher();
	random = new Random();
	paused = false;
	pauseMenu = new PauseMenu(sBatch, this, myApp, this);
	pauseMenu.setShow(false);
	world.setContactListener(cm);
	gameTime = 0;
	
	createHeli = false;
	respawnHeight = 0.0f;
	Prisoner.resetDistRun();
	RookieCop.resetDistRun();
	setTimersAndTasks();
}
 
开发者ID:ChainGangChase,项目名称:cgc-game,代码行数:40,代码来源:CGCWorld.java

示例7: Level

import com.badlogic.gdx.physics.box2d.World; //导入方法依赖的package包/类
private Level() {
    entityMap = new ConcurrentHashMap<String, Entity>();
    scriptMap = new ConcurrentHashMap<String, Script>();

    respawnPosition = new Vector2();

    World.setVelocityThreshold(0.5f);
    physicsWorld = new World(new Vector2(0, DEFAULT_GRAVITY), true);
    physicsWorld.setContactListener(CollisionListener.getInstance());
}
 
开发者ID:alexschimpf,项目名称:joe,代码行数:11,代码来源:Level.java

示例8: create

import com.badlogic.gdx.physics.box2d.World; //导入方法依赖的package包/类
/** Call this method to (re)create Box2D world according to current settings. */
public void create() {
    dispose();
    gridService.createGrid();
    world = new World(GRAVITY, true);
    createGameBounds();
    createPlayers();
    createBlocks();
    world.setContactListener(contactService);
}
 
开发者ID:BialJam,项目名称:M-M,代码行数:11,代码来源:Box2DService.java

示例9: createWorld

import com.badlogic.gdx.physics.box2d.World; //导入方法依赖的package包/类
World createWorld() {
    Vector2 gravity = new Vector2(0.0f, -1.0f);
    boolean doSleep = true;
    World newWorld = new World(gravity, doSleep);
    newWorld.setContactListener(this);
    return newWorld;
}
 
开发者ID:dozingcat,项目名称:Vector-Pinball-Editor,代码行数:8,代码来源:Field.java

示例10: show

import com.badlogic.gdx.physics.box2d.World; //导入方法依赖的package包/类
@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());
}
 
开发者ID:danirod,项目名称:jumpdontdie,代码行数:33,代码来源:Box2DScreen.java

示例11: PlayScreen

import com.badlogic.gdx.physics.box2d.World; //导入方法依赖的package包/类
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>();
}
 
开发者ID:lbalmaceda,项目名称:libgdx_mario,代码行数:29,代码来源:PlayScreen.java

示例12: PhysicsSystem

import com.badlogic.gdx.physics.box2d.World; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public PhysicsSystem(){
	super(Family.all(PhysicsComponent.class).get());
	logger.debug("initializing");
	world = new World(new Vector2(0,gravity),true);
	world.setContactListener(this);
}
 
开发者ID:Deftwun,项目名称:ZombieCopter,代码行数:8,代码来源:PhysicsSystem.java

示例13: resetForLevel

import com.badlogic.gdx.physics.box2d.World; //导入方法依赖的package包/类
/**
 * Creates Box2D world, reads layout definitions for the given level, and initializes the game
 * to the starting state.
 */
public void resetForLevel(Context context, int level) {
    Vector2 gravity = new Vector2(0.0f, -1.0f);
    boolean doSleep = true;
    world = new World(gravity, doSleep);
    world.setContactListener(this);

    gameState.statusMgr = LocalBroadcastManager.getInstance(context);
    Intent scoreIntent = new Intent(ArcadeCommon.ACTION_STATUS)
            .putExtra(ArcadeCommon.STATUS_RESET_SCORE, true)
            .putExtra(ArcadeCommon.STATUS_LEVEL, level)
            .putExtra(ArcadeCommon.STATUS_LIVES, gameState.totalBalls - gameState.ballNumber);
    gameState.statusMgr.sendBroadcast(scoreIntent);
    
    layout = FieldLayout.layoutForLevel(level, world);
    world.setGravity(new Vector2(0.0f, -layout.getGravity()));
    ballsAtTargets = new HashSet<Body>();

    scheduledActions = new PriorityQueue<ScheduledAction>();
    gameTime = 0;

    // Map bodies and IDs to FieldElements, and get elements on whom tick() has to be called.
    bodyToFieldElement = new HashMap<Body, FieldElement>();
    fieldElementsByID = new HashMap<String, FieldElement>();
    List<FieldElement> tickElements = new ArrayList<FieldElement>();

    for(FieldElement element : layout.getFieldElements()) {
        if (element.getElementId()!=null) {
            fieldElementsByID.put(element.getElementId(), element);
        }
        for(Body body : element.getBodies()) {
            bodyToFieldElement.put(body, element);
        }
        if (element.shouldCallTick()) {
            tickElements.add(element);
        }
    }
    fieldElementsToTick = tickElements.toArray(new FieldElement[0]);
    fieldElementsArray = layout.getFieldElements().toArray(new FieldElement[0]);

    delegate = null;
    String delegateClass = layout.getDelegateClassName();
    if (delegateClass!=null) {
        if (delegateClass.indexOf('.')==-1) {
            delegateClass = "com.homescreenarcade.pinball.fields." + delegateClass;
        }
        try {
            delegate = (Delegate)Class.forName(delegateClass).newInstance();
        }
        catch(Exception ex) {
            throw new RuntimeException(ex);
        }
    }
    else {
        // Use no-op delegate if no class specified, so that field.getDelegate() is non-null.
        delegate = new BaseFieldDelegate();
    }
}
 
开发者ID:StringMon,项目名称:homescreenarcade,代码行数:62,代码来源:Field.java

示例14: GameScreen

import com.badlogic.gdx.physics.box2d.World; //导入方法依赖的package包/类
public GameScreen(RebelInvader game) {
    this.game = game;

    state = GAME_RUNNING;

    engine = new PooledEngine();
    level = new Level(engine);
    world = new World(new Vector2(0, 0), true);
    listener = new PhysicsListener();

    // Testing
    guiCam = new OrthographicCamera(320, 480);
    guiCam.position.set(320 / 2, 480 / 2, 0);
    touchPoint = new Vector3();
    layout = new GlyphLayout();
    deadEntities = new ArrayList<Entity>();

    currentTime = 0f;
    missilex = 0f;
    powerActivated = false;

    engine.addSystem(new PlayerSystem(level));
    engine.addSystem(new CameraSystem());
    engine.addSystem(new BackgroundSystem());
    engine.addSystem(new MovementSystem());
    engine.addSystem(new BoundsSystem());
    engine.addSystem(new StateSystem());
    engine.addSystem(new AnimationSystem());
    engine.addSystem(new StructureSystem(level));
    engine.addSystem(new EnemySystem(level));
    engine.addSystem(new RenderingSystem(game.batch));
    engine.addSystem(new PhysicsSystem(world, engine.getSystem(RenderingSystem.class).getCamera()));
    engine.addSystem(new HealthSystem(this));
    engine.addSystem(new PowerSystem(this));
    engine.addSystem(new HeightDisposableSystem(this));
    engine.addSystem(new BulletSystem(this));
    engine.addSystem(new MissileSystem(this, level));
    engine.addSystem(new ExplosionSystem(this));

    // Set camera
    engine.getSystem(BackgroundSystem.class).setCamera(engine.getSystem(RenderingSystem.class).getCamera());

    // Set PhysicsListener as the entity listener for Ashley and contact listener for Box2D
    engine.addEntityListener(Family.all(BodyComponent.class).get(), listener);
    world.setContactListener(listener);

    // Set continuous physics for bullets
    world.setContinuousPhysics(true);

    level.create(world);

    pauseBounds = new Rectangle(320 - 40 - 5, 480 - 50 - 5, 40, 50);
    missileBounds = new Rectangle(10, 10, 50, 50);

    resumeSystems();

    Assets.musicMenu.stop();
    Assets.musicGame.play();
}
 
开发者ID:DevelopersGuild,项目名称:rebel-invader,代码行数:60,代码来源:GameScreen.java

示例15: show

import com.badlogic.gdx.physics.box2d.World; //导入方法依赖的package包/类
@Override
public void show() {
    camera = new OrthographicCamera();
    viewport = new FitViewport(WIDTH, HEIGHT, camera);
    camera.translate(WIDTH / 2, HEIGHT / 2);
    camera.update();

    batch = new SpriteBatch();

    playerSystem = new PlayerSystem();
    ghostSystem = new GhostSystem();
    movementSystem = new MovementSystem();
    pillSystem = new PillSystem();
    animationSystem = new AnimationSystem();
    renderSystem = new RenderSystem(batch);
    stateSystem = new StateSystem();

    engine = new Engine();
    engine.addSystem(playerSystem);
    engine.addSystem(ghostSystem);
    engine.addSystem(pillSystem);
    engine.addSystem(movementSystem);
    engine.addSystem(stateSystem);
    engine.addSystem(animationSystem);
    engine.addSystem(renderSystem);

    // box2d
    world = new World(Vector2.Zero, true);
    world.setContactListener(new WorldContactListener());
    box2DDebugRenderer = new Box2DDebugRenderer();
    showBox2DDebuggerRenderer = false;

    // box2d light
    rayHandler = new RayHandler(world);
    rayHandler.setAmbientLight(ambientLight);

    // load map
    tiledMap = new TmxMapLoader().load("map/map.tmx");
    tiledMapRenderer = new OrthogonalTiledMapRenderer(tiledMap, 1 / 16f, batch);

    new WorldBuilder(tiledMap, engine, world, rayHandler).buildAll();

    stageViewport = new FitViewport(WIDTH * 20, HEIGHT * 20);
    stage = new Stage(stageViewport, batch);

    font = new BitmapFont(Gdx.files.internal("fonts/army_stencil.fnt"));
    Label.LabelStyle labelStyle = new Label.LabelStyle(font, Color.WHITE);

    Label scoreTextLabel = new Label("SCORE", labelStyle);
    scoreTextLabel.setPosition(WIDTH * 1, HEIGHT * 19);
    stage.addActor(scoreTextLabel);

    Label hightScoreTextLabel = new Label("High Score", labelStyle);
    hightScoreTextLabel.setPosition(WIDTH * 14, HEIGHT * 19);
    stage.addActor(hightScoreTextLabel);

    scoreLabel = new Label("0", labelStyle);
    scoreLabel.setPosition(WIDTH * 1.5f, HEIGHT * 18.2f);
    stage.addActor(scoreLabel);

    highScoreLabel = new Label("0", labelStyle);
    highScoreLabel.setPosition(WIDTH * 16.5f, HEIGHT * 18.2f);
    stage.addActor(highScoreLabel);

    gameOverLabel = new Label("              - Game Over -\n Press Enter to continue", labelStyle);
    gameOverLabel.setPosition(WIDTH * 4.3f, HEIGHT * 9f);
    gameOverLabel.setVisible(false);
    stage.addActor(gameOverLabel);

    TextureAtlas textureAtlas = GameManager.instance.assetManager.get("images/actors.pack", TextureAtlas.class);
    pacmanSprite = new Sprite(new TextureRegion(textureAtlas.findRegion("Pacman"), 16, 0, 16, 16));
    pacmanSprite.setBounds(8f, 21.5f, 16 / GameManager.PPM, 16 / GameManager.PPM);

    stringBuilder = new StringBuilder();

    changeScreen = false;
}
 
开发者ID:yichen0831,项目名称:Pacman_libGdx,代码行数:78,代码来源:PlayScreen.java


注:本文中的com.badlogic.gdx.physics.box2d.World.setContactListener方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。