public final void AddPosition(Vector2f nextDestPosition) { Vector2f vector; nextDestPosition.y = MathUtils.clamp(nextDestPosition.y, 0f, LSystem.screenRect.height - 1f); nextDestPosition.x = MathUtils.clamp(nextDestPosition.x, 0f, LSystem.screenRect.width - 1f); vector = nextDestPosition; Vector2f position = this.position.cpy(); if (this.destination.size() != 0) { position = this.destination.get(this.destination.size() - 1).cpy(); } float num = MathUtils.atan2((nextDestPosition.y - position.y), (nextDestPosition.x - position.x)); if (Vector2f.dst(position, nextDestPosition) > Tile.size) { vector = position.add(new Vector2f(MathUtils.cos(num) * Tile.size, MathUtils.sin(num) * Tile.size)); } Vector2f item = new Vector2f(Tile.getBounds(vector).getCenterX(), Tile .getBounds(vector).getCenterY()); if (!this.destination.contains(item)) { this.destination.add(item); AddPosition(vector); } int index = this.destination.indexOf(item); this.destination.subList(index + 1, (this.destination.size() - index) - 1 + index + 1).clear(); }
public void setPosition(float px, float py) { _localPos.set(px, py); if (_parent != null) { _localPos.subLocal(_parent.pos); _parent.correctCenterOfGravity(); _parent.calcMassData(); } }
@Override public void SetPosition(Vector2f newPosition) { Vector2f vector = super.getPosition().sub(newPosition); if (!vector.equals(0, 0)) { for (int i = 0; i < this.nextBalls.size(); i++) { this.nextBalls.get(i).SetPosition( this.nextBalls.get(i).GetPosition().sub(vector)); } } super.SetPosition(newPosition); }
public final void AimToPosition(Vector2f position) { if (position.y > super.getPosition().y) { position.y = super.getPosition().y - 15f; } super.setRotation(Trigonometry.getAngle(position.sub(super .getPosition())) + 1.570796f); if (super.getRotation() < -1.4137166941154069) { super.setRotation(-1.413717f); } if (super.getRotation() > 1.4137166941154069) { super.setRotation(1.413717f); } }
private Vector2f getTextPosition(MenuScreen screen) { if (this.getScale() == 1f) { pos.set(((((int) this.position.x) + (this.buttonTexture.getWidth() / 2)) - (this .GetWidth(screen) / 2)), ((int) this.position.y)); return pos; } pos.set((this.position.x) + ((this.buttonTexture.getWidth() / 2) - ((this .GetWidth(screen) / 2) * this.getScale())), (this.position.y) + ((this.GetHeight(screen) - (this.GetHeight(screen) * this .getScale())) / 2f)); return pos; }
public final void Update(GameTime gameTime) { for (int i = this.bullets.size() - 1; i >= 0; i--) { this.bullets.get(i).Update(gameTime); if (this.bullets.get(i).totalDistance > this.Range) { this.bullets.remove(this.bullets.get(i)); } } if (this.isAlive()) { if (this.destination.size() > 0) { Vector2f vector = this.destination.get(0); float num2 = Vector2f.dst(vector, this.position); float num3 = MathUtils.atan2((vector.y - this.position.y), (vector.x - this.position.x)); this.rotation = num3; this.position.addLocal(((new Vector2f(MathUtils.cos(num3), MathUtils.sin(num3)).mul(this.MoveSpeed).mul(gameTime .getElapsedGameTime())).mul(40f))); if (num2 <= this.MoveSpeed) { this.position.set(vector); this.destination.remove(0); } this.animationPlayer.PlayAnimation(this.walkAnimation); } else { this.animationPlayer.PlayAnimation(this.idleAnimation); } this.reloadTime += gameTime.getElapsedGameTime(); } }
public LTouchLocation(int aId, LTouchLocationState aState, Vector2f aPosition, float aPressure) { id = aId; position = aPosition; previousPosition = Vector2f.ZERO(); state = aState; previousState = LTouchLocationState.Invalid; pressure = aPressure; previousPressure = 0.0f; }
public LTouchLocation(int aId, LTouchLocationState aState, float x, float y) { id = aId; position = new Vector2f(x, y); previousPosition = Vector2f.ZERO(); state = aState; previousState = LTouchLocationState.Invalid; pressure = 0.0f; previousPressure = 0.0f; }
public final void draw(GLEx g) { if (isOnLoadComplete()) { batch.begin(); before(batch); for (TileMap tile : tiles) { tile.draw(g, batch, offset.x(), offset.y()); } for (SpriteBatchObject o : objects) { objX = o.getX() + offset.x; objY = o.getY() + offset.y; if (contains(objX, objY)) { o.draw(batch, offset.x, offset.y); } } if (content.isVisible()) { content.drawNode(batch); } after(batch); batch.end(); } }
public boolean tryGetPreviousLocation(RefObject<LTouchLocation> aPreviousLocation) { if (aPreviousLocation.argvalue == null) { aPreviousLocation.argvalue = new LTouchLocation(); } if (previousState == LTouchLocationState.Invalid) { aPreviousLocation.argvalue.id = -1; aPreviousLocation.argvalue.state = LTouchLocationState.Invalid; aPreviousLocation.argvalue.position = Vector2f.ZERO(); aPreviousLocation.argvalue.previousState = LTouchLocationState.Invalid; aPreviousLocation.argvalue.previousPosition = Vector2f.ZERO(); aPreviousLocation.argvalue.pressure = 0.0f; aPreviousLocation.argvalue.previousPressure = 0.0f; return false; } else { aPreviousLocation.argvalue.id = this.id; aPreviousLocation.argvalue.state = this.previousState; aPreviousLocation.argvalue.position = this.previousPosition.cpy(); aPreviousLocation.argvalue.previousState = LTouchLocationState.Invalid; aPreviousLocation.argvalue.previousPosition = Vector2f.ZERO(); aPreviousLocation.argvalue.pressure = this.previousPressure; aPreviousLocation.argvalue.previousPressure = 0.0f; return true; } }
public final void HandleEnemy(java.util.ArrayList<RoleControl> armies) { RoleControl army = null; float positiveInfinity = Float.POSITIVE_INFINITY; for (int i = 0; i < armies.size(); i++) { if ((armies.get(i) != this) && (armies.get(i).shape != this.shape)) { float num3 = Vector2f .dst(armies.get(i).position, this.position); if ((positiveInfinity > num3) && armies.get(i).isAlive()) { positiveInfinity = num3; army = armies.get(i); } for (int j = armies.get(i).bullets.size() - 1; j >= 0; j--) { if (this.getBoundingRectangle() .intersects( armies.get(i).bullets.get(j) .getBoundingRectangle())) { this.health = MathUtils.max( (this.health - armies.get(i).Damage), 0f); armies.get(i).bullets.remove(j); if (!this.isAlive()) { this.gameContent.dieSound.Play(); this.animationPlayer .PlayAnimation(this.dieAnimation); } } } } } if (army != null) { this.rotation = MathUtils.atan2( (army.position.y - this.position.y), (army.position.x - this.position.x)); } if (this.rank.equals(RoleRank.bazooka)) { this.rotation = this.defaultRotaion; } if (((army != null) && (positiveInfinity < this.Range)) && (this.reloadTime > this.MaxReloadTime)) { this.reloadTime = 0f; this.bullets.add(new Bullet(this.gameContent.bullet[this.rank .getValue()], this.rank, this.position, this.rotation)); this.gameContent.noise[this.rank.getValue()].Play(); } }
public WalkingBiped(LTexture t2DHead, LTexture t2DTorso, LTexture t2DUpperArm, LTexture t2DLowerArm, LTexture t2DUpperLeg, LTexture t2DLowerLeg, Vector2f positionGround, int day) { this.t2DHead = t2DHead; this.t2DTorso = t2DTorso; this.t2DLowerArm = t2DLowerArm; this.t2DLowerLeg = t2DLowerLeg; this.t2DUpperArm = t2DUpperArm; this.t2DUpperLeg = t2DUpperLeg; this.positionGround = positionGround.cpy(); this.cycleLength = (int) (((MathUtils.random() * 40f) + 40f) / ((1f + (((float) day) / 22f)))); this.speed = 60f / ((float) this.cycleLength); this.angleBody = 0f; this.isDead = false; this.iCycle = 0; this.angleUppLegL = (((this.angleUppLegMax - this.angleUppLegMin) / 2f) * ((float) Math .sin(((((float) this.iCycle) / ((float) this.cycleLength)) * 2f) * 3.1415926535897931))) + ((this.angleUppLegMax + this.angleUppLegMin) / 2f); this.angleUppLegR = (((this.angleUppLegMax - this.angleUppLegMin) / 2f) * ((float) Math .sin((((((float) this.iCycle) / ((float) this.cycleLength)) * 2f) * 3.1415926535897931) + 3.1415926535897931))) + ((this.angleUppLegMax + this.angleUppLegMin) / 2f); this.angleLowLegL = (((this.angleLowLegMax - this.angleLowLegMin) / 2f) * ((float) Math .sin((((((float) this.iCycle) / ((float) this.cycleLength)) * 2f) * 3.1415926535897931) + (6.2831853071795862 * this.phaseDelay)))) + ((this.angleLowLegMax + this.angleLowLegMin) / 2f); this.angleLowLegR = (((this.angleLowLegMax - this.angleLowLegMin) / 2f) * ((float) Math .sin(((((((float) this.iCycle) / ((float) this.cycleLength)) * 2f) * 3.1415926535897931) + 3.1415926535897931) + (6.2831853071795862 * this.phaseDelay)))) + ((this.angleLowLegMax + this.angleLowLegMin) / 2f); this.position = positionGround.cpy(); float num = (((float) (Math.cos((double) this.angleUppLegL) + Math .cos((double) this.angleLowLegL))) > ((float) (Math .cos((double) this.angleUppLegR) + Math .cos((double) this.angleLowLegR)))) ? ((float) (t2DUpperLeg.getHeight() * (Math .cos((double) this.angleUppLegL) + Math .cos((double) this.angleLowLegL)))) : ((float) (t2DUpperLeg.getHeight() * (Math .cos((double) this.angleUppLegR) + Math .cos((double) this.angleLowLegR)))); this.position.y = positionGround.y - num; this.angleUppArmL = (((this.angleUppArmMax - this.angleUppArmMin) / 2f) * ((float) Math .sin(((((float) this.iCycle) / ((float) this.cycleLength)) * 2f) * 3.1415926535897931))) + ((this.angleUppArmMax + this.angleUppArmMin) / 2f); this.angleUppArmR = (((this.angleUppArmMax - this.angleUppArmMin) / 2f) * ((float) Math .sin((((((float) this.iCycle) / ((float) this.cycleLength)) * 2f) * 3.1415926535897931) + 3.1415926535897931))) + ((this.angleUppArmMax + this.angleUppArmMin) / 2f); this.angleLowArmL = (((this.angleLowArmMax - this.angleLowArmMin) / 2f) * ((float) Math .sin((((((float) this.iCycle) / ((float) this.cycleLength)) * 2f) * 3.1415926535897931) + (6.2831853071795862 * this.phaseDelay)))) + ((this.angleLowArmMax + this.angleLowArmMin) / 2f); this.angleLowArmR = (((this.angleLowArmMax - this.angleLowArmMin) / 2f) * ((float) Math .sin(((((((float) this.iCycle) / ((float) this.cycleLength)) * 2f) * 3.1415926535897931) + 3.1415926535897931) + (6.2831853071795862 * this.phaseDelay)))) + ((this.angleLowArmMax + this.angleLowArmMin) / 2f); this.head = new BodyPart(t2DHead, this.position .sub(0f, (float) (t2DTorso.getHeight() + (t2DHead.getHeight() / 2)))); this.torso = new BodyPart(t2DTorso, this.position); this.upperArmL = new BodyPart(t2DUpperArm, this.position .sub(0f, ((float) t2DTorso.getHeight()) / 1.2f)); this.upperArmR = new BodyPart(t2DUpperArm, this.position .sub(0f, ((float) t2DTorso.getHeight()) / 1.2f)); this.lowerArmL = new BodyPart( t2DLowerArm, (this.position.sub(0f, ((float) t2DTorso.getHeight()) / 1.2f)) .add( t2DUpperArm.getHeight() * ((float) Math .sin((double) this.angleUppArmL)), t2DUpperArm.getHeight() * ((float) Math .cos((double) this.angleUppArmL)))); this.lowerArmR = new BodyPart( t2DLowerArm, (this.position.sub(0f, ((float) t2DTorso.getHeight()) / 1.2f)) .add( t2DUpperArm.getHeight() * ((float) Math .sin((double) this.angleUppArmR)), t2DUpperArm.getHeight() * ((float) Math .cos((double) this.angleUppArmR)))); this.upperLegL = new BodyPart(t2DUpperLeg, this.position); this.upperLegR = new BodyPart(t2DUpperLeg, this.position); this.lowerLegL = new BodyPart( t2DLowerLeg, this.position .add( t2DUpperLeg.getHeight() * ((float) Math .sin((double) this.angleUppLegL)), (t2DUpperLeg.getHeight() * 0.8f) * ((float) Math .cos((double) this.angleUppLegL)))); this.lowerLegR = new BodyPart( t2DLowerLeg, this.position .add( t2DUpperLeg.getHeight() * ((float) Math .sin((double) this.angleUppLegR)), (t2DUpperLeg.getHeight() * 0.8f) * ((float) Math .cos((double) this.angleUppLegR)))); this.torso.origin = new Vector2f((float) (t2DTorso.getWidth() / 2), (float) t2DTorso.getHeight()); this.upperArmL.origin = new Vector2f((float) (t2DUpperArm.getWidth() / 2), 0f); this.upperArmR.origin = new Vector2f((float) (t2DUpperArm.getWidth() / 2), 0f); this.lowerArmL.origin = new Vector2f((float) (t2DLowerArm.getWidth() / 2), 4f); this.lowerArmR.origin = new Vector2f((float) (t2DLowerArm.getWidth() / 2), 4f); this.upperLegL.origin = new Vector2f((float) (t2DUpperLeg.getWidth() / 2), 6f); this.upperLegR.origin = new Vector2f((float) (t2DUpperLeg.getWidth() / 2), 6f); this.lowerLegL.origin = new Vector2f((float) t2DUpperLeg.getWidth(), 6f); this.lowerLegR.origin = new Vector2f((float) t2DUpperLeg.getWidth(), 6f); this.bodyPartList = new java.util.ArrayList<BodyPart>(); this.bodyPartList.add(this.lowerLegL); this.bodyPartList.add(this.lowerLegR); this.bodyPartList.add(this.upperLegL); this.bodyPartList.add(this.upperLegR); this.bodyPartList.add(this.torso); this.bodyPartList.add(this.head); this.bodyPartList.add(this.lowerArmL); this.bodyPartList.add(this.lowerArmR); this.bodyPartList.add(this.upperArmL); this.bodyPartList.add(this.upperArmR); }
public void setOffset(TileMap tile, float sx, float sy) { offset.set(sx, sy); tile.setOffset(offset); }
public LNJumpBy reverse() { return Action(_duration, _delta.negate(), _height, _jumps); }
@Override public int collide(PShape s1, PShape s2, PContact[] cs) { if (s1._type != PShapeType.CIRCLE_SHAPE || s2._type != PShapeType.CONVEX_SHAPE && s2._type != PShapeType.BOX_SHAPE) { return 0; } PCircleShape c1 = (PCircleShape) s1; PConvexPolygonShape p1 = (PConvexPolygonShape) s2; float distance = -1F; int edgeNumber = -1; Vector2f vers[] = p1.vers; int numVers = p1.numVertices; Vector2f normal = new Vector2f(); Vector2f edgeNormal = new Vector2f(); Vector2f a = new Vector2f(); Vector2f b = new Vector2f(); int num = 0; for (int i = 0; i < numVers; i++) { a.set(c1._pos.x - vers[i].x, c1._pos.y - vers[i].y); distance = a.length(); distance -= c1.rad; if (distance <= 0.0F) { PContact c = new PContact(); c.overlap = distance; a.normalize(); c.normal.set(a.x, a.y); c.pos.set(vers[i].x, vers[i].y); cs[num] = c; if (++num == 2) { return num; } } } if (num > 0) { return num; } for (int i = 0; i < numVers; i++) { Vector2f ver = vers[i]; Vector2f nextVer = vers[(i + 1) % numVers]; float edgeX = nextVer.x - ver.x; float edgeY = nextVer.y - ver.y; edgeNormal.set(edgeY, -edgeX); edgeNormal.normalize(); a.set(c1._pos.x - ver.x, c1._pos.y - ver.y); b.set(c1._pos.x - nextVer.x, c1._pos.y - nextVer.y); if ((a.x * edgeX + a.y * edgeY) * (b.x * edgeX + b.y * edgeY) <= 0.0F) { float edgeLen = (float) Math.sqrt(edgeX * edgeX + edgeY * edgeY); float distanceToEdge = Math.abs(a.x * edgeY - a.y * edgeX) / edgeLen; if (distanceToEdge <= c1.rad) { distanceToEdge -= c1.rad; if (distance > distanceToEdge || distance == -1F) { edgeNumber = i; distance = distanceToEdge; normal.set(edgeNormal.x, edgeNormal.y); } } } } if (edgeNumber > -1) { PContact c = new PContact(); c.overlap = distance; c.normal = normal; c.pos = c1._pos.sub(normal.mul(c1.rad)); cs[0] = c; return 1; } boolean hit = true; for (int i = 0; i < numVers; i++) { Vector2f ver = vers[i]; Vector2f nextVer = vers[(i + 1) % numVers]; float v1x = nextVer.x - ver.x; float v1y = nextVer.y - ver.y; float v2x = c1._pos.x - ver.x; float v2y = c1._pos.y - ver.y; if (v1x * v2y - v1y * v2x >= 0.0F) { continue; } hit = false; break; } if (hit) { distance = 1.0F; normal = new Vector2f(); for (int i = 0; i < numVers; i++) { Vector2f ver = vers[i]; Vector2f nextVer = vers[(i + 1) % numVers]; a.set(nextVer.x - ver.x, nextVer.y - ver.y); a.normalize(); float d = c1._pos.sub(ver).cross(a); if (d < 0.0F && (distance == 1.0F || distance < d)) { distance = d; normal.set(a.y, -a.x); } } if (distance != 1.0F) { PContact c = new PContact(); c.normal.set(normal.x, normal.y); c.pos.set(c1._pos.x, c1._pos.y); c.overlap = distance; cs[0] = c; return 1; } } return 0; }
public void setPrevPosition(Vector2f value) { previousPosition.set(value); }
public void setPosition(float x, float y) { previousPosition.set(position); position.set(x, y); }
public Vector2f getLocalPosition() { return _localPos.clone(); }
public Vector2f getPosition() { return _pos.clone(); }