@Override public boolean shouldCollide (Fixture fixtureA, Fixture fixtureB) { if ((fixtureA == m_platform && fixtureB == m_character) || (fixtureB == m_platform && fixtureA == m_character)) { Vector2 position = m_character.getBody().getPosition(); if (position.y < m_top + m_radius - 3.0f * 0.005f) return false; else return true; } else return true; }
/** Initialize the bodies and offsets using the current transforms. */ public void initialize (Body body1, Body body2) { this.bodyA = body1; this.bodyB = body2; this.linearOffset.set(bodyA.getLocalPoint(bodyB.getPosition())); this.angularOffset = bodyB.getAngle() - bodyA.getAngle(); }
/** Initialize the bodies and offsets using the current transforms. */ public void initialize (Body body1, Body body2) { this.bodyA = body1; this.bodyB = body2; this.linearOffset.set(bodyA.getLocalPoint(bodyB.getPosition())); this.angularOffset = bodyB.getAngle() - bodyA.getAngle(); }
protected void renderBody (Body body) { Transform transform = body.getTransform(); for (Fixture fixture : body.getFixtureList()) { if (drawBodies) { drawShape(fixture, transform, getColorByBody(body)); if (drawVelocities) { Vector2 position = body.getPosition(); drawSegment(position, body.getLinearVelocity().add(position), VELOCITY_COLOR); } } if (drawAABBs) { drawAABB(fixture, transform); } } }
private boolean isPlayerGrounded (float deltaTime) { groundedPlatform = null; Array<Contact> contactList = world.getContactList(); for (int i = 0; i < contactList.size; i++) { Contact contact = contactList.get(i); if (contact.isTouching() && (contact.getFixtureA() == playerSensorFixture || contact.getFixtureB() == playerSensorFixture)) { Vector2 pos = player.getPosition(); WorldManifold manifold = contact.getWorldManifold(); boolean below = true; for (int j = 0; j < manifold.getNumberOfContactPoints(); j++) { below &= (manifold.getPoints()[j].y < pos.y - 1.5f); } if (below) { if (contact.getFixtureA().getUserData() != null && contact.getFixtureA().getUserData().equals("p")) { groundedPlatform = (Platform)contact.getFixtureA().getBody().getUserData(); } if (contact.getFixtureB().getUserData() != null && contact.getFixtureB().getUserData().equals("p")) { groundedPlatform = (Platform)contact.getFixtureB().getBody().getUserData(); } return true; } return false; } } return false; }
@Override public void render () { Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); cam.position.set(player.getPosition().x, player.getPosition().y, 0); cam.update(); renderer.render(world, cam.combined); Vector2 pos = player.getPosition(); boolean grounded = isPlayerGrounded(Gdx.graphics.getDeltaTime()); if (grounded) {
for (int i = 0; i < boxes.size(); i++) { Body box = boxes.get(i); Vector2 position = box.getPosition(); // that's the box's center position float angle = MathUtils.radiansToDegrees * box.getAngle(); // the rotation angle around the center batch.draw(textureRegion, position.x - 1, position.y - 1, // the bottom left corner of the box, unrotated
public void draw(SpriteBatch batch) { batch.draw( texture, playerBody.getPosition().x - (PLAYER_WIDTH * .5f), playerBody.getPosition().y - (PLAYER_HEIGHT * .5f), PLAYER_WIDTH, PLAYER_HEIGHT); }
@Override public void draw(IFieldRenderer renderer) { float px = bumperBody.getPosition().x; float py = bumperBody.getPosition().y; renderer.fillCircle(px, py, radius, currentColor(DEFAULT_COLOR)); } }
public TiledMapTileLayer.Cell getCell(){ TiledMapTileLayer layer = (TiledMapTileLayer) map.getLayers().get(1); return layer.getCell((int)(body.getPosition().x * MarioBros.PPM / 16), (int)(body.getPosition().y * MarioBros.PPM / 16)); }
Vector2 impulseForBall(Ball ball) { if (this.kick <= 0.01f) return null; // Compute unit vector from center of bumper to ball, and scale by kick value to get impulse. Vector2 ballpos = ball.getPosition(); Vector2 thisPos = bumperBody.getPosition(); float ix = ballpos.x - thisPos.x; float iy = ballpos.y - thisPos.y; float mag = (float)Math.hypot(ix, iy); float scale = this.kick / mag; return new Vector2(ix*scale, iy*scale); }
@Override public void saveStateTo (EntityRenderState state) { state.position.set(body.getPosition()); state.orientation = body.getAngle(); }
@Override public void setWorldPosMt (Vector2 worldPosition, float orientationRads) { super.setWorldPosMt(worldPosition, orientationRads); previousPosition.set(body.getPosition()); }
@Override public void update(float dt) { setRegion(getFrame(dt)); if(currentState == State.STANDING_SHELL && stateTime > 5){ currentState = State.WALKING; velocity.x = 1; System.out.println("WAKE UP SHELL"); } setPosition(b2body.getPosition().x - getWidth() / 2, b2body.getPosition().y - 8 /MarioBros.PPM); b2body.setLinearVelocity(velocity); }
RotatingGroup createRotatingGroup(Field field, String centerID, String[] ids, double speed) { FieldElement centerElement = field.getFieldElementById(centerID); Vector2 centerPosition = centerElement.getBodies().get(0).getPosition(); return RotatingGroup.create(field, ids, centerPosition.x, centerPosition.y, speed); }
@Override public void update(float dt) { super.update(dt); setPosition(body.getPosition().x - getWidth() / 2, body.getPosition().y - getHeight() / 2); velocity.y = body.getLinearVelocity().y; body.setLinearVelocity(velocity); } }
/** Initialize the bodies and offsets using the current transforms. */ public void initialize (Body body1, Body body2) { this.bodyA = body1; this.bodyB = body2; this.linearOffset.set(bodyA.getLocalPoint(bodyB.getPosition())); this.angularOffset = bodyB.getAngle() - bodyA.getAngle(); }
protected void updateBody() { if (body == null || staticLight) return; final Vector2 vec = body.getPosition(); float angle = body.getAngle(); final float cos = MathUtils.cos(angle); final float sin = MathUtils.sin(angle); final float dX = bodyOffsetX * cos - bodyOffsetY * sin; final float dY = bodyOffsetX * sin + bodyOffsetY * cos; start.x = vec.x + dX; start.y = vec.y + dY; setDirection(bodyAngleOffset + angle * MathUtils.radiansToDegrees); }
public void draw(IFieldRenderer renderer) { CircleShape shape = (CircleShape)body.getFixtureList().get(0).getShape(); Vector2 center = body.getPosition(); float radius = shape.getRadius(); renderer.fillCircle(center.x, center.y, radius, primaryColor); // Draw a smaller circle to show the ball's rotation. float angle = body.getAngle(); float smallCenterX = center.x + (radius / 2) * MathUtils.cos(angle); float smallCenterY = center.y + (radius / 2) * MathUtils.sin(angle); renderer.fillCircle(smallCenterX, smallCenterY, radius / 4, secondaryColor); }
@Override public boolean touchDown (int x, int y, int pointer, int button) { // Screen coordinates to world coordinates viewport.getCamera().unproject(point.set(x, y, 0)); if (button == Input.Buttons.LEFT) { float force = 100f * player1.getBody().getMass(); Vector2 target = new Vector2(point.x, point.y); Vector2 direction = target.sub(player1.getBody().getPosition()); player1.getBody().applyForceToCenter(direction.scl(force), true); } return false; }