Search in sources :

Example 16 with Rectangle

use of com.badlogic.gdx.math.Rectangle in project commons-gdx by gemserk.

the class TextButton method recalculateBoundsSize.

private void recalculateBoundsSize(CharSequence text) {
    Rectangle textBounds = SpriteBatchUtils.getBounds(font, text, getX(), getY());
    width = textBounds.getWidth();
    height = textBounds.getHeight();
}
Also used : Rectangle(com.badlogic.gdx.math.Rectangle)

Example 17 with Rectangle

use of com.badlogic.gdx.math.Rectangle in project Entitas-Java by Rubentxu.

the class PongState method initialize.

@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));
}
Also used : Circle(com.badlogic.gdx.math.Circle) Batch(com.badlogic.gdx.graphics.g2d.Batch) BaseSceneManager(com.ilargia.games.entitas.egdx.base.managers.BaseSceneManager) Rectangle(com.badlogic.gdx.math.Rectangle) BaseGUIManager(com.ilargia.games.entitas.egdx.base.managers.BaseGUIManager) Camera(com.badlogic.gdx.graphics.Camera) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont)

Example 18 with Rectangle

use of com.badlogic.gdx.math.Rectangle in project Entitas-Java by Rubentxu.

the class RendererSystem method render.

@Override
public void render() {
    Gdx.gl.glClearColor(0, 0, 0, 1);
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
    cam.update();
    sr.setProjectionMatrix(cam.combined);
    sr.begin(ShapeRenderer.ShapeType.Filled);
    sr.setColor(Color.WHITE);
    for (CoreEntity e : _group.getEntities()) {
        View view = e.getView();
        System.out.printf("..views");
        if (view.shape instanceof Rectangle) {
            Rectangle ret = (Rectangle) view.shape;
            sr.rect(ret.x, ret.y, ret.width, ret.height);
        } else {
            Circle circle = (Circle) view.shape;
            sr.circle(circle.x, circle.y, circle.radius);
        }
    }
    sr.end();
    batch.begin();
    for (CoreEntity e : _groupScore.getEntities()) {
        Score score = e.getScore();
        font.draw(batch, score.text + " " + score.points, score.x, score.y);
    }
    for (CoreEntity e : _groupTextureView.getEntities()) {
        TextureView textureView = e.getTextureView();
        batch.draw(textureView.texture, textureView.position.x, textureView.position.y, 0, 0, textureView.width, textureView.height, 1, 1, textureView.rotation);
    }
    batch.end();
}
Also used : CoreEntity(com.ilargia.games.entitas.core.CoreEntity) Circle(com.badlogic.gdx.math.Circle) Score(com.ilargia.games.logicbrick.component.Score) Rectangle(com.badlogic.gdx.math.Rectangle) TextureView(com.ilargia.games.logicbrick.component.TextureView) TextureView(com.ilargia.games.logicbrick.component.TextureView) View(com.ilargia.games.logicbrick.component.View)

Example 19 with Rectangle

use of com.badlogic.gdx.math.Rectangle in project AmazingMaze by TheVirtualMachine.

the class Player method handleDeath.

/** Handle the player dying. */
private void handleDeath() {
    Rectangle thisBox = getBoundingRectangle();
    for (Rectangle wire : maze.wireBoxes) {
        if (thisBox.overlaps(wire)) {
            if (lives <= 0) {
                dead = true;
                return;
            }
            if (!maze.help) {
                lives--;
            }
            maze.updateLives((int) ((getX() - MapFactory.START_DISTANCE + 1) / MapFactory.WIRE_DISTANCE));
            setPosition(0, maze.mapHeight / 2);
            break;
        }
    }
}
Also used : Rectangle(com.badlogic.gdx.math.Rectangle)

Example 20 with Rectangle

use of com.badlogic.gdx.math.Rectangle in project Alkahest-Coffee by AlkahestDev.

the class ClientGameInstance method draw.

public void draw(SpriteBatch batch, ShapeRenderer renderer) {
    batch.begin();
    for (PlayerSoldier p : playWorld.getPlayers().values()) {
        //DrawTools.rec(renderer,p.getRect());
        p.draw(batch, playWorld.getPlayers().get(gameClient.getConnectionID()).equals(p));
    }
    //batch.draw(playWorld.getMap().getVisualComponent(),0,0);
    batch.end();
    playWorld.getMap().draw(batch);
    renderer.begin(ShapeRenderer.ShapeType.Filled);
    for (PlayerSoldier playerSoldier : gameClient.getPlayers().values()) {
        //playerSoldier.getMouseAngle());
        System.out.println(playerSoldier.getX() - playerSoldier.getCenterX());
        renderer.setColor(Color.RED);
        renderer.line(playerSoldier.getCenterX(), playerSoldier.getCenterY(), playerSoldier.getCenterX() + (5 * (float) Math.cos(Math.toRadians(playerSoldier.getMouseAngle()))), playerSoldier.getCenterY() + (5 * (float) Math.sin(Math.toRadians(playerSoldier.getMouseAngle()))));
        renderer.setColor(Color.BLUE);
        DrawTools.rec(renderer, new Rectangle((int) (playerSoldier.getX()), (int) (playerSoldier.getY() + playerSoldier.getvY()), 1, 1));
    }
    renderer.end();
}
Also used : PlayerSoldier(me.dumfing.multiplayerTools.PlayerSoldier) Rectangle(com.badlogic.gdx.math.Rectangle)

Aggregations

Rectangle (com.badlogic.gdx.math.Rectangle)35 Test (org.junit.Test)6 TiledMapTileLayer (com.badlogic.gdx.maps.tiled.TiledMapTileLayer)5 MockPointer (com.gemserk.commons.gdx.input.MockPointer)4 Circle (com.badlogic.gdx.math.Circle)3 BitmapFont (com.badlogic.gdx.graphics.g2d.BitmapFont)2 Cell (com.badlogic.gdx.maps.tiled.TiledMapTileLayer.Cell)2 GdxRuntimeException (com.badlogic.gdx.utils.GdxRuntimeException)2 CoreEntity (com.ilargia.games.entitas.core.CoreEntity)2 View (com.ilargia.games.logicbrick.component.View)2 PlayerSoldier (me.dumfing.multiplayerTools.PlayerSoldier)2 FishColour (ca.hiphiparray.amazingmaze.FishCell.FishColour)1 AssetManager (com.badlogic.gdx.assets.AssetManager)1 FileHandle (com.badlogic.gdx.files.FileHandle)1 Camera (com.badlogic.gdx.graphics.Camera)1 Color (com.badlogic.gdx.graphics.Color)1 Pixmap (com.badlogic.gdx.graphics.Pixmap)1 Batch (com.badlogic.gdx.graphics.g2d.Batch)1 Glyph (com.badlogic.gdx.graphics.g2d.BitmapFont.Glyph)1 TextBounds (com.badlogic.gdx.graphics.g2d.BitmapFont.TextBounds)1