Java Code Examples for com.badlogic.gdx.math.Rectangle

The following are top voted examples for showing how to use com.badlogic.gdx.math.Rectangle. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: guitar-finger-trainer   File: LevelScreen.java   Source Code and License 6 votes vote down vote up
LevelScreen(GftGame game) {
    this.game = game;

    this.guiCam = new OrthographicCamera(800, 480);
    this.guiCam.position.set(800 / 2, 480 / 2, 0);

    this.backBounds = new Rectangle(7, 432, 48, 48);
    this.autoMoveToNextBounds = new Rectangle(0, 0, 800, 62);

    this.levelBounds = new ArrayList<Rectangle>();
    int line = 0;
    int column = 0;
    for(int i = 0; i < LEVELS; i++) {
        this.levelBounds.add(i, new Rectangle(370 + 75 * column++, 240 - 70 * line, 57, 57));
        if(column == 5) {
            column = 0;
            line++;
        }
    }

    this.touchPoint = new Vector3();
}
 
Example 2
Project: FlappySpinner   File: GameButton.java   Source Code and License 6 votes vote down vote up
public GameButton(float WIDTH, float HEIGHT, String drawable, boolean isCheckable) {
    audioManager = AudioManager.getInstance();
    skin = new Skin();
    skin.addRegions(AssetsManager.getTextureAtlas());

    Button.ButtonStyle buttonStyle = new Button.ButtonStyle();
    buttonStyle.up = skin.getDrawable(drawable);
    buttonStyle.down = skin.getDrawable(drawable + "_pressed");
    if (isCheckable) {
        buttonStyle.checked = skin.getDrawable(drawable + "_pressed");
    }
    setStyle(buttonStyle);
    setSize(WIDTH, HEIGHT);

    rectangle = new Rectangle(getX(),getY(),getWidth(),getHeight());
    addListener(new ClickListener(){
        @Override
        public void clicked(InputEvent event, float x, float y) {
            super.clicked(event, x, y);
            audioManager.playSound(audioManager.getButtonSound());
        }
    });
}
 
Example 3
Project: cocos2d-java   File: QuadTreeV2.java   Source Code and License 6 votes vote down vote up
public void addObject(IQuadTreeObject obj) {
	tempObjects.add(obj);
	
	//update max aabb
	final Rectangle rect = obj.getRectangle();
	final float x0 = rect.x;
	final float y0 = rect.y;
	final float x1 = rect.x + rect.width;
	final float y1 = rect.y + rect.height;
	
	minX = minX > x0 ? x0 : minX;
	minY = minY > y0 ? y0 : minY;
	maxX = maxX < x1 ? x1 : maxX;
	maxY = maxY < y1 ? y1 : maxY;
	
	System.out.println("QuadTree : updateRootBounds [" + 
	minX +"," + minY + "," + maxX + "," + maxY + "]");
}
 
Example 4
Project: guitar-finger-trainer   File: TrainingScreen.java   Source Code and License 6 votes vote down vote up
TrainingScreen(GftGame game) {
    this.game = game;

    this.guiCam = new OrthographicCamera(800, 480);
    this.guiCam.position.set(800 / 2, 480 / 2, 0);

    this.backBounds = new Rectangle(7, 432, 48, 48);
    this.playPauseBounds = new Rectangle(7, 7, 48, 48);
    this.restartBounds = new Rectangle(62, 7, 48, 48);
    this.backFowardtBounds = new Rectangle(127, 7, 48, 48);
    this.soundBounds = new Rectangle(192, 7, 48, 48);
    this.minusBounds = new Rectangle(590, 7, 48, 48);
    this.plusBounds = new Rectangle(699, 7, 48, 48);

    this.touchPoint = new Vector3();

    this.grid = new Grid(this.game);
    this.grid.loadTraining();

    this.bottomBar = new BottomBar(this.game);

    this.firstRun = 3;
    this.lastUpdateTime = TimeUtils.millis();
    this.bpm = MINUTE_IN_MILLIS / SettingsUtil.bpm;
}
 
Example 5
Project: Klooni1010   File: GameLayout.java   Source Code and License 6 votes vote down vote up
void update(BaseScorer scorer) {
    float cupSize = Math.min(scoreHeight, scorer.cupTexture.getHeight());
    final Rectangle area = new Rectangle(
            marginWidth, pieceHolderHeight + boardHeight,
            availableWidth, scoreHeight);

    scorer.cupArea.set(
            area.x + area.width * 0.5f - cupSize * 0.5f, area.y,
            cupSize, cupSize);

    scorer.currentScoreLabel.setBounds(
            area.x, area.y,
            area.width * 0.5f - cupSize * 0.5f, area.height);

    scorer.highScoreLabel.setBounds(
            area.x + area.width * 0.5f + cupSize * 0.5f, area.y,
            area.width * 0.5f - cupSize * 0.5f, area.height);
}
 
Example 6
Project: Mindustry   File: Renderer.java   Source Code and License 6 votes vote down vote up
public Renderer() {
	Core.cameraScale = baseCameraScale;
	Effects.setEffectProvider((name, color, x, y, rotation) -> {
		if(Settings.getBool("effects")){
			Rectangle view = Tmp.r1.setSize(camera.viewportWidth, camera.viewportHeight)
					.setCenter(camera.position.x, camera.position.y);
			Rectangle pos = Tmp.r2.setSize(name.size).setCenter(x, y);
			if(view.overlaps(pos)){
				new EffectEntity(name, color, rotation).set(x, y).add();
			}
		}
	});
	
	clearColor = Hue.lightness(0.4f);
	clearColor.a = 1f;
}
 
Example 7
Project: libgdx_ui_editor   File: EditingZone.java   Source Code and License 6 votes vote down vote up
@Override
public void draw (Batch batch, float parentAlpha) {
    Rectangle scissors = new Rectangle();
    Rectangle clipBounds = new Rectangle(getX(),getY(),getWidth(),getHeight());
    ScissorStack.calculateScissors(getStage().getCamera(), batch.getTransformMatrix(), clipBounds, scissors);
    ScissorStack.pushScissors(scissors);

    drawBg(batch, parentAlpha);

    batch.draw(texture,
            getX() + getWidth() / 2 - texture.getRegionWidth() / 2 + shift.x,
            getY() + getHeight() / 2 - texture.getRegionHeight() / 2 + shift.y,
            texture.getRegionWidth() / 2f,
            texture.getRegionHeight() / 2f,
            texture.getRegionWidth(), texture.getRegionHeight(),
            currZoom, currZoom, 0);

    drawSplits(batch, parentAlpha);

    batch.flush();
    ScissorStack.popScissors();
}
 
Example 8
Project: Klooni1010   File: PieceHolder.java   Source Code and License 6 votes vote down vote up
public boolean pickPiece() {
    Vector2 mouse = new Vector2(
            Gdx.input.getX(),
            Gdx.graphics.getHeight() - Gdx.input.getY()); // Y axis is inverted

    final float perPieceWidth = area.width / count;
    for (int i = 0; i < count; ++i) {
        if (pieces[i] != null) {
            Rectangle maxPieceArea = new Rectangle(
                    area.x + i * perPieceWidth, area.y, perPieceWidth, area.height);

            if (maxPieceArea.contains(mouse)) {
                heldPiece = i;
                return true;
            }
        }
    }

    heldPiece = -1;
    return false;
}
 
Example 9
Project: feup-lpoo-armadillo   File: WaterModel.java   Source Code and License 6 votes vote down vote up
/**
 * Water Model's constructor.
 * Creates a water model from the given object, into the given world.
 *
 * @param world The world the water model will be in.
 * @param rect  The rectangle to create the water model with.
 */
public WaterModel(World world, Rectangle rect) {
    // Body and Fixture variables
    BodyDef bdef = new BodyDef();
    FixtureDef fdef = new FixtureDef();
    PolygonShape shape = new PolygonShape();

    bdef.type = BodyDef.BodyType.StaticBody;
    bdef.position.set(PIXEL_TO_METER * (rect.getX() + rect.getWidth() / 2), PIXEL_TO_METER * (rect.getY() + rect.getHeight() / 2));

    this.body = world.createBody(bdef);

    shape.setAsBox((rect.getWidth() / 2) * PIXEL_TO_METER, (rect.getHeight() / 2) * PIXEL_TO_METER);
    fdef.shape = shape;
    fdef.filter.categoryBits = FLUID_BIT;
    fdef.isSensor = true;
    fdef.density = 1f;
    fdef.friction = 0.1f;
    fdef.restitution = 0f;
    body.createFixture(fdef);

    body.setUserData(new BuoyancyController(world, body.getFixtureList().first()));

}
 
Example 10
Project: blueirisviewer   File: Images.java   Source Code and License 6 votes vote down vote up
public void resize(int w, int h)
{
	screenWidth.set(w);
	screenHeight.set(h);
	if (BlueIrisViewer.bivSettings != null)
	{
		double sqrt = Math.sqrt(numCams);
		cols = (int) Math.ceil(sqrt);
		rows = (int) sqrt;
		if (cols * rows < numCams)
			rows++;
		HandleOverrideGridSize();
		imageWidth = (float) w / cols;
		imageHeight = (float) h / rows;
		aImageWidth.set((int) Math.ceil(imageWidth));
		aImageHeight.set((int) Math.ceil(imageHeight));
	}
	blueIrisLayoutModelRect = new Rectangle(0, h, mainImageWidth, mainImageHeight);
	ScaleRectangleToFitScreenCentered(blueIrisLayoutModelRect);
	PrecalculateBlueIrisLayoutRectangles();
}
 
Example 11
Project: GangsterSquirrel   File: Box2DWorldCreator.java   Source Code and License 6 votes vote down vote up
/**
 * Reads the enemy type and spawn position out of an enemy object on the map and then spawns it in the current level
 * @param object the map object that has been read in the map file
 * @param rectangle the rectangular shape of the object, contains position used for selecting the spawn position
 */
private void addEnemy(MapObject object, Rectangle rectangle) {

    MapProperties properties = object.getProperties();

    if (properties != null && properties.containsKey("enemy_type")) {
        String enemyType = properties.get("enemy_type", String.class);

        switch (enemyType) {
            case "Frog":
                playScreen.spawnEnemy(FrogEnemy.class, (int) (rectangle.getX() / MainGameClass.TILE_PIXEL_SIZE), (int) (rectangle.getY() / MainGameClass.TILE_PIXEL_SIZE));
                break;
            case "Monkey":
                playScreen.spawnEnemy(MonkeyEnemy.class, (int) (rectangle.getX() / MainGameClass.TILE_PIXEL_SIZE), (int) (rectangle.getY() / MainGameClass.TILE_PIXEL_SIZE));
                break;
            case "Boss":
                playScreen.spawnEnemy(BossEnemy.class, (int) (rectangle.getX() / MainGameClass.TILE_PIXEL_SIZE), (int) (rectangle.getY() / MainGameClass.TILE_PIXEL_SIZE));
                break;
            default:
                break;
        }
    }
}
 
Example 12
Project: Klooni1010   File: Band.java   Source Code and License 6 votes vote down vote up
public Band(final Klooni game, final GameLayout layout, final BaseScorer scorer) {
    this.scorer = scorer;
    bandTexture = Theme.getBlankTexture();

    Label.LabelStyle labelStyle = new Label.LabelStyle();
    labelStyle.font = game.skin.getFont("font");

    scoreLabel = new Label("", labelStyle);
    scoreLabel.setAlignment(Align.center);
    infoLabel = new Label("pause menu", labelStyle);
    infoLabel.setAlignment(Align.center);

    scoreBounds = new Rectangle();
    infoBounds = new Rectangle();
    layout.update(this);
}
 
Example 13
Project: GDX-Engine   File: AnimatedSprite.java   Source Code and License 6 votes vote down vote up
public void PlayAnimation(Animation animation, Rectangle newRegionOnTexture)
  {
if (animation == null && this.animation == null)
          throw new GdxRuntimeException("No animation is currently playing.");
      // If this animation is already running, do not restart it.
      if (this.animation == animation)
          return;

      // Start the new animation.
      this.animation = animation;
      this.frameIndex = 0;
      this.animationTimeline = 0.0f;
      
      this.setRegionX((int) newRegionOnTexture.x);
      this.setRegionY((int) newRegionOnTexture.y);
      this.setRegionWidth((int) newRegionOnTexture.getWidth());
      this.setRegionHeight((int) newRegionOnTexture.getHeight());
      onAnimationChanged();
  }
 
Example 14
Project: summer17-android   File: InteractiveTileObject.java   Source Code and License 6 votes vote down vote up
public InteractiveTileObject(World world, TiledMap map, Rectangle bounds){
    this.world = world;
    this.map = map;
    this.bounds = bounds;

    BodyDef bdef = new BodyDef();
    FixtureDef fdef = new FixtureDef();
    PolygonShape shape = new PolygonShape();

    bdef.type = BodyDef.BodyType.StaticBody;
    bdef.position.set((bounds.getX() + bounds.getWidth() / 2) / NoObjectionGame.PPM, (bounds.getY() + bounds.getHeight() / 2 )/ NoObjectionGame.PPM);

    body = world.createBody(bdef);
    shape.setAsBox(bounds.getWidth() / 2 / NoObjectionGame.PPM, bounds.getHeight() / 2 / NoObjectionGame.PPM);
    fdef.shape = shape;
    fixture = body.createFixture(fdef);
}
 
Example 15
Project: GDX-Engine   File: GameService.java   Source Code and License 6 votes vote down vote up
public GameService(SpriteBatch batch, IGameAsset asset,
    BaseGameSetting setting, OrthographicCamera camera,
    ISceneManager sceneManager) {
this.batch = batch;
this.asset = asset;
this.setting = setting;

if (asset == null)
    this.asset = new DefaultGameAsset();
if (setting == null)
    this.setting = new DefaultGameSetting();
this.camera = camera;
this.setChangeScene(sceneManager);
Rectangle.tmp.set(0, 0, getWindowSize().x, getWindowSize().y);

services = new IService[MAX_SERVICES];
   }
 
Example 16
Project: miniventure   File: MyUtils.java   Source Code and License 6 votes vote down vote up
public static Rectangle moveRectInside(Rectangle toMove, Rectangle outer, float padding) {
	if(toMove.width >= outer.width)
		toMove.x = outer.x - (toMove.width - outer.width) / 2;
	else {
		if(toMove.x < outer.x)
			toMove.x = outer.x + padding;
		if(toMove.x + toMove.width > outer.x + outer.width)
			toMove.x = outer.x + outer.width - toMove.width - padding;
	}
	
	if(toMove.height >= outer.height)
		toMove.y = outer.y - (toMove.height - outer.height) / 2;
	else {
		if(toMove.y < outer.y)
			toMove.y = outer.y + padding;
		if(toMove.y + toMove.height > outer.y + outer.height)
			toMove.y = outer.y + outer.height - toMove.height - padding;
	}
	
	return toMove;
}
 
Example 17
Project: GDX-Engine   File: GameService.java   Source Code and License 6 votes vote down vote up
@SuppressWarnings("incomplete-switch")
   @Override
   public void draw(Texture texture, Vector2 position, Vector2 origin,
    Vector2 size, float scale, float rotation, Rectangle source,
    Flip flip) {
boolean flipX = false;
boolean flipY = false;
switch (flip) {
case Both:
    flipX = true;
    flipY = true;
    break;
case Horizontal:
    flipX = true;
    break;
case Vertical:
    flipY = true;
}
batch.draw(texture, position.x, position.y, origin.x, origin.y, size.x,
	size.y, scale, scale, rotation, (int) source.getX(),
	(int) source.getY(), (int) source.getWidth(),
	(int) source.getHeight(), flipX, flipY);

   }
 
Example 18
Project: KyperBox   File: QuadTree.java   Source Code and License 6 votes vote down vote up
/**
 * create a quadtree collision manager with a default max_depth of 4 and a
 * max_object count of 10.
 * 
 * @param x
 * @param y
 * @param width
 * @param height
 */
public QuadTree(float x, float y, float width, float height) {
	check_object = new BasicGameObject();
	check_object.init(null);
	remove_objects = new IntArray();
	culling = true;
	follow_x  =0;
	follow_y  =0;
	bounds = new Rectangle(x - PAD, y - PAD, width + PAD * 2, height + PAD * 2);
	objects =  new Array<GameObject>();
	follow_view = false;
	final QuadTree m = this;
	quad_pool = new Pool<QuadTree.Quad>() {
		@Override
		protected Quad newObject() {
			return new Quad(m);
		}
	};
	max_depth = 4;
	max_objects = 10;
	root = quad_pool.obtain();
	root.init(null, 0, bounds.x, bounds.y, bounds.width, bounds.height);
	ret_list = new Array<GameObject>();
}
 
Example 19
Project: MMORPG_Prototype   File: PixelCollisionMapTests.java   Source Code and License 6 votes vote down vote up
private void whenObjectsAreNearEachOtherSHouldBeAbleToBeYShiftedProperely(int shiftY)
{
	int width = 8;
	int height = 8;
	ShiftableCollisionMap<PixelCollisionMapTestObject> collisionMap = new PixelCollisionMap<>(width, height);
	Rectangle firstObjectStartBounds = new Rectangle(2, 2, 2, 2);
	Rectangle secondObjectStartBounds = new Rectangle(2, 4, 2, 2);
	PixelCollisionMapTestObject firstObject = new PixelCollisionMapTestObject(firstObjectStartBounds);
	PixelCollisionMapTestObject secondObject = new PixelCollisionMapTestObject(secondObjectStartBounds);
	collisionMap.insert(firstObject);
	collisionMap.insert(secondObject);
	int shiftX = 0;
	collisionMap.update(shiftX, shiftY);
	assertThereIsPlacedObject(collisionMap, firstObjectStartBounds, firstObject);
	assertThereIsPlacedObject(collisionMap, secondObjectStartBounds, secondObject);
	assertNullAroundObject(collisionMap, new Rectangle(2, 2, 2, 4));
}
 
Example 20
Project: miniventure   File: Player.java   Source Code and License 6 votes vote down vote up
@NotNull
private Array<WorldObject> getInteractionQueue() {
	Array<WorldObject> objects = new Array<>();
	
	// get level, and don't interact if level is not found
	Level level = Level.getEntityLevel(this);
	if(level == null) return objects;
	
	Rectangle interactionBounds = getInteractionRect();
	
	objects.addAll(level.getOverlappingEntities(interactionBounds, this));
	
	Tile tile = level.getClosestTile(interactionBounds);
	if(tile != null)
		objects.add(tile);
	
	return objects;
}
 
Example 21
Project: cocos2d-java   File: QuadTreeV2.java   Source Code and License 5 votes vote down vote up
public boolean insert(IQuadTreeObject obj, int currDepth) {
	Rectangle rect = obj.getRectangle();
	switch(type) {
	case 0:
		if(rect.x > x0 && rect.y > y0) {
			objs.add(obj);
			return true;
		}
		break;
	case 1:
		if(rect.x + rect.width < x1 && rect.y > y0) {
			objs.add(obj);
			return true;
		}
		break;
	case 2:
		if(rect.x + rect.width < x1 && rect.y + rect.height < y1) {
			objs.add(obj);
			return true;
		}
		break;
	case 3:
		if(rect.x > x0 && rect.y + rect.height < y1) {
			objs.add(obj);
			return true;
		}
		break;
	}
	return false;
}
 
Example 22
Project: summer17-android   File: Sheep.java   Source Code and License 5 votes vote down vote up
public Sheep(int x, int y) {
    super(x, y);
    sheep = new Texture("sheeprunning.png");
    sheepDead = new Texture("sheepsquish.png");
    sheepAnimation = new Animation(new TextureRegion(sheep), 4, 0.5f);
    sheep2Animation = new Animation(new TextureRegion(sheepDead), 15, 0.5f);
    bounds1 = new Rectangle(x, y, 70, 45);
    jump = Gdx.audio.newSound(Gdx.files.internal("jump_07.mp3"));
}
 
Example 23
Project: MMORPG_Prototype   File: PixelCollisionMapTests.java   Source Code and License 5 votes vote down vote up
private void shiftTest(final int shiftX, final int shiftY)
{
	int width = 10;
	int height = 10;
	ShiftableCollisionMap<PixelCollisionMapTestObject> collisionMap = new PixelCollisionMap<>(width, height);
	Rectangle startBounds = new Rectangle(5, 5, 2, 2);
	PixelCollisionMapTestObject object = new PixelCollisionMapTestObject(new Rectangle(startBounds));
	collisionMap.insert(object);
	collisionMap.update(shiftX, shiftY);
	assertNullAroundObject(collisionMap, startBounds);
	assertThereIsPlacedObject(collisionMap, startBounds, object);
}
 
Example 24
Project: cocos2d-java   File: QuadTree.java   Source Code and License 5 votes vote down vote up
public QuadTreeNode(QuadTree tree, int type, float x0, float y0, float x1, float y1) {
	this.tree = tree;
			
	this.x0 = x0;
	this.y0 = y0;
	this.x1 = x1;
	this.y1 = y1;
	_rect = new Rectangle(x0, y0, x1 - x0, y1 - y0);
	this.type = type;
	centerX = (x0 + x1) / 2;
	centerY = (y0 + y1) / 2; 
}
 
Example 25
Project: cocos2d-java   File: QuadTree.java   Source Code and License 5 votes vote down vote up
public void slowQuery(Rectangle rect, final Array<IQuadTreeObject> ret) {
	for(int i = 0, n = tempObjects.size; i < n; ++i) {
		final IQuadTreeObject o = tempObjects.get(i);
		if(rect.overlaps(o.getRectangle())) {
			ret.add(o);
		}
	}
}
 
Example 26
Project: GangsterSquirrel   File: DeathTile.java   Source Code and License 5 votes vote down vote up
public DeathTile(PlayScreen screen, Rectangle bounds) {
    super(screen, bounds, true);
    this.playScreen = screen;

    fixture.setUserData(this);
    createFilterMask();
}
 
Example 27
Project: cocos2d-java   File: Camera.java   Source Code and License 5 votes vote down vote up
/**
     * Is this aabb visible in frustum
     */
    public boolean isVisibleInFrustum(Rectangle aabb) {
    	if(_frustumDirty) {
//    		_frustum.
    		_frustumDirty = false;
    	}
    	return true;
    }
 
Example 28
Project: school-game   File: PhysicsTileMapBuilder.java   Source Code and License 5 votes vote down vote up
/**
 * Erzeugt aus einem RectangleMapObject ein rechteckiges PolygonShape.
 *
 * Rotationen werden NICHT unterst├╝tzt.
 *
 * @param rectObject das MapObject
 * @return die entsprechende Form
 */
public static PolygonShape createRectangle(RectangleMapObject rectObject)
{
    Rectangle rectangle = rectObject.getRectangle();

    Vector2 center = new Vector2(rectangle.x + rectangle.width * 0.5f, rectangle.y + rectangle.height * 0.5f);

    return Physics.createRectangle(rectangle.width, rectangle.height, center);
}
 
Example 29
Project: libgdx_ui_editor   File: SelectGroup.java   Source Code and License 5 votes vote down vote up
public SelectGroup(){
    cubRect = new Rectangle();
    childRect = new Rectangle();
    setCullingArea(cubRect);
    cubDra = DrawableUtil.getRectLineDrawable("icon/select.9.png");
    selection = new Selection<Actor>();
    addListener(dragListener);
}
 
Example 30
Project: GangsterSquirrel   File: Jumpable.java   Source Code and License 5 votes vote down vote up
public Jumpable(PlayScreen screen, Rectangle bounds) {
    super(screen, bounds, true);
    playScreen = screen;

    fixture.setUserData(this);
    createFilterMask();
}
 
Example 31
Project: blueirisviewer   File: Images.java   Source Code and License 5 votes vote down vote up
private void PrecalculateBlueIrisLayoutRectangles()
{
	for (int i = 0; i < blueIrisRectsProportional.size(); i++)
	{
		Rectangle propRect = blueIrisRectsProportional.get(i);
		float x = (propRect.x * blueIrisLayoutModelRect.width) + blueIrisLayoutModelRect.x;
		float y = (propRect.y * blueIrisLayoutModelRect.height) + blueIrisLayoutModelRect.y;
		Rectangle preCalcRect = new Rectangle(x, y, propRect.width * blueIrisLayoutModelRect.width, propRect.height
				* blueIrisLayoutModelRect.height);
		blueIrisRectsPrecalc.set(i, preCalcRect);
	}
}
 
Example 32
Project: miniventure   File: Level.java   Source Code and License 5 votes vote down vote up
public Array<Tile> getOverlappingTiles(Rectangle entityRect) {
	int tileMinX = (int) entityRect.x / Tile.SIZE;
	int tileMaxX = (int) (entityRect.x + entityRect.width) / Tile.SIZE;
	int tileMinY = (int) entityRect.y / Tile.SIZE;
	int tileMaxY = (int) (entityRect.y + entityRect.height) / Tile.SIZE;
	
	Array<Tile> overlappingTiles = new Array<>();
	for(int x = Math.max(0, tileMinX); x <= Math.min(width-1, tileMaxX); x++)
		for(int y = Math.max(0, tileMinY); y <= Math.min(height-1, tileMaxY); y++)
			overlappingTiles.add(tiles[x][y]);
	
	return overlappingTiles;
}
 
Example 33
Project: FlappyChapa   File: Tube.java   Source Code and License 5 votes vote down vote up
public boolean collides(Rectangle bird){

        if(bird.overlaps(boundsTop) || bird.overlaps(boundsBot)){
            return true;
        }
        
        return false;
    }
 
Example 34
Project: FlappyChapa   File: Anto.java   Source Code and License 5 votes vote down vote up
public boolean collides(Rectangle bird){

        if(bird.overlaps(boundsTop)){
            return true;
        }

        return false;
    }
 
Example 35
Project: Klooni1010   File: PieceHolder.java   Source Code and License 5 votes vote down vote up
private void updatePiecesStartLocation() {
    float perPieceWidth = area.width / count;
    Piece piece;
    for (int i = 0; i < count; ++i) {
        piece = pieces[i];
        if (piece == null)
            continue;

        // Set the absolute position on screen and the cells' cellSize
        // Also clamp the cell size to be the picked size as maximum, or
        // it would be too big in some cases.
        piece.pos.set(area.x + i * perPieceWidth, area.y);
        piece.cellSize = Math.min(Math.min(
                perPieceWidth / piece.cellCols,
                area.height / piece.cellRows), pickedCellSize);

        // Center the piece on the X and Y axes. For this we see how
        // much up we can go, this is, (area.height - piece.height) / 2
        Rectangle rectangle = piece.getRectangle();
        piece.pos.y += (area.height - rectangle.height) * 0.5f;
        piece.pos.x += (perPieceWidth - rectangle.width) * 0.5f;

        originalPositions[i] = new Rectangle(
                piece.pos.x, piece.pos.y,
                piece.cellSize, piece.cellSize);

        // Now that we have the original positions, reset the size so it animates and grows
        piece.cellSize = 0f;
    }
}
 
Example 36
Project: project-divine-intervention   File: Player.java   Source Code and License 5 votes vote down vote up
public Player(EntityManager ent, float x, float y, CharacterSheet c, int playerNum){
    super(ent, null, x,y);
    this.playerNum = playerNum;
    target = new Vector2();
    anim = new Animation(c);
    size = new Vector2(c.idle[0].getRegionWidth(), c.idle[0].getRegionHeight());
    body = new Rectangle(x, y, size.x, size.y);
    dir = 1f;
}
 
Example 37
Project: conquest   File: Grabber.java   Source Code and License 5 votes vote down vote up
public Grabber(Array<Tile> tiles, ConquestCamera cam, Manager manager, Pathway pathway, Player player) {
    this.tiles = tiles;
    rect = new Rectangle();
    this.cam = cam;

    this.manager = manager;
    this.pathway = pathway;
    this.player = player;

    mode = Mode.FIRST;
}
 
Example 38
Project: summer17-android   File: Pig.java   Source Code and License 5 votes vote down vote up
public Pig(int x, int y) {
    super(x, y);
    pig = new Texture("PigRun.png");
    pigDead = new Texture("PigDead.png");
    pigAnimation = new Animation(new TextureRegion(pig),4,0.5f);
    pig1Animation = new Animation(new TextureRegion(pigDead),27,0.5f);
    pigBounds = new Rectangle(x,y,70,45);
}
 
Example 39
Project: Flappy-Baranus   File: Tube.java   Source Code and License 5 votes vote down vote up
public Tube(float x){
    topTube = new Texture("toptube.png");
    bottomTube = new Texture("bottomtube.png");
    rand = new Random();

    posTopTube = new Vector2(x, rand.nextInt(FLUCTUATION) + TUBE_GAP + LOWEST_OPENING);
    posBotTube = new Vector2(x, posTopTube.y - TUBE_GAP - bottomTube.getHeight());

    boundsTop = new Rectangle(posTopTube.x, posTopTube.y, topTube.getWidth(), topTube.getHeight());
    boundsBot = new Rectangle(posBotTube.x, posBotTube.y, bottomTube.getWidth(), bottomTube.getHeight());

}
 
Example 40
Project: GDX-Engine   File: DefaultGameAsset.java   Source Code and License 5 votes vote down vote up
@Override
public TextureRegion loadTextureRegion(String textureFile, Rectangle rec)
{
	Texture texture = loadTexture(textureFile, Format.RGBA4444, true);
	TextureRegion tr = new TextureRegion(texture, (int)rec.x, (int)rec.y, (int)rec.width, (int)rec.height);
	//flip for system of y-axis down
	if(Game.isYdown())
		tr.flip(false, true);
	return tr;
}