Search in sources :

Example 1 with Circle

use of com.badlogic.gdx.math.Circle 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 2 with Circle

use of com.badlogic.gdx.math.Circle 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 3 with Circle

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

the class BoundsSystem method execute.

@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);
    }
}
Also used : CoreEntity(com.ilargia.games.entitas.core.CoreEntity) Circle(com.badlogic.gdx.math.Circle) Motion(com.ilargia.games.logicbrick.component.Motion) Player(com.ilargia.games.logicbrick.component.Player) Score(com.ilargia.games.logicbrick.component.Score)

Example 4 with Circle

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

the class ContactSystem method execute.

@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);
    }
}
Also used : CoreEntity(com.ilargia.games.entitas.core.CoreEntity) Circle(com.badlogic.gdx.math.Circle) Motion(com.ilargia.games.logicbrick.component.Motion) View(com.ilargia.games.logicbrick.component.View)

Example 5 with Circle

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

the class MoveSystem method execute.

@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());
        }
    }
}
Also used : CoreEntity(com.ilargia.games.entitas.core.CoreEntity) Motion(com.ilargia.games.logicbrick.component.Motion) Circle(com.badlogic.gdx.math.Circle) Rectangle(com.badlogic.gdx.math.Rectangle) View(com.ilargia.games.logicbrick.component.View)

Aggregations

Circle (com.badlogic.gdx.math.Circle)5 CoreEntity (com.ilargia.games.entitas.core.CoreEntity)4 Rectangle (com.badlogic.gdx.math.Rectangle)3 Motion (com.ilargia.games.logicbrick.component.Motion)3 View (com.ilargia.games.logicbrick.component.View)3 Score (com.ilargia.games.logicbrick.component.Score)2 Camera (com.badlogic.gdx.graphics.Camera)1 Batch (com.badlogic.gdx.graphics.g2d.Batch)1 BitmapFont (com.badlogic.gdx.graphics.g2d.BitmapFont)1 BaseGUIManager (com.ilargia.games.entitas.egdx.base.managers.BaseGUIManager)1 BaseSceneManager (com.ilargia.games.entitas.egdx.base.managers.BaseSceneManager)1 Player (com.ilargia.games.logicbrick.component.Player)1 TextureView (com.ilargia.games.logicbrick.component.TextureView)1