Skip to content

Instantly share code, notes, and snippets.

@schosin
Created August 14, 2020 05:47
Show Gist options
  • Select an option

  • Save schosin/c3b4d3da65a7c3c7aa2c86c0750827f7 to your computer and use it in GitHub Desktop.

Select an option

Save schosin/c3b4d3da65a7c3c7aa2c86c0750827f7 to your computer and use it in GitHub Desktop.
Example of a movement system in artemis-odb
@All({ Position.class, Velocity.class })
public class MovementSystem extends IteratingSystem {
// Component mappers
private ComponentMapper<Position> posM;
private ComponentMapper<Velocity> velocityM;
@Override
protected void process(int entityId) {
var velocity = velocityM.get(entityId);
if (velocity.moving()) {
var pos = posM.get(entityId);
pos.translate(velocity.vx() * world.delta, velocity.vy() * world.delta);
}
}
}
@Data
public class Position extends PooledComponent {
private boolean immutable;
private float x, y;
public Position translate(float x, float y) {
this.x += x;
this.y += y;
return this;
}
}
@Data
public class Velocity extends PooledComponent {
private float vx, vy;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment