本文整理汇总了Java中com.badlogic.gdx.math.Intersector.overlapConvexPolygons方法的典型用法代码示例。如果您正苦于以下问题:Java Intersector.overlapConvexPolygons方法的具体用法?Java Intersector.overlapConvexPolygons怎么用?Java Intersector.overlapConvexPolygons使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.badlogic.gdx.math.Intersector
的用法示例。
在下文中一共展示了Intersector.overlapConvexPolygons方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: update
import com.badlogic.gdx.math.Intersector; //导入方法依赖的package包/类
public void update(Application APP, Player player, Music gameMusic, float delta)
{
for (int i = 0; i < currentEnemies.size; i++)
{
bulletLoop:
for (int j = 0; j < currentBullets.size; j++)
{
// IF ENEMY COLLIDES WITH BULLET
if (Intersector.overlapConvexPolygons(currentEnemies.get(i).getBounds(), currentBullets.get(j).getBounds()))
{
// DAMAGE THE ENEMY
currentEnemies.get(i).renderHit = true;
currentEnemies.get(i).playSquishSound();
currentEnemies.get(i).setHitTexture();
currentEnemies.get(i).reduceHealth(Bullet.getWeapon().getDamage());
// KNOCKBACK ENEMY
currentEnemies.get(i).knockback(Bullet.getWeapon().getKnockbackPower());
currentEnemies.get(i).applyVelocityToPosition(delta);
// REMOVE THE HIT BULLET
currentBullets.get(j).isUsed = false;
currentBullets.get(j).isOutOfScreen = false;
currentBullets.removeIndex(j);
break bulletLoop;
}
}
// IF ENEMY COLLIDES WITH PLAYER
if (Intersector.overlapConvexPolygons(currentEnemies.get(i).getBounds(), player.getBounds()))
{
Input.touchDown = false;
APP.setScreen(deadScreen);
gameMusic.stop();
}
}
}
示例2: isOverlapingWith
import com.badlogic.gdx.math.Intersector; //导入方法依赖的package包/类
public boolean isOverlapingWith(GameObject g) {
boolean result = false;
float distance = Vector2.dst(this.getCenter().x, this.getCenter().y, g.getCenter().x, g.getCenter().y);
float totalRadios = this.getRadio() + g.getRadio();
//Solo se comprueba la colisión si la distancia entre los centros es menor a la suma de los radios
if (distance < totalRadios)
result = Intersector.overlapConvexPolygons(this.getLogicShape(), g.getLogicShape());
return result;
}
示例3: overlaps
import com.badlogic.gdx.math.Intersector; //导入方法依赖的package包/类
@Override
public boolean overlaps(AbstractSprite sprite) {
Polygon spritePolygon = new Polygon(new float[]{sprite.getBounds().getX(), sprite.getBounds().getY(),
sprite.getBounds().getX(), sprite.getBounds().getY() + sprite.getBounds().getHeight(),
sprite.getBounds().getX()+ sprite.getBounds().getWidth(), sprite.getBounds().getY() + sprite.getBounds().getHeight(),
sprite.getBounds().getX()+ sprite.getBounds().getWidth(), sprite.getBounds().getY()});
return Intersector.overlapConvexPolygons(spritePolygon, polygon);
}
示例4: processEntity
import com.badlogic.gdx.math.Intersector; //导入方法依赖的package包/类
@Override
public void processEntity(Entity entity, float deltaTime)
{
if (!player.getComponent(Invincibility.class).isInvincible)
{
CollisionBox playerBox = player.getComponent(CollisionBox.class);
Position playerPos = player.getComponent(Position.class);
playerBox.poly.setPosition((float) playerPos.x, (float) playerPos.y);
Health health = player.getComponent(Health.class);
CollisionBox bulletBox = entity.getComponent(CollisionBox.class);
EnemyBullet bullet = entity.getComponent(EnemyBullet.class);
Position bulletPos = entity.getComponent(Position.class);
bulletBox.poly.setPosition((float) bulletPos.x, (float) bulletPos.y);
if (Intersector.overlapConvexPolygons(playerBox.poly, bulletBox.poly))
{
health.current -= bullet.damage;
engine.removeEntity(entity);
if (health.current <= 0)
{
engine.removeEntity(player);
}
}
}
}
示例5: processEntity
import com.badlogic.gdx.math.Intersector; //导入方法依赖的package包/类
@Override
public void processEntity(Entity entity, float deltaTime)
{
CollisionBox bulletBox = entity.getComponent(CollisionBox.class);
PlayerBullet bullet = entity.getComponent(PlayerBullet.class);
Position bulletPos = entity.getComponent(Position.class);
bulletBox.poly.setPosition((float) bulletPos.x, (float) bulletPos.y);
IntMap.Keys keys = enemyEntities.keys();
while (keys.hasNext)
{
Entity enemy = enemyEntities.get(keys.next());
CollisionBox enemyBox = enemy.getComponent(CollisionBox.class);
Position enemyPos = enemy.getComponent(Position.class);
enemyBox.poly.setPosition((float) enemyPos.x, (float) enemyPos.y);
if (enemy.hasComponent(Direction.class))
{
Direction dir = enemy.getComponent(Direction.class);
enemyBox.poly.setRotation(dir.angle());
}
if (Math.abs(bulletPos.x - enemyPos.x) < 50.0 &&
Math.abs(bulletPos.y - enemyPos.y) < 50.0)
{
if (Intersector.overlapConvexPolygons(enemyBox.poly, bulletBox.poly))
{
Health hp = enemy.getComponent(Health.class);
hp.current -= bullet.damage;
engine.removeEntity(entity);
if (hp.current <= 0)
{
engine.removeEntity(enemy);
}
break;
}
}
}
}
示例6: doProcessEntity
import com.badlogic.gdx.math.Intersector; //导入方法依赖的package包/类
@Override
public void doProcessEntity(Entity entity, float deltaTime) {
Polygon polygon1 = BoundingAreaBuilder
.getBoundingPolygon((EngineEntity) entity);
CollisionComponent collisionComponent = entity
.getComponent(CollisionComponent.class);
SnapshotArray<RuntimeCollision> runtimeCollisions = collisionComponent
.getBehaviors();
Object[] runtimes = runtimeCollisions.begin();
for (int i = 0; i < runtimeCollisions.size; i++) {
RuntimeCollision runtime = (RuntimeCollision) runtimes[i];
runtime.updateTargets(variablesManager);
runtime.updateBoundingAreas(gameLoop);
for (EngineEntity potentialTarget : runtime.getPotentialTargets()) {
Polygon polygon2 = BoundingAreaBuilder
.getBoundingPolygon(potentialTarget);
if (Intersector.overlapConvexPolygons(polygon1, polygon2)) {
ChangeVar targetEntity = new ChangeVar();
targetEntity.setContext(ChangeVar.Context.LOCAL);
targetEntity.setExpression("(fromid s"
+ potentialTarget.getId() + ")");
targetEntity
.setVariable(ReservedVariableNames.COLLISION_TARGET);
Array<Effect> additionalEffect = new Array<Effect>();
additionalEffect.add(targetEntity);
addEffects(entity, additionalEffect);
addEffects(entity, runtime.getEffects());
break;
}
}
}
runtimeCollisions.end();
}
示例7: update
import com.badlogic.gdx.math.Intersector; //导入方法依赖的package包/类
@Override
public void update(float deltaTime)
{
if (!(player.getComponent(Invincibility.class).isInvincible))
{
IntMap.Keys keys = enemyEntities.keys();
while (keys.hasNext)
{
Entity enemy = enemyEntities.get(keys.next());
CollisionBox enemyBox = enemy.getComponent(CollisionBox.class);
Position enemyPos = enemy.getComponent(Position.class);
enemyBox.poly.setPosition((float) enemyPos.x, (float) enemyPos.y);
CollisionBox playerBox = player.getComponent(CollisionBox.class);
Position playerPos = player.getComponent(Position.class);
playerBox.poly.setPosition((float) playerPos.x, (float) playerPos.y);
if (Intersector.overlapConvexPolygons(playerBox.poly, enemyBox.poly))
{
// Player health decrease
player.getComponent(Health.class).current -= enemy.getComponent(Enemy.class).playerHealthHit;
if (player.getComponent(Health.class).current <= 0)
{
engine.removeEntity(player);
}
else
{
// Player invulnerable
player.getComponent(Invincibility.class).isInvincible = true;
// Player velocity stops
player.getComponent(Velocity.class).x = 0;
player.getComponent(Velocity.class).y = 0;
}
// Enemy dies
engine.removeEntity(enemy);
break;
}
}
}
}
示例8: collisionCheck
import com.badlogic.gdx.math.Intersector; //导入方法依赖的package包/类
/**
* A method that check for collisions between objects
*
* @param subject
* the subject to check against all other objects
* @param objects
* the objects in the game that may collide with the subject
* @return true if a crash happens, false if not
*/
public Collision collisionCheck(PhysObject subject,
List<? extends PhysObject> objects) {
for (PhysObject object : objects) {
boolean collided = false;
boolean over = false;
boolean platform = object.getPhysics().isPlatform();
if (Intersector.overlapConvexPolygons(subject.getPhysics()
.getPoly(), object.getPhysics().getPoly())) {
collided = true;
} else if (object.getPhysics().getPosition().y > subject
.getPhysics().getPosition().y
+ subject.getPhysics().getRect().height
&& object.getPhysics().getPosition().x < subject
.getPhysics().getPosition().x
+ subject.getPhysics().getRect().width) {
over = true;
}
if (collided && platform) {
if (object.getPhysics().getPosition().y >= ((subject
.getPhysics().getPosition().y + subject
.getPhysics().getRect().height) - 2f)
|| PhysEngine.collision.getCollisionType() == CollisionType.OVER) {
subject.getPhysics().setOnTopOfObject(
object.getPhysics());
return PhysEngine.collision.setCollision(subject,
object, CollisionType.ONTOP);
} else {
return PhysEngine.collision.setCollision(subject,
object, CollisionType.CRASHED);
}
} else if (collided) {
return PhysEngine.collision.setCollision(subject, object,
CollisionType.CRASHED);
} else if (over && platform) {
return PhysEngine.collision.setCollision(subject, object,
CollisionType.OVER);
} else if ((subject.getPhysics().getRect().x) > (object
.getPhysics().getRect().x + object.getPhysics()
.getRect().width)
&& PhysEngine.collision.getCollisionType() != CollisionType.PASSED
&& PhysEngine.collision.getCollisionType() != CollisionType.OVER) {
return PhysEngine.collision.setCollision(subject, object,
CollisionType.PASSED);
}
}
return PhysEngine.collision.setCollision(subject, null,
CollisionType.NONE);
}