Search in sources :

Example 1 with Motion

use of com.ilargia.games.logicbrick.component.Motion in project Entitas-Java by Rubentxu.

the class InputSystem method execute.

@Override
public void execute(float deltatime) {
    for (CoreEntity e : _group.getEntities()) {
        Motion motion = e.getMotion();
        Player player = e.getPlayer();
        View view = e.getView();
        if (player.id == Player.ID.PLAYER1) {
            motion.velocity.y = 0;
            if (movesUp(Input.Keys.W, (Rectangle) view.shape)) {
                motion.velocity.y = Pong.PLAYER_SPEED;
            }
            if (movesDown(Input.Keys.S, (Rectangle) view.shape)) {
                motion.velocity.y = -Pong.PLAYER_SPEED;
            }
        }
        if (player.id == Player.ID.PLAYER2) {
            motion.velocity.y = 0;
            if (movesUp(Input.Keys.UP, (Rectangle) view.shape)) {
                motion.velocity.y = Pong.PLAYER_SPEED;
            }
            if (movesDown(Input.Keys.DOWN, (Rectangle) view.shape)) {
                motion.velocity.y = -Pong.PLAYER_SPEED;
            }
        }
    }
}
Also used : CoreEntity(com.ilargia.games.entitas.core.CoreEntity) Motion(com.ilargia.games.logicbrick.component.Motion) Player(com.ilargia.games.logicbrick.component.Player) View(com.ilargia.games.logicbrick.component.View)

Example 2 with Motion

use of com.ilargia.games.logicbrick.component.Motion 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 3 with Motion

use of com.ilargia.games.logicbrick.component.Motion 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 4 with Motion

use of com.ilargia.games.logicbrick.component.Motion 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)

Example 5 with Motion

use of com.ilargia.games.logicbrick.component.Motion in project Entitas-Java by Rubentxu.

the class CoreEntity method addMotion.

public CoreEntity addMotion(float x, float y) {
    Motion component = (Motion) recoverComponent(CoreComponentsLookup.Motion);
    if (component == null) {
        component = new Motion(x, y);
    } else {
        component.velocity = new Vector2(x, y);
    }
    addComponent(CoreComponentsLookup.Motion, component);
    return this;
}
Also used : Motion(com.ilargia.games.logicbrick.component.Motion) Vector2(com.badlogic.gdx.math.Vector2)

Aggregations

Motion (com.ilargia.games.logicbrick.component.Motion)6 CoreEntity (com.ilargia.games.entitas.core.CoreEntity)4 Circle (com.badlogic.gdx.math.Circle)3 View (com.ilargia.games.logicbrick.component.View)3 Vector2 (com.badlogic.gdx.math.Vector2)2 Player (com.ilargia.games.logicbrick.component.Player)2 Rectangle (com.badlogic.gdx.math.Rectangle)1 Score (com.ilargia.games.logicbrick.component.Score)1