use of com.ilargia.games.entitas.core.CoreEntity in project Entitas-Java by Rubentxu.
the class DelaySystem method execute.
@Override
public void execute(float deltatime) {
for (CoreEntity e : _group.getEntities()) {
Delay delay = e.getDelay();
delay.time += deltatime;
if (delay.time > delay.duration) {
PongGame.ebus.post((ChangeStateCommand<PongGame>) (nameState, game) -> game.changeState(game.getPongState(), game.getSlideTransition()));
delay.time = 0;
}
}
}
use of com.ilargia.games.entitas.core.CoreEntity 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;
}
}
}
}
use of com.ilargia.games.entitas.core.CoreEntity 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);
}
}
use of com.ilargia.games.entitas.core.CoreEntity 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();
}
use of com.ilargia.games.entitas.core.CoreEntity 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);
}
}
Aggregations