com.badlogic.gdx.math.Circle Java Examples
The following examples show how to use
com.badlogic.gdx.math.Circle.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BoundsSystem.java From Entitas-Java with MIT License | 6 votes |
@Override public void execute(float deltatime) { CoreEntity ball = _context.getBallEntity(); Circle ballShape = (Circle) ball.getView().shape; Motion motion = ball.getMotion(); for (CoreEntity e : _groupPlayer.getEntities()) { Player player = e.getPlayer(); Score score = e.getScore(); if (ballShape.x + ballShape.radius <= -(WIDTH / 2) && player.id == Player.ID.PLAYER2) restart(ballShape, motion, score); if (ballShape.x - ballShape.radius >= (WIDTH / 2) && player.id == Player.ID.PLAYER1) restart(ballShape, motion, score); } }
Example #2
Source File: ContactSystem.java From Entitas-Java with MIT License | 6 votes |
@Override public void execute(float deltatime) { CoreEntity ball = _context.getBallEntity(); Circle ballShape = (Circle) ball.getView().shape; Motion ballMotion = ball.getMotion(); if (ballShape.y - ballShape.radius <= -(Pong.SCREEN_HEIGHT / 2)) { ballShape.setY(-(Pong.SCREEN_HEIGHT / 2) + ballShape.radius); ballMotion.velocity.y = -(ballMotion.velocity.y + 10); ballMotion.velocity.x = ballMotion.velocity.x + 10; } if (ballShape.y + ballShape.radius >= (Pong.SCREEN_HEIGHT / 2)) { ballShape.setY((Pong.SCREEN_HEIGHT / 2) - ballShape.radius); ballMotion.velocity.y = -(ballMotion.velocity.y + 10); ballMotion.velocity.x = ballMotion.velocity.x + 10; } for (CoreEntity e : _group.getEntities()) { View view = e.getView(); circleRectCollision(ballShape, (Rectangle) view.shape, ballMotion); } }
Example #3
Source File: MoveSystem.java From Entitas-Java with MIT License | 6 votes |
@Override public void execute(float deltatime) { for (CoreEntity e : _group.getEntities()) { Motion motion = e.getMotion(); View view = e.getView(); if (view.shape instanceof Rectangle) { Rectangle ret = (Rectangle) view.shape; ret.setPosition(ret.x + motion.velocity.x * Gdx.graphics.getDeltaTime(), ret.y + motion.velocity.y * Gdx.graphics.getDeltaTime()); } else { Circle circle = (Circle) view.shape; circle.setPosition(circle.x + motion.velocity.x * Gdx.graphics.getDeltaTime() , circle.y + motion.velocity.y * Gdx.graphics.getDeltaTime()); } } }
Example #4
Source File: RectangleCircleCollisionScreen.java From ud406 with MIT License | 6 votes |
private boolean areColliding(Rectangle rectangle, Circle circle) { // TODO: Complete this function! boolean containsACorner = circle.contains(rectangle.x, rectangle.y) || // Bottom left circle.contains(rectangle.x + rectangle.width, rectangle.y) || // Bottom right circle.contains(rectangle.x + rectangle.width, rectangle.y + rectangle.height) || // Top Right circle.contains(rectangle.x, rectangle.y + rectangle.height); // Top left boolean inHorizontalInterval = rectangle.x < circle.x && circle.x < rectangle.x + rectangle.width; boolean inVerticalInterval = rectangle.y < circle.y && circle.y < rectangle.y + rectangle.height; boolean inHorizontalNeighborhood = rectangle.x - circle.radius < circle.x && circle.x < rectangle.x + rectangle.width + circle.radius; boolean inVerticalNeighborhood = rectangle.y - circle.radius < circle.y && circle.y < rectangle.y + rectangle.height + circle.radius; boolean touchingAnEdge = inHorizontalInterval && inVerticalNeighborhood || inHorizontalNeighborhood && inVerticalInterval; return containsACorner || touchingAnEdge; }
Example #5
Source File: ContactSystem.java From Entitas-Java with MIT License | 5 votes |
public void circleRectCollision(Circle circle, Rectangle rectangle, Motion ballMotion) { temp.set(circle.x - circle.radius, circle.y + circle.radius, circle.radius * 2, circle.radius * 2); if (temp.overlaps(rectangle)) { if (ballMotion.velocity.x <= 0) circle.setX(rectangle.x + rectangle.width + circle.radius); if (ballMotion.velocity.x >= 0) circle.setX(rectangle.x - rectangle.width + circle.radius); ballMotion.velocity.x = (float) -(ballMotion.velocity.x * 1.05); ballMotion.velocity.y = (float) (ballMotion.velocity.y * 1.05); } }
Example #6
Source File: PongState.java From Entitas-Java with MIT License | 5 votes |
@Override public void initialize() { // Input Camera camera = engine.getManager(BaseSceneManager.class).getDefaultCamera(); Batch batch = engine.getManager(BaseSceneManager.class).getBatch(); BitmapFont font = engine.getManager(BaseGUIManager.class).getDefaultFont(); context.core.createEntity() .addBall(false) .addView(new Circle(0, 0, 8)) .addMotion(MathUtils.clamp(1, 230, 300), 300); context.core.createEntity() .addPlayer(Player.ID.PLAYER1) .addScore("Player 1: ", 180, 470) .addView(new Rectangle(-350, 0, Pong.PLAYER_WIDTH, Pong.PLAYER_HEIGHT)) .addMotion(0, 0); context.core.createEntity() .addPlayer(Player.ID.PLAYER2) .addScore("Player 2: ", 480, 470) .addView(new Rectangle(350, 0, Pong.PLAYER_WIDTH, Pong.PLAYER_HEIGHT)) .addMotion(0, 0); systems.add(new InputSystem(context.core)) .add(new ContactSystem(context.core)) .add(new BoundsSystem(context.core)) .add(new MoveSystem(context.core)) .add(new RendererSystem(context.core, engine.sr, camera, batch, font)); }
Example #7
Source File: WorldBodyUtils.java From killingspree with MIT License | 5 votes |
public WorldBodyUtils(WorldManager worldManager) { circle = new Circle(); this.worldManager = worldManager; entities = new ArrayList<ServerEntity>(); audio = worldManager.audio; this.world = worldManager.getWorld(); tempPlayerPosition = new Vector2(); }
Example #8
Source File: BoundsSystem.java From Entitas-Java with MIT License | 4 votes |
private void restart(Circle ballShape, Motion ballMotion, Score score) { score.points += 10; ballShape.setPosition(0, 0); ballMotion.velocity.set(MathUtils.clamp(1, 230, 300), 300); ballMotion.velocity.x *= -1; }
Example #9
Source File: OscillatingCircle.java From ud406 with MIT License | 4 votes |
public Circle getCurrentCircle(float elapsedTime) { float x = originX + magnitude * MathUtils.cos(angle) * MathUtils.sin(MathUtils.PI2 * elapsedTime / period); float y = originY + magnitude * MathUtils.sin(angle) * MathUtils.sin(MathUtils.PI2 * elapsedTime / period); return new Circle(x, y, radius); }
Example #10
Source File: OscillatingCircle.java From ud406 with MIT License | 4 votes |
public Circle getCurrentCircle(float elapsedTime) { float x = originX + magnitude * MathUtils.cos(angle) * MathUtils.sin(MathUtils.PI2 * elapsedTime / period); float y = originY + magnitude * MathUtils.sin(angle) * MathUtils.sin(MathUtils.PI2 * elapsedTime / period); return new Circle(x, y, radius); }
Example #11
Source File: RectangleCircleCollisionScreen.java From ud406 with MIT License | 2 votes |
private boolean areColliding(Rectangle rectangle, Circle circle) { // TODO: Complete this function! return false; }