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


Java Intersector.overlaps方法代码示例

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


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

示例1: isWithinCameraView

import com.badlogic.gdx.math.Intersector; //导入方法依赖的package包/类
/**
 * checks if a game object is within the given camera's viewport.
 * 
 * @param camera game camera to check if the game object is within the view port
 * @param gameObj game object to check
 * 
 * @return <b>true</b> if game object is within camera viewport. <b>false</b> otherwise.
 */
public static boolean isWithinCameraView(Camera camera, GameObject gameObj) {
	if (cameraBounds == null) {
		// first call to this method
		// create a Rectangle instance and keep it for later use
		// it is better to keep an instance to avoid gc during update/render calls
		cameraBounds = new Rectangle();
	}

	cameraBounds.x = camera.position.x - camera.viewportWidth / 2;
	cameraBounds.y = camera.position.y - camera.viewportHeight / 2;
	cameraBounds.width = camera.viewportWidth;
	cameraBounds.height = camera.viewportHeight;

	return Intersector.overlaps(cameraBounds, gameObj.getBoundingRectangle());
}
 
开发者ID:Quillraven,项目名称:Protoman-vs-Megaman,代码行数:24,代码来源:GameUtils.java

示例2: updateRunning

import com.badlogic.gdx.math.Intersector; //导入方法依赖的package包/类
public void updateRunning(float delta) {
    if (delta > .15f) {
        delta = .15f;
    }

    bird.update(delta);
    scroller.update(delta);

    if (scroller.collides(bird) && bird.isAlive()) {
        scroller.stop();
        bird.die();
        AssetLoader.deadSound.play();
    }

    if (Intersector.overlaps(bird.getBoundingCircle(), ground)) {
        scroller.stop();
        bird.die();
        bird.decelerate();
        currentState = GameState.GAMEOVER;
    }
}
 
开发者ID:onatm,项目名称:Ampel-Bird,代码行数:22,代码来源:GameWorld.java

示例3: checkForPaddleCollision

import com.badlogic.gdx.math.Intersector; //导入方法依赖的package包/类
private void checkForPaddleCollision() {
    for (Paddle hitPaddle : paddleList) {
        if (Intersector.overlaps(hitPaddle, ball)) {
            paddleHits++;
            ball.xVel *= -1;
            if (ball.xVel > 0) {ball.xVel += 20;} else {ball.xVel -= 20;}

            paddleCollisionSound.play();
            startScreenShake();
            if (hitPaddle.name.equals("paddle1")) {
                ball.setPosition((hitPaddle.x + hitPaddle.width), ball.y);
            } else if (hitPaddle.name.equals("paddle2")) {
                ball.setPosition((hitPaddle.x - ball.width), ball.y);
            }
        }
    }
}
 
开发者ID:justinmeister,项目名称:PongWithLibgdx,代码行数:18,代码来源:PongBoard.java

示例4: checkItems

import com.badlogic.gdx.math.Intersector; //导入方法依赖的package包/类
public void checkItems() {
	for(Item i : items) {
		if(Intersector.overlaps(i,player.getR())) {
			switch(i.getType()) {
			case KILL:
				setLost(true);
				break;
			case FLY:
				velocityY = Constants.velocityY*2f;
				/*if(velocityX >0)
						velocityX = Constants.velocityX;
					else
						velocityX = -Constants.velocityX;*/
				break;
			}
		}
	}

}
 
开发者ID:dieubware,项目名称:Escape-of-the-Ninja,代码行数:20,代码来源:GameModel.java

示例5: overlaps

import com.badlogic.gdx.math.Intersector; //导入方法依赖的package包/类
public boolean overlaps(BoundsComponent other) {
    if (getBounds() instanceof Rectangle && other.getBounds() instanceof Rectangle) {
        return Intersector.overlaps((Rectangle) getBounds(), (Rectangle) other.getBounds());
    } else if (getBounds() instanceof Circle && other.getBounds() instanceof Circle) {
        return Intersector.overlaps((Circle) getBounds(), (Circle) other.getBounds());
    } else if (getBounds() instanceof Circle && other.getBounds() instanceof Rectangle) {
        return Intersector.overlaps((Circle) getBounds(), (Rectangle) other.getBounds());
    } else if (getBounds() instanceof Rectangle && other.getBounds() instanceof Circle) {
        return Intersector.overlaps((Circle) other.getBounds(), (Rectangle) getBounds());
    }
    throw new RuntimeException("Cannot compare " + this.getBounds() + " and " + other.getBounds());
}
 
开发者ID:ezet,项目名称:penguins-in-space,代码行数:13,代码来源:BoundsComponent.java

示例6: update

import com.badlogic.gdx.math.Intersector; //导入方法依赖的package包/类
@Override
public void update(GameObject object, float delta) {
	if (tree == null) {
		tree = object.getGameLayer().getSystem(QuadTree.class);
	}

	if (tree != null) {
		CollisionData.getPool().freeAll(collisions);
		collisions.clear();
		Array<GameObject> possible_collisions = tree.getPossibleCollisions(object);
		for (int i = 0; i < possible_collisions.size; i++) {
			GameObject target = possible_collisions.get(i);
			CollisionController target_controller = target.getController(CollisionController.class);
			if (target == object || target_controller == null)
				continue;
			if (Intersector.overlaps(object.getCollisionBounds(), target.getCollisionBounds())) {
				CollisionData data = CollisionData.getPool().obtain();
				Rectangle self_bounds = object.getCollisionBounds();
				Rectangle target_bounds = target.getCollisionBounds();
				
				//create a quad for the collision
				float x = self_bounds.x > target_bounds.x ? self_bounds.x : target_bounds.x; 						//X
				float y = self_bounds.y > target_bounds.y ? self_bounds.y : target_bounds.y; 						//Y
				float w = self_bounds.x > target_bounds.x ? target_bounds.x + target_bounds.width - self_bounds.x	//WIDTH
						: self_bounds.x + self_bounds.width - target_bounds.x;									
				float h = self_bounds.y > target_bounds.y ? target_bounds.y + target_bounds.height - self_bounds.y	//HEIGHT
						: self_bounds.y + self_bounds.height - target_bounds.y;

				data.init(object, target, this, x, y, w, h);
				collisions.add(data);
			}
		}
	} else
		object.getState().log("tree is null.");

}
 
开发者ID:kyperbelt,项目名称:KyperBox,代码行数:37,代码来源:CollisionController.java

示例7: getCollidingMapObject

import com.badlogic.gdx.math.Intersector; //导入方法依赖的package包/类
/**
 * This method returns the properties of an object in a collision layer by checking the player rectangle and object rectangle for an intersection
 * @param layerIndex the index of the layer in which to search for objects
 * @return the collided object
 */
protected MapObject getCollidingMapObject(int layerIndex) {
    MapObjects mapObjects = map.getLayers().get(layerIndex).getObjects();

    for (MapObject mapObject : mapObjects) {
        MapProperties mapProperties = mapObject.getProperties();

        float width, height, x, y;
        Rectangle objectRectangle = new Rectangle();
        Rectangle playerRectangle = new Rectangle();

        if (mapProperties.containsKey("width") && mapProperties.containsKey("height") && mapProperties.containsKey("x") && mapProperties.containsKey("y")) {
            width = (float) mapProperties.get("width");
            height = (float) mapProperties.get("height");
            x = (float) mapProperties.get("x");
            y = (float) mapProperties.get("y");
            objectRectangle.set(x, y, width, height);
        }

        playerRectangle.set(
                playScreen.getPlayer().getX() * MainGameClass.PPM,
                playScreen.getPlayer().getY() * MainGameClass.PPM,
                playScreen.getPlayer().getWidth() * MainGameClass.PPM,
                playScreen.getPlayer().getHeight() * MainGameClass.PPM
        );

        // If the player rectangle and the object rectangle is colliding, return the object
        if (Intersector.overlaps(objectRectangle, playerRectangle)) {
            return mapObject;
        }
    }

    // If no colliding object was found in that layer
    return null;
}
 
开发者ID:johannesmols,项目名称:GangsterSquirrel,代码行数:40,代码来源:InteractiveMapTileObject.java

示例8: hitbox

import com.badlogic.gdx.math.Intersector; //导入方法依赖的package包/类
boolean hitbox(Circle eggLeft, Circle eggRight, Rectangle... rects) {
    return  Intersector.overlaps(eggLeft, rects[0]) ||
            Intersector.overlaps(eggRight, rects[1]) ||
            Intersector.overlaps(rects[2], rects[0]) ||
            Intersector.overlaps(rects[2], rects[1]) ||
            Intersector.overlaps(rects[3], rects[0]) ||
            Intersector.overlaps(rects[3], rects[1]);
    //rects[0] = frontPipe, rects[1] = backPipe, rects[2] = engines, rects[3] = body
}
 
开发者ID:SamukiPL,项目名称:cykacommander,代码行数:10,代码来源:GameBasic.java

示例9: destroyEntities

import com.badlogic.gdx.math.Intersector; //导入方法依赖的package包/类
public void destroyEntities(ServerBomb bomb, float radius, Vector2 position) {
    Body body = bomb.body;
    circle.set(position, radius);
    for (ServerEntity entity: worldManager.entities) {
        if (entity.body == body || entity.body.toDestroy) {
            continue;
        }
        if (Intersector.overlaps(circle, entity.body.rectangle)) {
            Vector2 step = entity.body.getPosition();
            float length = position.dst(step);
            step.sub(position);
            float max = Math.max(step.x, step.y);
            step.scl(4 / max);
            Body otherBody = Ray.findBody(world,
                    body, step, length, true);
            if (otherBody == null) {
                if (entity instanceof LivingCategory) {
                    if (((LivingCategory)entity.body.getUserData()).kill()) {
                        if (bomb.bomber != entity.body.getUserData())
                            bomb.bomber.addKill();
                        else {
                            bomb.bomber.reduceKill();
                        }
                    }
                }
            }
        }
    }
}
 
开发者ID:ganeshkamathp,项目名称:killingspree,代码行数:30,代码来源:WorldBodyUtils.java

示例10: checkWallCollision

import com.badlogic.gdx.math.Intersector; //导入方法依赖的package包/类
private void checkWallCollision (float delta) {
	float newX= maincharacter.getX();
	float newY = maincharacter.getY();
	
	tmp_circle.set(newX+ maincharacter.getOriginX(),newY + maincharacter.getOriginY(), radius);
	float k;
	for (Rectangle r : walls) {
		/* 
		 * check if our maincharacter collides with walls
		 */
		if (Intersector.overlaps(tmp_circle, r)) {
			if (  newX+maincharacter.getOriginX() < r.x ) {
				k = Intersector.distanceLinePoint(r.x, r.y, r.x, r.y+r.height, newX+maincharacter.getOriginX(), newY+maincharacter.getOriginY());
				newX -= (radius-k);
			} else if (  newX+maincharacter.getOriginX() + radius*2> r.x + r.width ) {
				k = Intersector.distanceLinePoint(r.x+r.width, r.y, r.x+r.width, r.y+r.height, newX+maincharacter.getOriginX(), newY+maincharacter.getOriginY());
				newX += (radius-k);
			}
			if (  newY+maincharacter.getOriginY() < r.y  ) {
				k =  Intersector.distanceLinePoint(r.x, r.y, r.x+r.width, r.y, newX+maincharacter.getOriginX(), newY+maincharacter.getOriginY());
				newY -= (radius-k);
			} else if ( newY+maincharacter.getOriginY() + radius*2 > r.y + r.height) {
				k = Intersector.distanceLinePoint(r.x, r.y+r.height, r.x+r.width, r.y+r.height, newX+maincharacter.getOriginX(), newY+maincharacter.getOriginY());
				newY += (radius-k);
			}
		}
	}

	maincharacter.move(newX, newY);
}
 
开发者ID:s76,项目名称:zesp2013,代码行数:31,代码来源:GameStage.java

示例11: isActorsCollide

import com.badlogic.gdx.math.Intersector; //导入方法依赖的package包/类
/**
 * Check collision from actor's rectangles.
 *
 * @param actor1 the actor1
 * @param actor2 the actor2
 * @return true, if is actors collide
 */
public static boolean isActorsCollide(Actor actor1, Actor actor2) {
	if (Intersector.overlaps(UtilsActor.getRectangleOfActor(actor1),
			UtilsActor.getRectangleOfActor(actor2))) {
		logCollision1(actor1, actor2);
		return true;
	} else {
		return false;
	}
}
 
开发者ID:sawankh,项目名称:MathAttack,代码行数:17,代码来源:CollisionDetector.java

示例12: collides

import com.badlogic.gdx.math.Intersector; //导入方法依赖的package包/类
public static boolean collides(Actor actor, float x, float y) {
	Rectangle rectA1 = getBounds(actor);
	Rectangle rectA2 = new Rectangle(x, y, 5, 5);
	// Check if rectangles collides
	if (Intersector.overlaps(rectA1, rectA2)) {
		return true;
	} else {
		return false;
	}
}
 
开发者ID:pyros2097,项目名称:GdxStudio,代码行数:11,代码来源:Scene.java

示例13: collides

import com.badlogic.gdx.math.Intersector; //导入方法依赖的package包/类
public boolean collides(Bird bird) {
    if (position.x < bird.getX() + bird.getWidth()) {
        return (Intersector.overlaps(bird.getBoundingCircle(), barUp)
                || Intersector.overlaps(bird.getBoundingCircle(), barDown)
                || Intersector.overlaps(bird.getBoundingCircle(), arrowUp)
                || Intersector.overlaps(bird.getBoundingCircle(), arrowDown));
    }
    return false;
}
 
开发者ID:onatm,项目名称:Ampel-Bird,代码行数:10,代码来源:Pipe.java

示例14: collides

import com.badlogic.gdx.math.Intersector; //导入方法依赖的package包/类
public boolean collides(Bird bird) {
	if (position.x < bird.getX() + bird.getWidth()) {
		return (Intersector.overlaps(bird.getBoundingCircle(), barUp)
				|| Intersector.overlaps(bird.getBoundingCircle(), barDown)
				|| Intersector.overlaps(bird.getBoundingCircle(), skullUp) || Intersector
					.overlaps(bird.getBoundingCircle(), skullDown));
	}
	return false;
}
 
开发者ID:Adeor,项目名称:A-Flappy-Bird-Clone,代码行数:10,代码来源:Pipe.java

示例15: updateRunning

import com.badlogic.gdx.math.Intersector; //导入方法依赖的package包/类
public void updateRunning(float delta) {
	if (delta > .15f) {
		delta = .15f;
	}

	bird.update(delta);
	scroller.update(delta);

	if (scroller.collides(bird) && bird.isAlive()) {
		scroller.stop();
		bird.die();
		AssetLoader.dead.play();
		renderer.prepareTransition(255, 255, 255, .3f);

		AssetLoader.fall.play();
	}

	if (Intersector.overlaps(bird.getBoundingCircle(), ground)) {

		if (bird.isAlive()) {
			AssetLoader.dead.play();
			renderer.prepareTransition(255, 255, 255, .3f);

			bird.die();
		}

		scroller.stop();
		bird.decelerate();
		currentState = GameState.GAMEOVER;

		if (score > AssetLoader.getHighScore()) {
			AssetLoader.setHighScore(score);
			currentState = GameState.HIGHSCORE;
		}
	}
}
 
开发者ID:Adeor,项目名称:A-Flappy-Bird-Clone,代码行数:37,代码来源:GameWorld.java


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