public int splitCollision(float x, float y) { Circle touchCircle = new Circle(); touchCircle.radius = 5f; touchCircle.setPosition(x, y); if(touchCircle.contains(splitPositions[0], touchCircle.y)) { return 0; } if(touchCircle.contains(splitPositions[1], touchCircle.y)) { return 1; } if(touchCircle.contains(touchCircle.x, splitPositions[2])) { return 2; } if(touchCircle.contains(touchCircle.x, splitPositions[3])) { return 3; } return -1; }
private void initBall() { float radius = 26; mBall = new Circle(0.f, 0.f, radius); mBallTextureRegion = new TextureRegion(new Texture(Gdx.files.internal("ball.png"))); // create physics body BodyDef bodyDef = new BodyDef(); bodyDef.type = BodyDef.BodyType.DynamicBody; bodyDef.position.set(mBall.x, mBall.y); CircleShape ballShape = new CircleShape(); ballShape.setRadius(mBall.radius - 2.f); mBallBody = mWorld.createBody(bodyDef); mBallBody.setUserData(new BodyUserDate(BODY_USER_DATA_TYPE_BALL)); Fixture fixture = mBallBody.createFixture(ballShape, 0.5f); fixture.setFriction(BALL_FRICTION_BASE); fixture.setRestitution(0.4f); ballShape.dispose(); }
public Caterpillar(ShapeRenderer renderer, Vector2 position,boolean facingRight) { super(renderer, position, facingRight); float x = position.x - 4 *CATERPILLAR_TIGHT_RADIUS; float y = position.y; circles = new Array<Circle>(); for ( int i = 0 ; i< CATERPILLAR_CIRCLES_NUMBER; i++) { circles.add(new Circle(x, y, CATERPILLAR_RADIUS)); x += 2 * CATERPILLAR_TIGHT_RADIUS; } if (facingRight) { velocity.set(CATERPILLAR_SPEED_X, 0f); } else{ velocity.set(-CATERPILLAR_SPEED_X, 0f); } nanotimeAnimationStart = TimeUtils.nanoTime(); eye = new Vector2(); }
public Cat(ShapeRenderer renderer, Boolean facingRight) { super(renderer, new Vector2(), facingRight); if (facingRight) { position.set(CAT_START_X_LEFT, CAT_Y); velocity.set(CAT_SPEED_X, 0f); } else{ position.set(CAT_START_X_RIGHT, CAT_Y); velocity.set(-CAT_SPEED_X, 0f); } catCreateMillis = TimeUtils.millis(); circle = new Circle(0,0, CAT_HEAD_RADIUS); rectangle = new Rectangle(0,0, CAT_BODY_LENGTH, CAT_BODY_WIDTH); update(0); }
private Vector2 getPositionFromMapObject(MapObject mapObject) { if (mapObject instanceof PolygonMapObject) { Polygon polygon = ((PolygonMapObject) mapObject).getPolygon(); return new Vector2(polygon.getX(), polygon.getY()); } else if (mapObject instanceof RectangleMapObject) { Rectangle rectangle = ((RectangleMapObject) mapObject).getRectangle(); return new Vector2(rectangle.getX(), rectangle.getY()); } else if (mapObject instanceof EllipseMapObject) { Ellipse ellipse = ((EllipseMapObject) mapObject).getEllipse(); return new Vector2(ellipse.x, ellipse.y); } else if (mapObject instanceof CircleMapObject) { Circle circle = ((CircleMapObject) mapObject).getCircle(); return new Vector2(circle.x, circle.y); } throw new GdxRuntimeException("Only Polygons, Rectangles, Ellipses and Circles are supported!"); }
@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); } }
@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); } }
@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()); } } }
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; }
public Meteorite(float x, float y, float scrollSpeed) { super(x, y, 0, 0, scrollSpeed); meteor= new Circle(); //alfa = new Random(); altura = new Random(); radius=new Random(); //increm = (float)((alfa.nextInt(4000)-2000)/1000); /* if((int)increm==0) this.height = altura.nextInt(100); else if((int)increm==-1) this.height = altura.nextInt(50)-50; else if((int)increm==1) this.height = altura.nextInt(50)+50; else this.height = altura.nextInt(100); */ this.height = altura.nextInt(100); this.width = radius.nextInt(15)+5; }
public PhysicalObject(float x, float y, float offsetX, float offsetY, String textureName, IRTSMap map) { super(x, y); this.map = map; this.shapeRenderer = RTSGame.game.cameraShapeRenderer; this.textureName = textureName; this.spriteOffsetX = offsetX; this.spriteOffsetY = offsetY; initGraphics(); initHardRadius(height / 2f); // Default soft radius of 5 softRadius = new Circle(x, y, 10); // Default shadow shadowA = 15f; shadowB = 4f; // Add to map, just once (these entities do not move) map.updateEntity(this); }
public ThirdScreen (Game agame) { game = agame; batch = new SpriteBatch(); img = new Texture("aklu.jpg"); shapeRenderer = new ShapeRenderer(); centerCircle = new Circle(); leftCircle = new Circle(); rightCircle = new Circle(); myTouch = new Circle(); camera = new OrthographicCamera(); camera.setToOrtho(false, 800, 400); colorChanger = 0; counter = 0; }
public secondScreen (Game agame) { game = agame; batch = new SpriteBatch(); img = new Texture("aklu.jpg"); shapeRenderer = new ShapeRenderer(); centerCircle = new Circle(); leftCircle = new Circle(); rightCircle = new Circle(); myTouch = new Circle(); camera = new OrthographicCamera(); camera.setToOrtho(false, 800, 400); colorChanger = 0; counter = 0; }
@Override public void create () { batch = new SpriteBatch(); img = new Texture("aklu.jpg"); shapeRenderer = new ShapeRenderer(); centerCircle = new Circle(); leftCircle = new Circle(); rightCircle = new Circle(); myTouch = new Circle(); camera = new OrthographicCamera(); camera.setToOrtho(false, 800, 400); colorChanger = 0; }
public boolean overlaps(BoundsComponent other) { if (getBounds() instanceof Rectangle && other.getBounds() instanceof Rectangle) { return Intersector.overlaps((Rectangle) getBounds(), (Rectangle) other.getBounds()); } else if (getBounds() instanceof Circle && other.getBounds() instanceof Circle) { return Intersector.overlaps((Circle) getBounds(), (Circle) other.getBounds()); } else if (getBounds() instanceof Circle && other.getBounds() instanceof Rectangle) { return Intersector.overlaps((Circle) getBounds(), (Rectangle) other.getBounds()); } else if (getBounds() instanceof Rectangle && other.getBounds() instanceof Circle) { return Intersector.overlaps((Circle) other.getBounds(), (Rectangle) getBounds()); } throw new RuntimeException("Cannot compare " + this.getBounds() + " and " + other.getBounds()); }
private void doCollision2(Entity entity, Entity other) { CollisionComponent thisCollision = collisionMapper.get(entity); MovementComponent entityMovement = movementMapper.get(entity); CollisionComponent otherCollision = collisionMapper.get(other); MovementComponent otherMovement = movementMapper.get(other); Vector2 thisVelocityTmp = new Vector2(entityMovement.velocity); Vector2 otherVelocity = otherMovement.velocity; BoundsComponent bounds = boundsMapper.get(entity); BoundsComponent otherBounds = boundsMapper.get(other); Circle thisCircle = (Circle) bounds.getBounds(); Circle otherCircle = (Circle) otherBounds.getBounds(); double distance = Math.sqrt(Math.pow((thisCircle.x) - (otherCircle.x), 2) + Math.pow((thisCircle.y) - (otherCircle.y), 2)); double normalizedX = (otherCircle.x - thisCircle.x) / distance; double normalizedY = (otherCircle.y - thisCircle.y) / distance; double p = 2 * (thisVelocityTmp.x * normalizedX + thisVelocityTmp.y * normalizedY - otherVelocity.x * normalizedX - otherVelocity.y * normalizedY) / (thisCollision.mass + otherCollision.mass); entityMovement.velocity.x = (float) (entityMovement.velocity.x - p * thisCollision.mass * normalizedX); entityMovement.velocity.y = (float) (entityMovement.velocity.y - p * thisCollision.mass * normalizedY); otherMovement.velocity.x = (float) (otherMovement.velocity.x - p * otherCollision.mass * normalizedX); otherMovement.velocity.y = (float) (otherMovement.velocity.y - p * otherCollision.mass * normalizedY); revertPosition(entity); revertPosition(other); }
private boolean isValidPosition(Entity entity) { TransformComponent transform = entity.getComponent(TransformComponent.class); positionObstacle(entity); for (Entity player : players) { Circle playerBounds = (Circle) player.getComponent(CircularBoundsComponent.class).getBounds(); if (playerBounds.radius > 0) { Circle spawnCircle = new Circle(playerBounds.x, playerBounds.y, playerBounds.radius + gameSettings.getPlayerNoSpawnRadius()); if (spawnCircle.contains(transform.position.x, transform.position.y)) { return false; } } } return true; }
public static PlayerCollisionData playerCollision() { Stream<Entry<ImmutableWrapper<Circle>, PlayerCollisionData>> stream = enemyJudges.entrySet().parallelStream(); mJudgeEntry = null; stream.forEach((entry) -> { if (entry.getValue().judgeCallback.getDamage() > 0 && entry.getKey().getData().contains(playerJudge)) { mJudgeEntry = entry; } }); stream.close(); return mJudgeEntry == null ? null : mJudgeEntry.getValue(); }
public static IJudgeCallback collideFriendlyBullets(Circle judge) { for (Iterator<Entry<ImmutableWrapper<LineSegment>, IJudgeCallback>> iterator = friendlyJudges.entrySet().iterator(); iterator.hasNext();) { Entry<ImmutableWrapper<LineSegment>, IJudgeCallback> pos = iterator.next(); if (pos.getKey().getData().intersectCircle(judge)) return pos.getValue(); } return null; }
public static void judgeEnemyHurt() { for (Iterator<Entry<ImmutableWrapper<Circle>, PlayerCollisionData>> iterator = enemyJudges.entrySet().iterator(); iterator.hasNext();) { Entry<ImmutableWrapper<Circle>, PlayerCollisionData> wrapper = iterator.next(); if (wrapper.getValue().judgeCallback.canHurt()) { IJudgeCallback callback = null; do { callback = collideFriendlyBullets(wrapper.getKey().getData()); if (callback != null) { callback.onCollide(); wrapper.getValue().judgeCallback.onHurt(callback.getDamage()); } } while (callback != null); } } }
public EnemyJudgeCircle(float radius, float biasX, float biasY, IJudgeCallback callback) { circle = new Circle(0, 0, radius); wrapper = ImmutableWrapper.wrap(circle); this.biasX = biasX; this.biasY = biasY; bias = new Vector2(); this.callback = callback; }
@Override public Circle read(Kryo kryo, Input input, Class<Circle> type) { float x = input.readFloat(); float y = input.readFloat(); float radius = input.readFloat(); return new Circle(x, y, radius); }
boolean hitbox(Circle eggLeft, Circle eggRight, Rectangle... rects) { return Intersector.overlaps(eggLeft, rects[0]) || Intersector.overlaps(eggRight, rects[1]) || Intersector.overlaps(rects[2], rects[0]) || Intersector.overlaps(rects[2], rects[1]) || Intersector.overlaps(rects[3], rects[0]) || Intersector.overlaps(rects[3], rects[1]); //rects[0] = frontPipe, rects[1] = backPipe, rects[2] = engines, rects[3] = body }
public void render(){ renderer.set(ShapeRenderer.ShapeType.Filled); renderer.setColor(CATERPILLAR_COLOR_BODY); for (Circle circle : circles) renderer.circle(circle.x, circle.y, circle.radius, POOP_SEGMENTS); renderer.setColor(Color.CORAL); renderer.circle(eye.x,eye.y + CATERPILLAR_EYE_Y_OFFSET, CATERPILLAR_EYE_RADIUS); }
@Override public Boolean hasCollisionWith(Bird bird){ for (Circle circle : circles) if (bird.bodyCircle.overlaps(circle)) return true; return false; }
public static FixtureBodyDefinition createCircleFixtureBodyDef(CircleMapObject object) { BodyDef bodyDef = new BodyDef(); Circle circle = object.getCircle(); bodyDef.position.x = circle.x; bodyDef.position.y = circle.y; bodyDef.position.scl(MainCamera.getInstance().getTileMapScale()); bodyDef.type = getBodyType(object); FixtureDef fixtureDef = getFixtureDefFromBodySkeleton(object); return new FixtureBodyDefinition(fixtureDef, bodyDef); }
private static Shape getCircleShape(MapObject object) { Circle circle = ((CircleMapObject)object).getCircle(); CircleShape shape = new CircleShape(); shape.setRadius(circle.radius * MainCamera.getInstance().getTileMapScale()); return shape; }
@Override public void apply() { owner.changeSpeed(speedBoost); Circle c = new Circle(owner.getX(), owner.getY(), echoRange); for (int i = 0; i < Wave.mobs.size; i++){ Mob m = Wave.mobs.get(i); if(c.contains(m.getPosition())){ m.addEffect(new CommandFaithBuff(aoeRange, speedBoost, duration).setOwner(m)); } } // }
@Override public boolean die(/*Tower source*/) { Circle dieAoe = new Circle(owner.getX(), owner.getY(), aoeRange); for (int i = 0; i < Wave.mobs.size; i++){ Mob m = Wave.mobs.get(i); if(dieAoe.contains(m.getPosition())){ m.addEffect(new CommandFaithBuff(aoeRange, speedBoost, duration).setOwner(m)); } } return false; }
@Override public void create () { batch = new SpriteBatch(); background = new Texture("bg.png"); shapeRenderer = new ShapeRenderer(); birdCircle = new Circle(); bitmapFont = new BitmapFont(); bitmapFont.setColor(Color.WHITE); bitmapFont.getData().setScale(10); gameover = new Texture("gameover.png"); birds = new Texture[2]; birds[0] = new Texture("bird.png"); birds[1] = new Texture("bird2.png"); birdY = Gdx.graphics.getHeight()/2 - birds[0].getHeight()/2; topTube = new Texture("toptube.png"); bottomTube = new Texture("bottomtube.png"); maxTubeOffset = Gdx.graphics.getHeight()/2 - gap/2 - 100; random = new Random(); distanceBetweenTubes = Gdx.graphics.getWidth() * 3/4; topTubeRectangles = new Rectangle[numberOfTubes]; bottomTubeRectangles = new Rectangle[numberOfTubes]; startGame(); }
public Bullet(boolean isPlayer, boolean flip, float direction) { isPlayerOwned = isPlayer; dir = direction; time = 0f; bound = new Circle(this.x, this.y, 2); sprite = new Sprite(Game.gfxMgr.getTexture("test", "bullet.png")); sprite.setOrigin(sprite.getWidth() / 2, sprite.getHeight() / 2); sprite.setRotation(direction); sprite.setFlip(flip, false); }
public Cog(boolean fallIn, float toX) { super(fallIn, toX); sprite = new Sprite(Game.gfxMgr.getTexture("test", "cog.png")); sprite.setOrigin(sprite.getWidth() / 2f, sprite.getHeight() / 2); this.bound = new Circle(this.x, this.y, 16); }
public Engine(boolean fallIn, float toX) { super(fallIn, toX); sprite = new Sprite(Game.gfxMgr.getTexture("test", "engine.png")); sprite.setOrigin(sprite.getWidth() / 2f, sprite.getHeight() / 2); emit = new ParticleEmitter(Game.gfxMgr.getParticleEffect("test", "boss.p").getEmitters().get(0)); emit.setPosition(this.x, this.y); laser = null; chargingMyLaser = false; this.bound = new Circle(this.x, this.y, 8); }
public Pully(boolean fallIn, float toX) { super(fallIn, toX); sprite = new Sprite(Game.gfxMgr.getTexture("test", "pully.png")); sprite.setOrigin(sprite.getWidth() / 2f, sprite.getHeight() / 2); this.bound = new Circle(this.x, this.y, 6); }
public Eye(boolean fallIn, float toX) { super(fallIn, toX); sprite = new Sprite(Game.gfxMgr.getTexture("test", "eye.png")); sprite.setOrigin(sprite.getWidth() / 2f, sprite.getHeight() / 2); this.bound = new Circle(this.x, this.y, 11); }
public HumanShip(boolean beSmart, Difficulty diff) { sprite = new Sprite(Game.gfxMgr.getTexture("test", "human.png")); sprite.setOrigin(sprite.getWidth() / 2, sprite.getHeight() / 2); glowSprite = new Sprite(Game.gfxMgr.getTexture("test", "glow_red.png")); glowSprite.setOrigin(glowSprite.getWidth() / 2, glowSprite.getHeight() / 2); smart = beSmart; change = 0f; shoot = 0f; switch(diff) { case CASUAL: health = 200; bulletCount = 4; break; case NORMAL: health = 225; bulletCount = 6; break; case HARDCORE: health = 270; bulletCount = 8; break; } moveTweenX = null; moveTweenY = null; this.bound = new Circle(this.x, this.y, 16); }
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); } }
@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)); }
public Chip(TextureRegion[] chipRegions, int type, float x, float y, float width, float height, float phaseShiftFraction) { this.chipRegions = chipRegions; this.type = type; this.origin.set(x, y, width, height); this.bounds.set(x, y, width, height); this.collisionCircle = new Circle(x + width / 2, y + height / 2, Math.min(width, height) / 2); this.phaseShiftFraction = phaseShiftFraction; }