public void tick() { if (!mIsStatic) { changeVelocity(); mCurPosition = new Position( mCurPosition.getPositionX(), mCurPosition.getPositionY() + mVelocity.getVelocityY()); collider.setPosition(mCurPosition); } }
public boolean intersects(Collider c, boolean flag) { boolean colliding = false; if (c.getLayer() != layer) return false; Vec2[] vertices = { pos, Vec2.add(pos, new Vec2(0, size.y())), Vec2.add(pos, size), Vec2.add(pos, new Vec2(size.x(), 0)) }; if (c instanceof QuadCollider) { QuadCollider qc = (QuadCollider) c; if (!flag && qc.intersects(this, true)) return true; for (int i = 0; i < vertices.length; i++) { float x = vertices[i].x(); float y = vertices[i].y(); if (x >= qc.bottomLeft().x() && x <= qc.topRight().x() && y <= qc.topRight().y() && y >= qc.bottomLeft().y()) { colliding = true; break; } } } else if (c instanceof CircleCollider) { CircleCollider cc = (CircleCollider) c; Vec2 distV = Vec2.sub(center, cc.getPos()); Vec2 rad = Vec2.mult(distV, Vec2.REV); rad.normalize(); rad.mult(new Vec2(cc.getR(), cc.getR())); distV.add(rad); distV.add(center); if (distV.x() >= bottomLeft().x() && distV.x() <= topRight().x() && distV.y() >= bottomLeft().y() && distV.y() <= topRight().y()) { colliding = true; } else if (cc.getPos().x() >= bottomLeft().x() && cc.getPos().x() <= topRight().x() && cc.getPos().y() >= bottomLeft().y() && cc.getPos().y() <= topRight().y()) colliding = true; } return colliding; }