List of usage examples for com.badlogic.gdx.math Vector2 set
public Vector2 set(float x, float y)
From source file:com.turbogerm.helljump.game.character.states.NormalCharacterState.java
License:Open Source License
private void handleCollisionWithPlatform(Vector2 position, Vector2 speed, float visibleAreaPosition, PlatformToCharCollisionData platformToCharCollisionData, Array<RiseSection> activeRiseSections, Array<PlatformBase> visiblePlatforms, CharacterEffects characterEffects, float delta) { if (!platformToCharCollisionData.isCollision) { Vector2 cpNext = Pools.obtainVector(); cpNext.set(position.x + speed.x * delta, position.y + speed.y * delta); Vector2 intersection = Pools.obtainVector(); if (isCollisionWithPlatform(visiblePlatforms, position, cpNext, intersection, mCharCollisionData)) { position.set(intersection);/* w w w. j av a 2s . com*/ handleFall(position, speed, visibleAreaPosition, characterEffects); if (!mIsDying) { handleCollisionWithPlatform(position, speed, activeRiseSections, characterEffects); } } else { position.set(cpNext); handleFall(position, speed, visibleAreaPosition, characterEffects); speed.y = Math.max(speed.y - GameCharacter.GRAVITY * delta, -GameCharacter.JUMP_SPEED); } Pools.freeVector(cpNext); Pools.freeVector(intersection); } else { position.y = platformToCharCollisionData.collisionPoint.y; mCharCollisionData.collisionPlatform = platformToCharCollisionData.collisionPlatform; mCharCollisionData.collisionPointX = platformToCharCollisionData.collisionPoint.x; handleFall(position, speed, visibleAreaPosition, characterEffects); if (!mIsDying) { handleCollisionWithPlatform(position, speed, activeRiseSections, characterEffects); } } }
From source file:com.turbogerm.helljump.game.GameActiveAreaObjects.java
License:Open Source License
private void updatePlatforms(GameCharacter character, float delta) { Vector2 c1 = Pools.obtainVector(); Vector2 c2 = Pools.obtainVector(); mPlatformToCharCollisionData.reset(); Vector2 charPosition = character.getPosition(); c1.set(charPosition.x + GameCharacter.COLLISION_WIDTH_OFFSET - PlatformData.PLATFORM_WIDTH, charPosition.y); c2.set(charPosition.x + GameCharacter.COLLISION_LINE_LENGTH, charPosition.y); // only check for collision when character is going down mPlatformToCharCollisionData.isEnabled = character.getSpeed().y < 0.0f; for (RiseSection riseSection : mActiveRiseSections) { Array<PlatformBase> platforms = riseSection.getPlatforms(); for (PlatformBase platform : platforms) { platform.update(delta, c1, c2, mPlatformToCharCollisionData); }//from w w w .ja v a2 s.c o m } Pools.freeVector(c1); Pools.freeVector(c2); }
From source file:com.turbogerm.helljump.game.platforms.PlatformBase.java
License:Open Source License
public final void update(float delta, Vector2 c1, Vector2 c2, PlatformToCharCollisionData collisionData) { // if platform can move up, additional platform to char collision must be checked if (mHasVerticalMovement && collisionData.isEnabled) { Vector2 position = getPosition(); Vector2 p1 = Pools.obtainVector(); p1.set(position.x, position.y + PlatformData.PLATFORM_HEIGHT); updateImpl(delta, c1, c2, collisionData); position = getPosition();/* w ww .java 2 s . c o m*/ Vector2 p2 = Pools.obtainVector(); p2.set(position.x, position.y + PlatformData.PLATFORM_HEIGHT); // only check for collision when platform is going up, and character is going down if (p2.y > p1.y) { collisionData.isCollision = Intersector.intersectSegments(c1, c2, p1, p2, collisionData.collisionPoint); if (collisionData.isCollision) { collisionData.collisionPlatform = this; collisionData.collisionPoint.y = p2.y; } } Pools.freeVector(p1); Pools.freeVector(p2); } else { updateImpl(delta, c1, c2, collisionData); } }
From source file:com.turbogerm.helljump.game.platforms.PlatformBase.java
License:Open Source License
public boolean isCollision(Vector2 c1, Vector2 c2, Vector2 intersection) { Vector2 position = getPosition(); Vector2 p1 = Pools.obtainVector(); Vector2 p2 = Pools.obtainVector(); float pY = position.y + PlatformData.PLATFORM_HEIGHT; p1.set(position.x - GameCharacter.COLLISION_LINE_LENGTH, pY); p2.set(position.x + PlatformData.PLATFORM_WIDTH - GameCharacter.COLLISION_WIDTH_OFFSET, pY); boolean isIntersection = Intersector.intersectSegments(c1, c2, p1, p2, intersection); Pools.freeVector(p1);//w w w .j a va 2s. co m Pools.freeVector(p2); return isIntersection; }
From source file:com.vlaaad.dice.game.world.controllers.ViewController.java
License:Open Source License
public Vector2 stageToWorldCoordinates(Vector2 input) { root.stageToLocalCoordinates(input); input.scl(1 / ViewController.CELL_SIZE); int x = MathUtils.floor(input.x); int y = MathUtils.floor(input.y); if (input.x < 0) { x = -Math.abs(x);/*from w ww .ja v a 2 s.com*/ } if (input.y < 0) { y = -Math.abs(y); } input.set(x, y); return input; }
From source file:de.homelab.madgaksha.lotsofbs.bettersprite.CroppableSprite.java
License:Apache License
public void getCropX(Vector2 cropX) { cropX.set(cropLeft, cropRight); }
From source file:de.homelab.madgaksha.lotsofbs.bettersprite.CroppableSprite.java
License:Apache License
public void getCropY(Vector2 cropY) { cropY.set(cropBottom, cropTop); }
From source file:de.philweb.bubblr.TiledMapHelper.java
License:Apache License
public ArrayList<Vector2> getCharacterList(String ID, float pixelPerMeter) { ArrayList<Vector2> objectList = new ArrayList<Vector2>(); // Gdx.app.log("ID", "" + ID); int anz_objectGroups = getMap().objectGroups.size(); for (int counter_groups = 0; counter_groups < anz_objectGroups; counter_groups++) { if (getMap().objectGroups.get(counter_groups).name.equals(ID)) { int anz_objekte = getMap().objectGroups.get(counter_groups).objects.size(); for (int counter = 0; counter < anz_objekte; counter++) { float x = getMap().objectGroups.get(counter_groups).objects.get(counter).x / pixelPerMeter; float y = (480 - getMap().objectGroups.get(counter_groups).objects.get(counter).y) / pixelPerMeter; Vector2 objekt = new Vector2(); objekt.set(x, y); // TODO objectList.add(objekt);//from ww w .j ava 2s . c o m } } } return objectList; }
From source file:es.eucm.ead.editor.view.builders.scene.groupeditor.GroupEditor.java
License:Open Source License
/** * @return if there was any element in the given coordinates *//*from w w w.j ava 2s . c om*/ public boolean selectLayer(float x, float y) { layersTouched.clear(); Vector2 origin = Pools.obtain(Vector2.class); Vector2 size = Pools.obtain(Vector2.class); Vector2 tmp = Pools.obtain(Vector2.class); Polygon polygon = Pools.obtain(Polygon.class); for (Actor actor : editedGroup.getChildren()) { EngineUtils.calculateBounds(actor, origin, size); int j = 0; for (int i = 0; i < 4; i++) { tmp.set(i == 0 || i == 3 ? origin.x : origin.x + size.x, i > 1 ? origin.y : origin.y + size.y); actor.localToAscendantCoordinates(this, tmp); points[j++] = tmp.x; points[j++] = tmp.y; } polygon.setVertices(points); if (polygon.contains(x, y)) { layersTouched.add(actor); } else { for (int i = 0; i < 8; i += 2) { if (nearEnough(x, y, points[i], points[i + 1])) { layersTouched.add(actor); break; } } } } Pools.free(polygon); Pools.free(tmp); Pools.free(origin); Pools.free(size); if (layersTouched.size > 0) { showLayerSelector(x, y); return true; } return false; }
From source file:es.eucm.ead.editor.view.widgets.groupeditor.GroupEditor.java
License:Open Source License
public void getViewPortCenter(Vector2 center) { center.set(getWidth() / 2.0f, getHeight() / 2.0f); localToDescendantCoordinates(groupEditorDragListener.getContainer(), center); }