本文整理匯總了Java中com.badlogic.gdx.math.Vector2.dst方法的典型用法代碼示例。如果您正苦於以下問題:Java Vector2.dst方法的具體用法?Java Vector2.dst怎麽用?Java Vector2.dst使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.badlogic.gdx.math.Vector2
的用法示例。
在下文中一共展示了Vector2.dst方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: damageNearby
import com.badlogic.gdx.math.Vector2; //導入方法依賴的package包/類
public void damageNearby(int rad, int amount, float falloff){
for(int dx = -rad; dx <= rad; dx ++){
for(int dy = -rad; dy <= rad; dy ++){
float dst = Vector2.dst(dx, dy, 0, 0);
if(dst > rad || (dx == 0 && dy == 0)) continue;
Tile other = Vars.world.tile(x + dx, y + dy);
if(other != null && other.entity != null){
other.entity.damage((int)(amount * Mathf.lerp(1f-dst/rad, 1f, falloff)));
}
}
}
}
示例2: pointLineDist
import com.badlogic.gdx.math.Vector2; //導入方法依賴的package包/類
/**Returns distance from a point to a line segment.*/
private static float pointLineDist(float x, float y, float x2, float y2, float px, float py){
float l2 = Vector2.dst2(x, y, x2, y2);
float t = Math.max(0, Math.min(1, Vector2.dot(px - x, py - y, x2 - x, y2 - y) / l2));
Vector2 projection = Tmp.v1.set(x, y).add(Tmp.v2.set(x2, y2).sub(x, y).scl(t)); // Projection falls on the segment
return projection.dst(px, py);
}
示例3: findTileTarget
import com.badlogic.gdx.math.Vector2; //導入方法依賴的package包/類
public TileEntity findTileTarget(float x, float y, Tile tile, float range, boolean damaged){
Entity closest = null;
float dst = 0;
int rad = (int)(range/tilesize)+1;
int tilex = Mathf.scl2(x, tilesize);
int tiley = Mathf.scl2(y, tilesize);
for(int rx = -rad; rx <= rad; rx ++){
for(int ry = -rad; ry <= rad; ry ++){
Tile other = tile(rx+tilex, ry+tiley);
if(other != null && other.getLinked() != null){
other = other.getLinked();
}
if(other == null || other.entity == null || (tile != null && other.entity == tile.entity)) continue;
TileEntity e = other.entity;
if(damaged && e.health >= e.tile.block().health)
continue;
float ndst = Vector2.dst(x, y, e.x, e.y);
if(ndst < range && (closest == null || ndst < dst)){
dst = ndst;
closest = e;
}
}
}
return (TileEntity) closest;
}
示例4: VStick
import com.badlogic.gdx.math.Vector2; //導入方法依賴的package包/類
public VStick(VPoint argA, VPoint argB) {
this.pointA = argA;
this.pointB = argB;
Vector2 v1 = new Vector2(pointA.x, pointA.y);
Vector2 v2 = new Vector2(pointB.x, pointB.y);
hypotenuse = v1.dst(v2);
}
示例5: resetWithPoints
import com.badlogic.gdx.math.Vector2; //導入方法依賴的package包/類
public void resetWithPoints(Vector2 pointA, Vector2 pointB) {
float distance = pointA.dst(pointB);
Vector2 diffVector = pointA.sub(pointB);
float multiplier = distance / (numPoints - 1);
for(int i=0;i<numPoints;i++) {
Vector2 tmpVector = pointA.add(diffVector.nor().mul(multiplier*i*(1-antiSagHack)));
VPoint tmpPoint = vPoints.get(i);
tmpPoint.setPos(tmpVector.x, tmpVector.y);
}
}
示例6: findNearestEnemy
import com.badlogic.gdx.math.Vector2; //導入方法依賴的package包/類
private Entity findNearestEnemy(Entity towerEntity) {
Vector2 towerPosition = towerEntity.getComponent(PositionComponent.class).position;
if (getEngine().getEntitiesFor(Families.ENEMY) == null) {
return null;
}
ImmutableArray<Entity> enemies = getEngine().getEntitiesFor(Families.ENEMY);
HashMap<Double, Entity> distanceMap = new HashMap<>();
for (int i = 0; i < enemies.size(); i++) {
Vector2 enemyPosition = enemies.get(i).getComponent(PositionComponent.class).position;
double distance = towerPosition.dst(enemyPosition);
distanceMap.put(distance, enemies.get(i));
}
if (distanceMap.isEmpty()) {
return null;
}
Double minKey = Collections.min(distanceMap.keySet());
RangeComponent component = towerEntity.getComponent(RangeComponent.class);
if (component == null) {
return null;
}
Double range = component.getRange();
if (range < minKey) {
return null;
}
return distanceMap.get(minKey);
}
示例7: calculateDamage
import com.badlogic.gdx.math.Vector2; //導入方法依賴的package包/類
static int calculateDamage(float x, float y, float tx, float ty, float radius, int damage){
float dist = Vector2.dst(x, y, tx, ty);
float scaled = 1f - dist/radius;
return (int)(damage * scaled);
}
示例8: cursorNear
import com.badlogic.gdx.math.Vector2; //導入方法依賴的package包/類
public boolean cursorNear(){
return Vector2.dst(player.x, player.y, getBlockX() * tilesize, getBlockY() * tilesize) <= placerange;
}
示例9: validPlace
import com.badlogic.gdx.math.Vector2; //導入方法依賴的package包/類
public boolean validPlace(int x, int y, Block type){
for(SpawnPoint spawn : control.getSpawnPoints()){
if(Vector2.dst(x * tilesize, y * tilesize, spawn.start.worldx(), spawn.start.worldy()) < enemyspawnspace){
return false;
}
}
Tmp.r2.setSize(type.width * Vars.tilesize, type.height * Vars.tilesize);
Vector2 offset = type.getPlaceOffset();
Tmp.r2.setCenter(offset.x + x * Vars.tilesize, offset.y + y * Vars.tilesize);
for(SolidEntity e : Entities.getNearby(control.enemyGroup, x * tilesize, y * tilesize, tilesize * 2f)){
Rectangle rect = e.hitbox.getRect(e.x, e.y);
if(Tmp.r2.overlaps(rect)){
return false;
}
}
if(type.solid || type.solidifes) {
for (Player player : Vars.control.playerGroup.all()) {
if (!player.isAndroid && Tmp.r2.overlaps(player.hitbox.getRect(player.x, player.y))) {
return false;
}
}
}
Tile tile = world.tile(x, y);
if(tile == null) return false;
if(!type.isMultiblock() && Vars.control.getTutorial().active() &&
Vars.control.getTutorial().showBlock()){
GridPoint2 point = Vars.control.getTutorial().getPlacePoint();
int rotation = Vars.control.getTutorial().getPlaceRotation();
Block block = Vars.control.getTutorial().getPlaceBlock();
if(type != block || point.x != x - control.getCore().x || point.y != y - control.getCore().y
|| (rotation != -1 && rotation != this.rotation)){
return false;
}
}else if(Vars.control.getTutorial().active()){
return false;
}
if(type.isMultiblock()){
int offsetx = -(type.width-1)/2;
int offsety = -(type.height-1)/2;
for(int dx = 0; dx < type.width; dx ++){
for(int dy = 0; dy < type.height; dy ++){
Tile other = world.tile(x + dx + offsetx, y + dy + offsety);
if(other == null || other.block() != Blocks.air){
return false;
}
}
}
return true;
}else{
if(tile.block() != type && type.canReplace(tile.block()) && tile.block().isMultiblock() == type.isMultiblock()){
return true;
}
return tile != null && tile.block() == Blocks.air;
}
}
示例10: findNearestEnemies
import com.badlogic.gdx.math.Vector2; //導入方法依賴的package包/類
private ArrayList<Entity> findNearestEnemies(Entity towerEntity) {
Vector2 towerPosition = towerEntity.getComponent(PositionComponent.class).position;
TargetComponent targetComp = Mappers.TARGET_M.get(towerEntity);
if (getEngine().getEntitiesFor(Families.ENEMY) == null) {
return null;
}
RangeComponent component = towerEntity.getComponent(RangeComponent.class);
if (component == null) {
return null;
}
Double range = component.getRange();
ImmutableArray<Entity> enemies = getEngine().getEntitiesFor(Families.ENEMY);
HashMap<Double, Entity> distanceMap = new HashMap<>();
for (int i = 0; i < enemies.size(); i++) {
Vector2 enemyPosition = enemies.get(i).getComponent(PositionComponent.class).position;
double distance = towerPosition.dst(enemyPosition);
if (distance < range) {
distanceMap.put(distance, enemies.get(i));
}
}
if (distanceMap.isEmpty() || distanceMap.keySet().isEmpty()) {
return null;
}
Map<Double, Entity> multiDistanceList = new HashMap<>();
for (int i = 0; i < targetComp.getMaxTargets(); i++) {
if (distanceMap.isEmpty() || distanceMap.keySet().isEmpty()) {
break;
}
Double min = Collections.min(distanceMap.keySet());
multiDistanceList.put(min, distanceMap.get(min));
distanceMap.remove(min);
}
return new ArrayList<Entity>(multiDistanceList.values());
}
示例11: moveToEnemy
import com.badlogic.gdx.math.Vector2; //導入方法依賴的package包/類
private void moveToEnemy(Entity projectileEntity, float deltaTime) {
Entity destinationEntity = projectileEntity.getComponent(DestinationComponent.class).getDestinationEntity();
if (destinationEntity.getComponent(PositionComponent.class) == null) {
return;
}
Vector2 position = projectileEntity.getComponent(PositionComponent.class).position;
AngleComponent angle = projectileEntity.getComponent(AngleComponent.class);
VelocityComponent velocity = projectileEntity.getComponent(VelocityComponent.class);
Vector2 destination = destinationEntity.getComponent(PositionComponent.class).position;
double damage = projectileEntity.getComponent(DamageComponent.class).getDamage();
float destinationX = destination.x;
float destinationY = destination.y;
double difX = destinationX - position.x;
double difY = destinationY - position.y;
// set direction
float spriteAngle = (float) Math.toDegrees(Math.atan2(difX, -difY));
float rotAng = (float) Math.toDegrees(Math.atan2(difY, difX));
angle.spriteAngle = spriteAngle;
angle.angle = rotAng;
float angleX = (float) Math.cos(Math.toRadians(angle.angle));
float angleY = (float) Math.sin(Math.toRadians(angle.angle));
velocity.velocity.x = angleX * velocity.maxSpeed;
velocity.velocity.y = angleY * velocity.maxSpeed;
position.x += velocity.velocity.x * deltaTime;
position.y += velocity.velocity.y * deltaTime;
if (position.dst(destination) < 5) {
dealDamage(projectileEntity, damage);
}
if (destinationEntity == null || destinationEntity.getComponent(EnemyComponent.class) == null
|| destinationEntity.getComponent(TowerComponent.class) != null
|| destinationEntity.getComponent(ProjectileComponent.class) != null
|| destinationEntity.getComponents().size() == 0) {
getEngine().removeEntity(projectileEntity);
return;
}
}