本文整理汇总了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());
}
示例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;
}
}
示例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);
}
}
}
}
示例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;
}
}
}
}
示例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());
}
示例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.");
}
示例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;
}
示例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
}
示例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();
}
}
}
}
}
}
}
示例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);
}
示例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;
}
}
示例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;
}
}
示例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;
}
示例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;
}
示例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;
}
}
}